本文整理汇总了C#中EditorMap.AddEntity方法的典型用法代码示例。如果您正苦于以下问题:C# EditorMap.AddEntity方法的具体用法?C# EditorMap.AddEntity怎么用?C# EditorMap.AddEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EditorMap
的用法示例。
在下文中一共展示了EditorMap.AddEntity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapContainer_MouseUp
/// <summary>
/// Handles when the mouse button is raised on a map.
/// </summary>
/// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
/// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
/// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
protected override void MapContainer_MouseUp(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera,
MouseEventArgs e)
{
var cursorPos = e.Position();
var worldPos = camera.ToWorld(cursorPos);
// Create entity
if (e.Button == MouseButtons.Right)
{
Type createType = null;
// Create using same type as the last entity, if possible
if (Input.IsCtrlDown)
createType = _lastCreatedType;
// Display selection dialog
if (createType == null)
{
using (var frm = new EntityTypeUITypeEditorForm(_lastCreatedType))
{
if (frm.ShowDialog(sender as IWin32Window) == DialogResult.OK)
createType = frm.SelectedItem;
}
}
// Create the type
if (createType != null)
{
_lastCreatedType = null;
try
{
// Create the Entity
var entity = (Entity)Activator.CreateInstance(createType);
map.AddEntity(entity);
entity.Size = new Vector2(64);
entity.Position = worldPos - (entity.Size / 2f);
GridAligner.Instance.Fit(entity);
_lastCreatedType = createType;
}
catch (Exception ex)
{
const string errmsg = "Failed to create entity of type `{0}` on map `{1}`. Exception: {2}";
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, createType, map, ex);
Debug.Fail(string.Format(errmsg, createType, map, ex));
}
}
}
base.MapContainer_MouseUp(sender, map, camera, e);
}
示例2: MapContainer_MouseDown
/// <summary>
/// Handles when the mouse button is raised on a map.
/// </summary>
/// <param name="sender">The <see cref="IToolTargetMapContainer"/> the event came from. Cannot be null.</param>
/// <param name="map">The <see cref="EditorMap"/>. Cannot be null.</param>
/// <param name="camera">The <see cref="ICamera2D"/>. Cannot be null.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data. Cannot be null.</param>
protected override void MapContainer_MouseDown(IToolTargetMapContainer sender, EditorMap map, ICamera2D camera, MouseEventArgs e)
{
var cursorPos = e.Position();
var worldPos = camera.ToWorld(cursorPos);
if (e.Button == MouseButtons.Right)
{
var ga = GridAligner.Instance;
var entity = new WallEntity(worldPos, ga.GridSize);
ga.Fit(entity);
map.AddEntity(entity);
SOM.SetSelected(entity);
}
base.MapContainer_MouseDown(sender, map, camera, e);
}