本文整理汇总了C#中Entity.RemoveComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.RemoveComponent方法的具体用法?C# Entity.RemoveComponent怎么用?C# Entity.RemoveComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity.RemoveComponent方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override void Process(Entity e)
{
Sprite sprite = e.GetComponent<Sprite>();
Animation anim = e.GetComponent<Animation>();
if (anim.Type != AnimationType.None)
{
anim._Tick++;
anim._Tick %= anim.FrameRate;
if (anim._Tick == 0) //If time to animate.
{
switch (anim.Type)
{
case AnimationType.Loop:
sprite.FrameIndex++;
break;
case AnimationType.ReverseLoop:
sprite.FrameIndex--;
break;
case AnimationType.Increment:
sprite.FrameIndex++;
anim.Type = AnimationType.None;
break;
case AnimationType.Decrement:
sprite.FrameIndex--;
anim.Type = AnimationType.None;
break;
case AnimationType.Bounce:
sprite.FrameIndex += anim.FrameInc;
if (sprite.FrameIndex == sprite.Source.Count() - 1)
anim.FrameInc = -1;
if (sprite.FrameIndex == 0)
anim.FrameInc = 1;
break;
case AnimationType.Once:
if (sprite.FrameIndex < sprite.Source.Count() - 1)
sprite.FrameIndex++;
else
anim.Type = AnimationType.None;
break;
}
e.RemoveComponent<Sprite>(e.GetComponent<Sprite>());
e.AddComponent<Sprite>(sprite);
}
}
}
示例2: Process
public override void Process(Entity entity)
{
var position = entity.GetComponent<Position> ().position;
var target = entity.GetComponent<Target> ().Entity;
if(target == null || !target.HasComponent<Position>() || target.GetComponent<UnitState>().state == UnitState.State.dead)
{
// EntityWorld.DeleteEntity(entity);
entity.RemoveComponent<Position>();
return;
}
var targetPosition = target.GetComponent<Position> ().position;
var projectile = entity.GetComponent<Projectile> ();
if (!AIUtils.MakeStepToPosition(entity, new SlimMath.Vector2(targetPosition.X+300, targetPosition.Y+1000)))
return;
entity.RemoveComponent<Position>();
switch(projectile.AttackAction)
{
case Attack.TargetAction.block:
target.AddComponent(new Block());
AIUtils.TriggerBlock(target);
break;
case Attack.TargetAction.dodge:
target.AddComponent(new Dodge());
AIUtils.TriggerDodge(target);
break;
case Attack.TargetAction.hit:
AIUtils.TriggerHit (target, projectile.Damage);
break;
default:
break;
}
}
示例3: Process
public override void Process(Entity entity)
{
var perkNames = entity.GetComponent<PerkTemplate> ().perks;
List<Entity> perksCollection = new List<Entity> ();
foreach(var name in perkNames)
perksCollection.Add(DBMagager.CreateEntityByTemplateName(EntityWorld, name));
perksCollection = perksCollection.OrderBy (p => p.GetComponent<Perk> ().branch).ThenBy (p => p.GetComponent<Perk> ().perkLevel).ToList();
foreach (var perkEntity in perksCollection)
{
var putOnCommand = EntityWorld.CreateEntity ();
putOnCommand.AddComponent (new Command ());
putOnCommand.AddComponent (new SetPerkCommand (entity.entityId, perkEntity.entityId));
putOnCommand.Refresh ();
}
entity.RemoveComponent<PerkTemplate>();
}
示例4: Process
public override void Process(Entity entity)
{
var hit = entity.GetComponent<Hit>();
if (AIUtils.IsDead(entity))
{
entity.RemoveComponent<Hit>();
return;
}
hit.timer--;
if(hit.timer <= 0)
{
AIUtils.SetState(entity, UnitState.State.idle);
entity.RemoveComponent<Hit>();
}
}
示例5: DrawComponent
public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
{
var componentType = component.GetType();
var componentName = EntityExtension.RemoveComponentSuffix(componentType.Name);
if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {
var fields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);
var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
EntitasEditorLayout.BeginVerticalBox(boxStyle);
{
EntitasEditorLayout.BeginHorizontal();
{
if (fields.Length == 0) {
EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
} else {
unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
}
if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
entity.RemoveComponent(index);
}
}
EntitasEditorLayout.EndHorizontal();
if (unfoldedComponents[index]) {
foreach (var field in fields) {
var value = field.GetValue(component);
DrawAndSetElement(field.FieldType, field.Name, value,
entity, index, component, field.SetValue);
}
}
}
EntitasEditorLayout.EndVertical();
}
}
示例6: drawComponent
void drawComponent(EntityBehaviour entityBehaviour, Entity entity, int index, IComponent component) {
var componentType = component.GetType();
var fields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);
EditorGUILayout.BeginVertical(GUI.skin.box);
{
EditorGUILayout.BeginHorizontal();
{
if (fields.Length == 0) {
EditorGUILayout.LabelField(componentType.RemoveComponentSuffix(), EditorStyles.boldLabel);
} else {
entityBehaviour.unfoldedComponents[index] = EditorGUILayout.Foldout(entityBehaviour.unfoldedComponents[index], componentType.RemoveComponentSuffix(), _foldoutStyle);
}
if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
entity.RemoveComponent(index);
}
}
EditorGUILayout.EndHorizontal();
if (entityBehaviour.unfoldedComponents[index]) {
foreach (var field in fields) {
var value = field.GetValue(component);
DrawAndSetElement(field.FieldType, field.Name, value,
entity, index, component, newValue => field.SetValue(component, newValue));
}
}
}
EditorGUILayout.EndVertical();
}
示例7: EnslaveMovementAndSprite
public void EnslaveMovementAndSprite(Entity master, Entity slave)
{
slave.RemoveComponent(ComponentFamily.Mover);
slave.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>());
slave.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(master);
if (slave.HasComponent(ComponentFamily.Renderable) && master.HasComponent(ComponentFamily.Renderable))
{
slave.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(master);
}
}
示例8: FreeMovementAndSprite
public void FreeMovementAndSprite(Entity slave)
{
var toRemoveSlaveMover = slave.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover);
if (toRemoveSlaveMover != null)
{
toRemoveSlaveMover.Detach();
}
if (slave.HasComponent(ComponentFamily.Renderable))
{
slave.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster();
}
slave.RemoveComponent(ComponentFamily.Mover);
slave.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>());
slave.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped();
}
示例9: DrawComponent
public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
{
var componentType = component.GetType();
var componentName = componentType.Name.RemoveComponentSuffix();
if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {
var memberInfos = componentType.GetPublicMemberInfos();
var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
EntitasEditorLayout.BeginVerticalBox(boxStyle);
{
EntitasEditorLayout.BeginHorizontal();
{
if (memberInfos.Length == 0) {
EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
} else {
unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
}
if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
entity.RemoveComponent(index);
}
}
EntitasEditorLayout.EndHorizontal();
if (unfoldedComponents[index]) {
foreach (var info in memberInfos) {
DrawAndSetElement(info.type, info.name, info.GetValue(component),
entity, index, component, info.SetValue);
}
}
}
EntitasEditorLayout.EndVertical();
}
}
示例10: DrawComponent
public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
{
var componentType = component.GetType();
var componentName = componentType.Name.RemoveComponentSuffix();
if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {
var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
EntitasEditorLayout.BeginVerticalBox(boxStyle);
{
var memberInfos = componentType.GetPublicMemberInfos();
EntitasEditorLayout.BeginHorizontal();
{
if (memberInfos.Count == 0) {
EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
} else {
unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
}
if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
entity.RemoveComponent(index);
}
}
EntitasEditorLayout.EndHorizontal();
if (unfoldedComponents[index]) {
var componentDrawer = getComponentDrawer(componentType);
if (componentDrawer != null) {
var newComponent = entity.CreateComponent(index, componentType);
component.CopyPublicMemberValues(newComponent);
EditorGUI.BeginChangeCheck();
{
componentDrawer.DrawComponent(newComponent);
}
var changed = EditorGUI.EndChangeCheck();
if (changed) {
entity.ReplaceComponent(index, newComponent);
} else {
entity.GetComponentPool(index).Push(newComponent);
}
} else {
foreach (var info in memberInfos) {
DrawAndSetElement(info.type, info.name, info.GetValue(component),
entity, index, component, info.SetValue);
}
}
}
}
EntitasEditorLayout.EndVertical();
}
}
示例11: CommandSuccseded
public static void CommandSuccseded(Entity command)
{
if (command.HasComponent<ProcessCommand>())
{
command.RemoveComponent<ProcessCommand>();
}
command.AddComponent(new CommandComplete());
command.AddComponent(new SaveCommand());
}
示例12: AddEditorComponentsToPartEntity
private void AddEditorComponentsToPartEntity(Entity entity)
{
entity.AddComponent(new EditorComponent());
var select = new BoundingBoxSelectorComponent() { IsEnabled = false };
entity.AddComponent(select);
var drawbounds = new DrawBoundingBoxComponent();
drawbounds.IsEnabled = false;
entity.AddComponent(drawbounds);
select.SelectedChanged += (s, e) =>
{
drawbounds.IsEnabled = select.IsSelected;
if (!select.IsSelected)
entity.RemoveComponent<MouseControlledTransformComponent>();
};
entity.AddComponent(entity.GetComponent<IShipPartComponent>().Part.Transform);
if (entity.HasComponent<DummyPartComponent>())
{
entity.AddComponent(new GenericDrawableComponent((a, b, e) => {
var xform = e.GetComponent<Transform>();
b.DrawCircle(xform.Position, 9, 15, Color.Cyan);
b.DrawLine(xform.Position.X - 10, xform.Position.Y, xform.Position.X + 10, xform.Position.Y, Color.LightCyan);
b.DrawLine(xform.Position.X, xform.Position.Y - 10, xform.Position.X, xform.Position.Y + 10, Color.LightCyan);
}));
}
entity.Refresh();
}
示例13: ChangeGun
public void ChangeGun(Entity e, GunType gun)
{
if (e.GetComponent<Gun>() != null)
{
CurrentGun.Ammunition = e.GetComponent<Gun>().Ammunition;
e.RemoveComponent<Gun>(e.GetComponent<Gun>());
}
_CurrentGunType = gun;
e.AddComponent<Gun>(CurrentGun);
}
示例14: Process
public override void Process(Entity e)
{
AI ai = e.GetComponent<AI>();
switch (ai.Targeting)
{
case Targeting.Closest:
ai.Target = ClosestTarget(e);
break;
case Targeting.Strongest:
ai.Target = StrongestEntity(world.GetBodiesInArea(e.GetComponent<ITransform>().Position, ai.SearchRadius)).GetComponent<Body>();
break;
case Targeting.Weakest:
ai.Target = WeakestEntity(world.GetBodiesInArea(e.GetComponent<ITransform>().Position, ai.SearchRadius)).GetComponent<Body>();
break;
}
if (e.Group == "Crystals")
{
if ((ai.Target.UserData as Entity).DeletingState != true)
{
Vector2 distance = e.GetComponent<AI>().Target.Position - e.GetComponent<Body>().Position;
distance.Normalize();
e.GetComponent<Body>().LinearVelocity = distance * new Vector2(7);
}
else
{
e.Delete();
//ai.Target = ClosestTarget(e);
}
}
e.RemoveComponent<AI>(e.GetComponent<AI>());
e.AddComponent<AI>(ai);
}