本文整理汇总了C#中System.Entity.HasComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.HasComponent方法的具体用法?C# Entity.HasComponent怎么用?C# Entity.HasComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.HasComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override void Process(Entity e)
{
Health h = healthMapper.Get(e);
if (h == null)
return;
if (e.HasComponent<Origin>())
{
Origin o = e.GetComponent<Origin>();
Entity parent = o.Parent;
if (!parent.HasComponent<Body>() || !parent.GetComponent<Health>().IsAlive)
{
if (e.HasComponent<Health>())
e.GetComponent<Health>().SetHealth(e, 0);
else
e.Delete();
}
}
if (!h.IsAlive)
{
h.SetHealth(e, 0);
e.Delete();
}
}
示例2: UserClickedEntity
public bool UserClickedEntity(Entity user, Entity obj, int mouseClickType)
{
if (user.HasComponent(ComponentFamily.Hands))
{
//It's something with hands!
if (mouseClickType == MouseClickType.Left)
{
if (obj.HasComponent(ComponentFamily.Item))
{
//It's something with hands using their hands on an item!
return DoHandsToItemInteraction(user, obj);
}
if (obj.HasComponent(ComponentFamily.LargeObject))
{
//It's something with hands using their hands on a large object!
return DoHandsToLargeObjectInteraction(user, obj);
}
if (obj.HasComponent(ComponentFamily.Actor))
{
//It's something with hands using their hands on an actor!
return DoHandsToActorInteraction(user, obj);
}
}
if (mouseClickType == MouseClickType.Right)
{
if (obj.HasComponent(ComponentFamily.Item))
{
//It's something with hands using their hands on an item!
return DoHandsToItemInteraction(user, obj);
}
if (obj.HasComponent(ComponentFamily.LargeObject))
{
//It's something with hands using their hands on a large object!
return DoHandsToLargeObjectInteraction(user, obj);
}
if (obj.HasComponent(ComponentFamily.Actor))
{
//It's something with hands using their hands on an actor!
return DoHandsToActorInteraction(user, obj);
}
}
}
return false;
}
示例3: Process
public override void Process(Entity e)
{
if (!e.HasComponent<Animation>())
return;
Sprite sprite = e.GetComponent<Sprite>();
Animation anim = e.GetComponent<Animation>();
if (anim.Type != AnimationType.None)
{
anim._Tick += world.Delta;
if (anim._Tick >= anim.FrameRate)
{
anim._Tick -= anim.FrameRate;
switch (anim.Type)
{
case AnimationType.Loop:
sprite.FrameIndex++; //Console.WriteLine("Animation happened");
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);
}
}
}
示例4: apply
public bool apply(Entity entity)
{
foreach (Type componentType in ComponentTypes) {
if (!entity.HasComponent(componentType)) {
return false;
}
}
return true;
}
示例5: GetIconSprite
public static CluwneSprite GetIconSprite(Entity entity)
{
if(entity.HasComponent(ComponentFamily.Icon))
{
var icon = entity.GetComponent<IconComponent>(ComponentFamily.Icon).Icon;
if (icon == null)
return IoCManager.Resolve<IResourceManager>().GetNoSprite();
return icon;
}
return IoCManager.Resolve<IResourceManager>().GetNoSprite();
}
示例6: ProcessEntity
// Process a single entity if it has all required components.
internal void ProcessEntity(Entity entity)
{
// Make sure it has all required components.
foreach (var t in Types)
{
if (!entity.HasComponent(t))
{
return;
}
}
Process(entity);
}
示例7: RegisterEntity
public void RegisterEntity (Entity entity)
{
if (!entity.HasComponent<TransformComponent>())
{
Logger.Log.AddLogEntry (LogLevel.Error, "AIManager",
"An error occured while registering new entity in AIManager: " +
"'{0}' has no TransformComponent!}");
}
lock (entities)
{
entities.Add (entity);
}
}
示例8: ItemStats
public ItemStats(Entity item)
{
this.item = item;
if (translate == null)
{
translate = new StatTranslator();
}
stats = new float[Enum.GetValues(typeof(ItemStatEnum)).Length];
ParseSockets();
ParseExplicitMods();
if (item.HasComponent<Weapon>())
{
ParseWeaponStats();
}
}
示例9: ApplyTo
public override bool ApplyTo(Entity target, Entity sourceActor)
{
string sourceName = sourceActor.Name;
string targetName = (sourceActor.Uid == target.Uid) ? "himself" : target.Name;
if (!active)
{
IoCManager.Resolve<IChatManager>()
.SendChatMessage(ChatChannel.Damage, sourceName + " tries to attack " + targetName
+ " with the " + owner.Owner.Name + ", but nothing happens!",
null, sourceActor.Uid);
return true;
}
var targetedArea = BodyPart.Torso;
ComponentReplyMessage reply = sourceActor.SendMessage(this, ComponentFamily.Actor,
ComponentMessageType.GetActorSession);
if (reply.MessageType == ComponentMessageType.ReturnActorSession)
{
var session = (IPlayerSession) reply.ParamsList[0];
targetedArea = session.TargetedArea;
}
else
throw new NotImplementedException("Actor has no session or No actor component that returns a session");
//Damage the item that is doing the damage.
owner.Owner.SendMessage(this, ComponentMessageType.Damage, owner.Owner, 5, DamageType.Collateral);
//Damage the target.
if (target.HasComponent(ComponentFamily.Damageable))
{
target.SendMessage(this, ComponentMessageType.Damage, owner.Owner, damageAmount, damType, targetedArea);
//string suffix = (sourceActor.Uid == target.Uid) ? " What a fucking weirdo..." : "";
IoCManager.Resolve<IChatManager>()
.SendChatMessage(ChatChannel.Damage,
sourceName + " " + DamTypeMessage(damType) + " " + targetName + " in the " +
BodyPartMessage(targetedArea) + " with a " + owner.Owner.Name + "!",
null, sourceActor.Uid);
return true;
}
return false;
}
示例10: BigEnemyDeath
public static Action<Entity> BigEnemyDeath(Entity e, EntityWorld _World, int points)
{
return ent =>
{
Vector2 poss = e.GetComponent<ITransform>().Position;
_World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, ent, e.GetComponent<IVelocity>().LinearVelocity);
int splodeSound = rbitch.Next(1, 5);
SoundManager.Play("Explosion" + splodeSound.ToString());
if (ent is Entity && (ent as Entity).Group != null && ((ent as Entity).Group == "Players" || (ent as Entity).Group == "Structures") && e.HasComponent<Crystal>())
{
_World.CreateEntity("Crystal", e.GetComponent<ITransform>().Position, e.GetComponent<Crystal>().Color, e.GetComponent<Crystal>().Amount, e);
ScoreSystem.GivePoints(points);
_World.CreateEntity("Score", points.ToString(), poss).Refresh();
}
};
}
示例11: Process
public override void Process(Entity e)
{
ITransform t = TransformMapper.Get(e);
if (t == null)
return;
if (Vector2.Distance(t.Position, Vector2.Zero) > bound)
{
e.Delete();
return;
}
if (e.HasComponent<Components.Timer>() && e.GetComponent<Components.Timer>().Update(world.Delta))
{
if (e.Tag == "Boss1")
Console.WriteLine("Whooops");
e.Delete();
}
}
示例12: Process
public override void Process(Entity e)
{
Slow slow = slowMapper.Get(e);
if (slow != null && slow != Slow.None) //If particle is slowing
{
slow.Elapsed--;
if (slow.Elapsed <= 0)
{
e.RemoveComponent<Slow>(slow);
IDamping d = dampingMapper.Get(e);
d.LinearDamping = 0;
d.AngularDamping = 0;
if (e.HasComponent<AI>())
{
AI a = e.GetComponent<AI>();
e.RemoveComponent<AI>(e.GetComponent<AI>());
a.Calculated = false;
e.AddComponent<AI>(a);
}
e.Refresh();
return;
}
IVelocity velocity = velocityMapper.Get(e);
IDamping damping = dampingMapper.Get(e);
//Slow particle angular speed
if (velocity.AngularVelocity > slow.AngularTargetVelocity || damping.AngularDamping != slow.AngularSlowRate)
damping.AngularDamping = slow.AngularSlowRate;
else
damping.AngularDamping = 0;
//Slow particle linear speed
if (velocity.LinearVelocity.Length() - slow.LinearTargetVelocity.Length() > 1 || damping.LinearDamping != slow.LinearSlowRate)
damping.LinearDamping = slow.LinearSlowRate;
else
damping.LinearDamping = 0;
SpawnFrostEffect(e);
}
}
示例13: ApplyTo
public override bool ApplyTo(Entity target, Entity sourceActor)
{
if (capacity <= 0)
{
return false;
//TODO send the player using the item a message
}
var targetedArea = BodyPart.Torso;
ComponentReplyMessage reply = sourceActor.SendMessage(this, ComponentFamily.Actor,
ComponentMessageType.GetActorSession);
if (reply.MessageType == ComponentMessageType.ReturnActorSession)
{
var session = (IPlayerSession) reply.ParamsList[0];
targetedArea = session.TargetedArea;
}
else
throw new NotImplementedException("Actor has no session or No actor component that returns a session");
//Reduce the capacity.
capacity -= 20;
//Heal the target.
if (target.HasComponent(ComponentFamily.Damageable))
{
target.SendMessage(this, ComponentMessageType.Heal, owner.Owner, 20, damType, targetedArea);
string sourceName = sourceActor.Name;
string targetName = (sourceActor.Uid == target.Uid) ? "his" : target.Name + "'s";
//string suffix = (sourceActor.Uid == target.Uid) ? " What a fucking weirdo..." : "";
IoCManager.Resolve<IChatManager>()
.SendChatMessage(ChatChannel.Damage,
sourceName + " applies the " + owner.Owner.Name + " to " + targetName + " " +
BodyPartMessage(targetedArea) + ".",
null, sourceActor.Uid);
return true;
}
return false;
}
示例14: SetMaster
public void SetMaster(Entity m)
{
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
示例15: PickUpEntity
public bool PickUpEntity(Entity user, Entity obj)
{
HumanHandsComponent userHands = user.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
BasicItemComponent objItem = obj.GetComponent<BasicItemComponent>(ComponentFamily.Item);
if (userHands != null && objItem != null)
{
return AddEntity(user, user, obj, userHands.CurrentHand);
}
else if (userHands == null && objItem != null && obj.HasComponent(ComponentFamily.Inventory))
{
return AddEntity(user, user, obj, InventoryLocation.Inventory);
}
return false;
}