public void SetWarning(Unit unit) { if (unit.IsProtect()) return; bool enable = unit.IsEnable(); if (enable && !unit.IsProtect()) { unit.SetEnable(false); } foreach (Room other in this.level.GetRooms()) { if (!this.level.IsReachFromStart(other, true)) { this.SetUnitColor(other, FloorColor.Warning); } } foreach (Route other in this.level.GetRoutes()) { if (!this.level.IsReachFromStart(other, true)) { this.SetUnitColor(other, FloorColor.Warning); } } if (enable) { unit.SetEnable(true); } }
public void DestroyIsolatedUnits(Unit origin) { List<Room> destroyRooms = new List<Room>(); List<int> roomDistances = new List<int>(); foreach (Room r in this.level.GetRooms() ) { if (!this.level.IsReachFromStart(r, true)) { destroyRooms.Add (r); origin.SetEnable(true); int distance = this.level.CalcDistance(origin, r); roomDistances.Add(distance); origin.SetEnable(false); } } foreach (Route route in this.level.GetRoutes()) { foreach (KeyValuePair<Vector2, Unit> pair in route.GetNeighbors()) { Vector2 pos = pair.Key; Unit u = pair.Value; if (!u.IsEnable()) { GameObject shutterPrefab = (GameObject)Resources.Load("Prefabs/shutterPrefab", typeof(GameObject)); GameObject routeTile = this.level.GetObject(pos); if (routeTile != null) { this.AddGate(routeTile, shutterPrefab); } } } if (!this.level.IsReachFromStart(route, true)) { origin.SetEnable(true); int distance = this.level.CalcDistance(origin, route); origin.SetEnable(false); this.StartCoroutine(this.DestroyUnitDelay(route, distance)); } } for (int i = 0; i < destroyRooms.Count; ++i) { Room r = destroyRooms[i]; int distance = roomDistances[i]; this.StartCoroutine(this.DestroyRoomDelay(r, distance)); } this.UpdatePath(); }