本文整理匯總了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;
}