本文整理汇总了C#中Entity.HasComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.HasComponent方法的具体用法?C# Entity.HasComponent怎么用?C# Entity.HasComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity.HasComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EntityBeliefs
public EntityBeliefs(Beliefs beliefs, Entity ent)
{
Beliefs = beliefs;
Entity = ent;
Type = ent.HasComponent<Survivor>() ? EntityType.Survivor
: ent.HasComponent<Zombie>() ? EntityType.Zombie
: ent.HasComponent<WoodPile>() ? EntityType.PlankPile
: ent.HasComponent<WoodenBreakable>() ? EntityType.PlankSource
: EntityType.Other;
Update();
}
示例2: OnAdded
public override void OnAdded(Entity entity)
{
if (entity.HasComponent<ShipComponent>())
{
entity.AddComponent(new SpatialTokenComponent { Token = Ships.AllocateToken(entity) });
}
}
示例3: DeleteLocalString
public static void DeleteLocalString(Entity entity, string key)
{
if (!entity.HasComponent<LocalData>()) return;
LocalData data = entity.GetComponent<LocalData>();
if (data.LocalStrings.ContainsKey(key))
data.LocalStrings.Remove(key);
}
示例4: Process
public override void Process(Entity e)
{
if (!e.HasComponent<FadingText>())
return;
e.GetComponent<FadingText>().Draw(spriteBatch, spriteFont);
}
示例5: OnRemoveEntity
private void OnRemoveEntity(Entity entity)
{
if (entity.HasComponent<ShipComponent>())
{
var token = entity.GetComponent<SpatialTokenComponent>().Token;
token.Dispose();
}
}
示例6: OnUse
public override void OnUse(Entity targetEnt)
{
if (targetEnt.HasComponent(ComponentFamily.StatusEffects)) //Use component messages instead.
{
var statComp = (StatusEffectComp) targetEnt.GetComponent(ComponentFamily.StatusEffects);
statComp.AddEffect("Bleeding", 10);
parent.StartCooldown(this);
}
}
示例7: Process
public override void Process(Entity entity)
{
if (!entity.HasComponent<TimeStamp>())
{
Int32 unixTimestamp = (Int32)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
entity.AddComponent(new TimeStamp(unixTimestamp));
entity.Refresh();
}
}
示例8: Process
public override void Process(Entity e)
{
if (!e.HasComponent<AI>())
return;
AI ai = e.GetComponent<AI>();
bool behavior;
if (ai.Target != null)
{
if (World.EntityManager.GetEntity((ai.Target.UserData as Entity).Id) == null)
ai.Target = null;
else if (!(!ai.Recalculate && ai.Calculated) && ai.Target != null && (ai.Target.UserData as Entity) != null && !(behavior = ai.Behavior(ai.Target))) //Run ai behavior, if behavior returns true look for new target.
{
ai.Calculated = true;
if (ai.Target == null && e.Group != "Players" && e.Group != "Structures" && !e.Tag.Contains("Cannon"))
{
if (e.HasComponent<Health>())
e.GetComponent<Health>().SetHealth(null, 0);
else
e.Delete();
}
return;
}
}
ai.Calculated = true;
ai.Target = _FindNewTarget(ai, e.GetComponent<Body>());
if (ai.Target == null && e.Group != "Players" && e.Group != "Structures" && !e.Tag.Contains("Boss"))
{
if (e.HasComponent<Health>())
e.GetComponent<Health>().SetHealth(null, 0);
else
e.Delete();
}
else if (ai.Target == null && e.Group == "Players")
ai.Behavior(null);
e.Refresh();
}
示例9: Matches
public override bool Matches(Entity entity)
{
for (int i = 0, indicesLength = indices.Length; i < indicesLength; i++) {
if (entity.HasComponent(indices[i])) {
return false;
}
}
return true;
}
示例10: GetIconSprite
public static Sprite 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();
}
示例11: GetIsHostile
public static bool GetIsHostile(Entity entity)
{
try
{
return entity.HasComponent<Hostile>();
}
catch (Exception)
{
return false;
}
}
示例12: SetMaster
public void SetMaster(Entity m)
{
if (!m.HasComponent(ComponentFamily.Renderable))
return;
var mastercompo = m.GetComponent<IRenderableComponent>(ComponentFamily.Renderable);
//If there's no sprite component, then FUCK IT
if (mastercompo == null)
return;
mastercompo.AddSlave(this);
master = mastercompo;
}
示例13: HandleCollision
public void HandleCollision(Entity entity, Entity other)
{
if (other.HasComponent<CollisionBehaviorComponent> ())
{
CollisionDispatcher dispatcher = other.GetComponent<CollisionBehaviorComponent> ()
.Behavior as CollisionDispatcher;
if (dispatcher != null)
{
dispatcher.DispatchCollision (this, other, entity);
}
}
}
示例14: AddModifier
/// <summary>
/// Add a Modifier script to an Entity, based on a code block (delegate) and a VectorFunction
/// </summary>
/// <param name="e">Entity to add modifier script to</param>
/// <param name="scriptCode">Code block (delegate) that is the script</param>
/// <param name="func">Function whose value will be passed in ScriptContext.FunctionValue to script</param>
/// <returns></returns>
public static VectorModifierScript AddModifier(Entity e, VectorModifierDelegate scriptCode, IVectorFunction func)
{
if (!e.HasComponent<ScriptComp>())
{
e.AddComponent(new ScriptComp());
e.Refresh();
}
var sc = e.GetComponent<ScriptComp>();
var script = new VectorModifierScript(scriptCode, func);
sc.Add(script);
return script;
}
示例15: Process
public override void Process(Entity e)
{
if (!e.HasComponent<FadingText>())
return;
FadingText f = e.GetComponent<FadingText>();
f.Update(world.Delta);
if (f.Fraction() <= 0)
{
e.Delete();
}
}