public UnitOverlay Clone(string name = "") { UnitOverlay newOverlay = new UnitOverlay(); newOverlay.rootObj = (GameObject)MonoBehaviour.Instantiate(rootObj); newOverlay.rootObj.name = name == "" ? rootObj.name + "(Clone)" : name; newOverlay.Init(); newOverlay.rootT.SetParent(rootT.parent); newOverlay.rootT.localScale = rootT.localScale; return(newOverlay); }
UnitOverlay GetUnusedOverlay() { for (int i = 0; i < overlayList.Count; i++) { if (!overlayList[i].rootObj.activeInHierarchy) { return(overlayList[i]); } } UnitOverlay overlay = overlayList[0].Clone(); overlayList.Add(overlay); return(overlay); }
IEnumerator _UnitOverlay(Unit unit) { if (overlayedUnitList.Contains(unit)) { yield break; } overlayedUnitList.Add(unit); UnitOverlay overlay = GetUnusedOverlay(); overlay.rootObj.SetActive(true); if (unit.defaultShield > 0) { overlay.barShield.gameObject.SetActive(true); } else { overlay.barShield.gameObject.SetActive(false); } while (unit != null && !unit.dead && unit.thisObj.activeInHierarchy) { overlay.barHP.value = unit.HP / unit.fullHP; if (unit.defaultShield > 0) { overlay.barShield.value = unit.shield / unit.fullShield; } Vector3 screenPos = mainCam.WorldToScreenPoint(unit.thisT.position + new Vector3(0, 0, 0)); overlay.rootT.localPosition = (screenPos + new Vector3(0, 20, 0)) / UI.GetScaleFactor(); if (overlay.barHP.value == 1 && overlay.barShield.value == 1) { break; } yield return(null); } overlay.rootObj.SetActive(false); overlayedUnitList.Remove(unit); }