//if spawned == null, we spawn a new unit immediately. if there is a spawned unit //we destroy it and defer the spawning of the new unit until that process has //completed by listening to the units destroyed event public void SpawnUnit(UnitType unit) { if (HasSpawnedUnit()) { selectedUnit = unit; spawned.Destroying += new DestroyingDelegate(spawned_Destroying); spawned.SetForDeletion(false); spawned = null; } else { CreateUnit(unit); } }
public Unit CreateUnit(UnitType unit) { Unit newUnit = (Unit)Entities.Instance.Create(unit, Parent); newUnit.Position = Position + new Vec3(0, 0, unit.SpawnHeight); newUnit.Rotation = Rotation; spawned = newUnit; newUnit.PostCreate(); selectedUnit = null; if (UnitSpawned != null) UnitSpawned(newUnit); return newUnit; }