本文整理汇总了C#中Unit.GetID方法的典型用法代码示例。如果您正苦于以下问题:C# Unit.GetID方法的具体用法?C# Unit.GetID怎么用?C# Unit.GetID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Unit
的用法示例。
在下文中一共展示了Unit.GetID方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MakeCard
protected void MakeCard(Unit unit, float count)
{
if (!isPlayer || guiCamera == null || !unit.IsOwnedByPlayer())
return;
GameObject labelGO = unit.GetLabel();
if (labelGO == null)
return;
GameObject unitCard = Instantiate(labelGO) as GameObject;
unitCard.layer = hudLayer;
unitCard.transform.parent = guiCamera.transform;
unitCard.transform.localRotation = Quaternion.identity;
unitCard.transform.localScale = Vector3.one / 27.5f;
GameObject unitCardBG = Instantiate(cardBackground) as GameObject;
unitCardBG.transform.parent = unitCard.transform;
unitCardBG.transform.localScale = new Vector3(125.0f, 50.0f, 1.0f);
unitCardBG.transform.localPosition = new Vector3(60.0f, -25.0f, 0.0f);
unitCardBG.transform.localRotation = Quaternion.identity;
float percentage = (count - 1.00f) / 10.00f;
unitCard.transform.position = guiCamera.ViewportToWorldPoint(new Vector3(0, 1 - percentage, 1));
int uID = unit.GetID();
if (unitCards.ContainsKey(uID))
Destroy(unitCards[uID]);
unitCards.Add(uID, unitCard);
}
示例2: PromoteUnit
public Unit PromoteUnit(Unit unit, UnitType type)
{
// If we're already of the correct type, no need to do anything.
if (unit.GetUnitType() == type)
return unit;
// Get how much this UnitType will cost.
float resourceCost = Unit.GetCost(type);
// If it's too expensive, we can't buy it.
if (resourceCost > resourceCount)
{
// The player gets a message seeing why it didn't work.
if (IsPlayer())
{
MessageList.Instance.AddMessage("You don't have enough resources to upgrade " + unit.name + " to " + type.ToString() + "!");
}
Debug.LogWarning("Too expensive to upgrade " + unit + " to a " + type.ToString() + "!");
return unit;
}
//
switch (type)
{
case UnitType.Commander:
{
// Not implemented.
Debug.LogError("You are trying to make a new Commander. This is not supported currently!");
return null;
}
case UnitType.Leader:
{
if (leaderCount >= MAX_LEADER_COUNT)
{
if (IsPlayer())
MessageList.Instance.AddMessage("You have too many Leaders already!");
Debug.LogWarning("We have too many Leaders already!");
return null;
}
Leader leader = unit.UpgradeUnit(this);
for (int i = 1; i <= MAX_LEADER_COUNT; i++)
{
if (leaders.ContainsKey(i))
continue;
leaders.Add(i, leader);
break;
}
unitID[leader.GetID()] = leader;
leaderCount++;
return leader;
}
case UnitType.Unit:
default:
{
Leader leader = unit as Leader;
if (leader == null)
return unit;
int i = -1;
foreach (KeyValuePair<int, Leader> kvp in leaders)
{
if (kvp.Value != leader)
continue;
i = kvp.Key;
break;
}
leaders.Remove(i);
unit = leader.DowngradeUnit();
unitID[unit.GetID()] = unit;
leaderCount--;
return unit;
}
}
}
示例3: AddUnit
public void AddUnit(Unit unit)
{
if (!IsAlive())
{
backloggedUnits.Add(unit);
Invoke("AddAllUnits", timeToOurRespawn + 0.5f);
return;
}
if (!unit.IsAlive())
{
backloggedUnits.Add(unit);
Invoke("AddAllUnits", unit.GetTimeUntilRespawn() + 0.5f);
return;
}
int id = unit.GetID();
if (allUnits.ContainsKey(id))
{
allUnits[id] = unit;
}
else
{
allUnits.Add(id, unit);
}
if (friendlyFire || unit == this)
return;
Collider[] cols = unit.GetComponents<Collider>();
foreach (Collider col in cols)
{
if (col.isTrigger || col.gameObject.GetComponent<Weapon>() != null)
continue;
col.enabled = true;
}
Unit[] allOurUnits = GetAllUnits();
foreach (Unit u in allOurUnits)
{
if (u == unit || !u.IsAlive())
continue;
Physics.IgnoreCollision(u.collider, unit.collider, true);
}
Physics.IgnoreCollision(unit.collider, collider, true);
}
示例4: IsEnemy
public bool IsEnemy(Unit unit)
{
return !unitID.ContainsKey(unit.GetID());
}
示例5: RegisterUnit
public void RegisterUnit(Unit unit)
{
int id = unit.GetID();
if (unitID.ContainsKey(id))
return;
if (leaderLookup.ContainsKey(id))
leaderLookup[id].RemoveUnit(id);
unitID.Add(id, unit);
commander.AddUnit(unit);
leaderLookup.Add(id, this);
if (orderData != null)
{
Order currentOrder = orderData.GetOrder();
Transform orderTarget = orderData.GetOrderTarget();
GiveOrder(currentOrder, orderTarget, unit);
}
ownedUnits = new Unit[unitID.Count];
unitID.Values.CopyTo(ownedUnits, 0);
Debug.Log("Registered ID number " + id);
}