public void LeaveGarrison(GameObject unit) { if (IsGarrisoned(unit)) { InfantryBody body = unit.GetComponentInChildren <InfantryBody>(); body.enabled = true; unit.transform.SetParent(null); unit.transform.SetPositionAndRotation( new Vector3(unit.transform.position.x, transform.root.position.y, unit.transform.position.z), Quaternion.Euler(0f, unit.transform.eulerAngles.y, 0f)); if (HideGarrisoned) { unit.transform.localScale = Vector3.one; } } else { throw new InvalidOperationException("This unit is not garrisoned here."); } }
unit.transform.root != transform.root; // For the time being simply support infantry bodies only. Later perhaps refactor into an IGarrisonable interface. public void EnterGarrison(GameObject unit) { Assert.IsTrue(CanGarrison(unit), "Tried to garrison unit that cannot be garrisoned."); if (AvailableCount > 0) { InfantryBody body = unit.GetComponentInChildren <InfantryBody>(); Transform slot = GetFirstEmptySlot(); unit.transform.SetParent(slot); unit.transform.position = slot.position; unit.transform.rotation = slot.rotation; body.enabled = false; if (HideGarrisoned) { unit.transform.localScale = Vector3.one * 0.1f; } } else { throw new InvalidOperationException("Cannot garrison a unit as the garrison is already full."); } }