本文整理汇总了C#中OpenRA.Actor.TraitOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# Actor.TraitOrDefault方法的具体用法?C# Actor.TraitOrDefault怎么用?C# Actor.TraitOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenRA.Actor
的用法示例。
在下文中一共展示了Actor.TraitOrDefault方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneralProperties
public GeneralProperties(Actor self)
: base(self)
{
facing = self.TraitOrDefault<IFacing>();
autotarget = self.TraitOrDefault<AutoTarget>();
}
示例2: RefuelNear
public RefuelNear(Actor self, Actor host)
{
move = self.TraitOrDefault<IMove>();
target = Target.FromActor(host);
refuelsNear = host.TraitOrDefault<RefuelsUnitsNear>();
}
示例3: GetAttractiveness
///<summary>Evaluates a single actor according to the rules defined in this consideration</summary>
public int GetAttractiveness(Actor a, Stance stance, Player firedBy)
{
if (stance != Against)
return 0;
if (a == null)
return 0;
var targetable = a.TraitOrDefault<ITargetable>();
if (targetable == null)
return 0;
if (!targetable.TargetableBy(a, firedBy.PlayerActor))
return 0;
if (Types.Intersect(targetable.TargetTypes).Any())
{
switch (TargetMetric)
{
case DecisionMetric.Value:
var valueInfo = a.Info.Traits.GetOrDefault<ValuedInfo>();
return (valueInfo != null) ? valueInfo.Cost * Attractiveness : 0;
case DecisionMetric.Health:
var health = a.TraitOrDefault<Health>();
return (health != null) ? (health.HP / health.MaxHP) * Attractiveness : 0;
default:
return Attractiveness;
}
}
return 0;
}