本文整理汇总了C#中System.Entity.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.Remove方法的具体用法?C# Entity.Remove怎么用?C# Entity.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.Remove方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestComponentDoubleRemoval
public void TestComponentDoubleRemoval()
{
Entity entity = new Entity();
entity.Add(new ComponentA());
entity.Remove<ComponentA>();
entity.Remove<ComponentA>();
Assert.AreEqual(0, entity.ComponentCount);
}
示例2: TestContains
public void TestContains()
{
Entity entity = new Entity();
entity.Add(new ComponentA());
Assert.AreEqual(true, entity.Contains<ComponentA>());
entity.Remove<ComponentA>();
Assert.AreEqual(false, entity.Contains<ComponentA>());
}
示例3: MakeAttachable
public static void MakeAttachable(Entity entity, Main main)
{
Transform transform = entity.Get<Transform>();
Property<float> attachOffset = entity.GetOrMakeProperty<float>("AttachmentOffset", true);
Property<Entity.Handle> map = entity.GetOrMakeProperty<Entity.Handle>("AttachedMap");
Property<Map.Coordinate> coord = entity.GetOrMakeProperty<Map.Coordinate>("AttachedCoordinate");
if (main.EditorEnabled)
return;
Binding<Matrix> attachmentBinding = null;
CommandBinding deleteBinding = null;
CommandBinding<IEnumerable<Map.Coordinate>, Map> cellEmptiedBinding = null;
entity.Add(new NotifyBinding(delegate()
{
if (attachmentBinding != null)
{
entity.Remove(attachmentBinding);
entity.Remove(deleteBinding);
entity.Remove(cellEmptiedBinding);
}
Map m = map.Value.Target.Get<Map>();
coord.Value = m.GetCoordinate(Vector3.Transform(new Vector3(0, 0, attachOffset), transform.Matrix));
Matrix offset = transform.Matrix * Matrix.Invert(Matrix.CreateTranslation(m.Offset) * m.Transform);
attachmentBinding = new Binding<Matrix>(transform.Matrix, () => offset * Matrix.CreateTranslation(m.Offset) * m.Transform, m.Transform, m.Offset);
entity.Add(attachmentBinding);
deleteBinding = new CommandBinding(m.Delete, entity.Delete);
entity.Add(deleteBinding);
cellEmptiedBinding = new CommandBinding<IEnumerable<Map.Coordinate>, Map>(m.CellsEmptied, delegate(IEnumerable<Map.Coordinate> coords, Map newMap)
{
foreach (Map.Coordinate c in coords)
{
if (c.Equivalent(coord))
{
if (newMap == null)
entity.Delete.Execute();
else
map.Value = newMap.Entity;
break;
}
}
});
entity.Add(cellEmptiedBinding);
}, map));
entity.Add(new PostInitialization
{
delegate()
{
if (map.Value.Target == null)
{
Map closestMap = null;
int closestDistance = 3;
float closestFloatDistance = 3.0f;
Vector3 target = Vector3.Transform(new Vector3(0, 0, attachOffset), transform.Matrix);
foreach (Map m in Map.Maps)
{
Map.Coordinate targetCoord = m.GetCoordinate(target);
Map.Coordinate? c = m.FindClosestFilledCell(targetCoord, closestDistance);
if (c.HasValue)
{
float distance = (m.GetRelativePosition(c.Value) - m.GetRelativePosition(targetCoord)).Length();
if (distance < closestFloatDistance)
{
closestFloatDistance = distance;
closestDistance = (int)Math.Floor(distance);
closestMap = m;
}
}
}
if (closestMap == null)
entity.Delete.Execute();
else
map.Value = closestMap.Entity;
}
else
map.Reset();
}
});
}
示例4: Bind
public static void Bind(Entity result, Main main, Func<BEPUphysics.Entities.Entity, BEPUphysics.Entities.Entity, Vector3, Vector3, Vector3, ISpaceObject> createJoint, bool allowRotation, bool creating = false)
{
Transform mapTransform = result.GetOrCreate<Transform>("MapTransform");
Transform transform = result.GetOrCreate<Transform>("Transform");
Factory.Get<DynamicMapFactory>().InternalBind(result, main, creating, mapTransform);
DynamicMap map = result.Get<DynamicMap>();
Property<Entity.Handle> parentMap = result.GetOrMakeProperty<Entity.Handle>("Parent");
Property<Map.Coordinate> coord = result.GetOrMakeProperty<Map.Coordinate>("Coord");
Property<Direction> dir = result.GetOrMakeProperty<Direction>("Direction", true);
Action refreshMapTransform = delegate()
{
Entity parent = parentMap.Value.Target;
if (parent != null)
{
if (!parent.Active)
parent = null;
else
{
Map staticMap = parent.Get<Map>();
coord.Value = staticMap.GetCoordinate(transform.Position);
mapTransform.Position.Value = staticMap.GetAbsolutePosition(staticMap.GetRelativePosition(coord) - new Vector3(0.5f) + staticMap.Offset + map.Offset);
if (!allowRotation)
mapTransform.Orientation.Value = parent.Get<Transform>().Orientation;
}
}
else
mapTransform.Matrix.Value = transform.Matrix;
};
if (main.EditorEnabled)
result.Add(new NotifyBinding(refreshMapTransform, transform.Matrix, map.Offset));
ISpaceObject joint = null;
CommandBinding jointDeleteBinding = null, physicsUpdateBinding = null;
Action rebuildJoint = null;
rebuildJoint = delegate()
{
if (joint != null)
{
if (joint.Space != null)
main.Space.Remove(joint);
result.Remove(jointDeleteBinding);
if (physicsUpdateBinding != null)
result.Remove(physicsUpdateBinding);
physicsUpdateBinding = null;
joint = null;
jointDeleteBinding = null;
}
Entity parent = parentMap.Value.Target;
if (main.EditorEnabled)
{
refreshMapTransform();
return;
}
if (parent != null)
{
if (!parent.Active)
parent = null;
else
{
Map staticMap = parent.Get<Map>();
map.PhysicsEntity.Position = mapTransform.Position;
if (!allowRotation)
map.PhysicsEntity.Orientation = mapTransform.Quaternion;
if (dir != Direction.None && !main.EditorEnabled)
{
Vector3 relativeLineAnchor = staticMap.GetRelativePosition(coord) - new Vector3(0.5f) + staticMap.Offset + map.Offset;
Vector3 lineAnchor = staticMap.GetAbsolutePosition(relativeLineAnchor);
DynamicMap dynamicMap = parent.Get<DynamicMap>();
joint = createJoint(map.PhysicsEntity, dynamicMap == null ? null : dynamicMap.PhysicsEntity, map.PhysicsEntity.Position, staticMap.GetAbsoluteVector(dir.Value.GetVector()), lineAnchor);
main.Space.Add(joint);
map.PhysicsEntity.ActivityInformation.Activate();
if (dynamicMap != null)
{
physicsUpdateBinding = new CommandBinding(dynamicMap.PhysicsUpdated, rebuildJoint);
result.Add(physicsUpdateBinding);
}
jointDeleteBinding = new CommandBinding(parent.Delete, delegate()
{
parentMap.Value = null;
});
result.Add(jointDeleteBinding);
}
}
}
};
result.Add(new NotifyBinding(rebuildJoint, parentMap));
result.Add(new CommandBinding(result.Delete, delegate()
//.........这里部分代码省略.........
示例5: testRemoveComponent
public void testRemoveComponent()
{
Entity entity = new Entity();
Id id = new Id();
id.Value = 1;
entity.Add(id);
Name name = new Name();
name.Value = "bob";
entity.Add(name);
NodeList<TestNode> nodeList = Ash.GetNodeList<TestNode>();
Ash.AddEntity(entity);
//Ash.RemoveEntity(entity);
Assert.AreEqual(nodeList.Count, 1);
entity.Remove(typeof(Name));
Assert.AreEqual(nodeList.Count, 0); // entity should no longer be in nodeList
}
示例6: Bind
public static void Bind(Entity entity, Main main, Func<BEPUphysics.Entities.Entity, BEPUphysics.Entities.Entity, Vector3, Vector3, Vector3, ISpaceObject> createJoint, bool allowRotation, bool creating = false, bool directional = true)
{
Transform mapTransform = entity.GetOrCreate<Transform>("MapTransform");
mapTransform.Selectable.Value = false;
Transform transform = entity.GetOrCreate<Transform>("Transform");
Factory.Get<DynamicVoxelFactory>().InternalBind(entity, main, creating, mapTransform);
DynamicVoxel map = entity.Get<DynamicVoxel>();
Components.Joint jointData = entity.GetOrCreate<Components.Joint>("Joint");
Action refreshMapTransform = delegate()
{
Entity parent = jointData.Parent.Value.Target;
if (parent != null && parent.Active)
{
Voxel staticMap = parent.Get<Voxel>();
jointData.Coord.Value = staticMap.GetCoordinate(transform.Matrix.Value.Translation);
mapTransform.Position.Value = staticMap.GetAbsolutePosition(staticMap.GetRelativePosition(jointData.Coord) - new Vector3(0.5f) + staticMap.Offset + map.Offset.Value);
if (allowRotation)
{
if (main.EditorEnabled)
mapTransform.Quaternion.Value = transform.Quaternion;
}
else
{
Matrix parentOrientation = staticMap.Transform;
parentOrientation.Translation = Vector3.Zero;
mapTransform.Quaternion.Value = Quaternion.CreateFromRotationMatrix(parentOrientation);
}
}
else
mapTransform.Matrix.Value = transform.Matrix;
};
if (main.EditorEnabled)
entity.Add(new NotifyBinding(refreshMapTransform, transform.Matrix, transform.Quaternion, map.Offset, jointData.Parent));
ISpaceObject joint = null;
CommandBinding jointDeleteBinding = null, parentPhysicsUpdateBinding = null;
NotifyBinding parentStaticMoveBinding = null;
Action updateJoint = null;
Action rebuildJoint = null;
rebuildJoint = delegate()
{
if (jointDeleteBinding != null)
entity.Remove(jointDeleteBinding);
jointDeleteBinding = null;
if (parentPhysicsUpdateBinding != null)
entity.Remove(parentPhysicsUpdateBinding);
parentPhysicsUpdateBinding = null;
updateJoint();
};
updateJoint = delegate()
{
if (joint != null)
{
if (joint.Space != null)
main.Space.Remove(joint);
joint = null;
}
if (parentStaticMoveBinding != null)
{
entity.Remove(parentStaticMoveBinding);
parentStaticMoveBinding = null;
}
Entity parent = jointData.Parent.Value.Target;
if (main.EditorEnabled)
refreshMapTransform();
else if (parent != null && parent.Active)
{
Voxel parentStaticMap = parent.Get<Voxel>();
//map.PhysicsEntity.Position = mapTransform.Position;
if (!allowRotation)
map.PhysicsEntity.Orientation = mapTransform.Quaternion;
if (jointData.Direction != Direction.None)
{
Vector3 relativeLineAnchor = parentStaticMap.GetRelativePosition(jointData.Coord) - new Vector3(0.5f) + parentStaticMap.Offset + map.Offset;
Vector3 lineAnchor = parentStaticMap.GetAbsolutePosition(relativeLineAnchor);
DynamicVoxel parentDynamicMap = parent.Get<DynamicVoxel>();
joint = createJoint(map.PhysicsEntity, parentDynamicMap == null ? null : parentDynamicMap.PhysicsEntity, lineAnchor, parentStaticMap.GetAbsoluteVector(jointData.Direction.Value.GetVector()), parentStaticMap.GetAbsolutePosition(jointData.Coord));
main.Space.Add(joint);
map.PhysicsEntity.ActivityInformation.Activate();
if (parentDynamicMap != null && parentPhysicsUpdateBinding == null)
{
parentPhysicsUpdateBinding = new CommandBinding(parentDynamicMap.PhysicsUpdated, updateJoint);
entity.Add(parentPhysicsUpdateBinding);
}
//.........这里部分代码省略.........