public static CanvasForCanvasUIElement Instance() { if (_instance == null) { _instance = FindObjectOfType <CanvasForCanvasUIElement>(); } return(_instance); }
public RectTransform GetUI() { if (ui == null) { CanvasForCanvasUIElement c = CanvasForCanvasUIElement.Instance(); ui = (Instantiate(prefab.gameObject) as GameObject).GetComponent <RectTransform>(); ui.SetParent(c.transform); ui.name += ui.parent.childCount; CanvasUIElementElement slave = ui.gameObject.AddComponent <CanvasUIElementElement>(); slave.owner = this; } return(ui); }
void Update() { if (activated) { CanvasForCanvasUIElement c = CanvasForCanvasUIElement.Instance(); Vector2 position = c.uiCamera.WorldToScreenPoint(transform.position); ui = GetUI(); ui.position = position; } else { ui.gameObject.SetActive(false); } }
public void UpdateTriangleUIParent(Show triangleShow) { Transform maslowTransform = transform.parent; Transform placeTobe = null; if (rb != null) { rb.simulated = false; } Show lastState = this.triangleShow; this.triangleShow = triangleShow; switch (triangleShow) { case Show.inChest: //if (lastState != Show.inChest) { Debug.Log("bringing to chest from " + lastState); } if (maslow.chestCanvas == null) { Debug.Log("need to set chest canvas for " + maslow.gameObject + " (" + maslow.transform.root + ")"); } placeTobe = maslow.chestCanvas.transform; SetTextVisible(false); break; case Show.playerUI: placeTobe = CanvasForCanvasUIElement.Instance().transform.Find("maslowanchor"); break; case Show.aboveHead: RectTransform ui = maslow.headScreenUI.GetComponent <CanvasUIElement>().ui; if (ui == null) { NS.Chrono.setTimeout(() => UpdateTriangleUIParent(triangleShow), 100); //Debug.Log("waiting for UI to happen..."); return; } if (rb != null) { rb.simulated = true; isColliding = false; } placeTobe = ui.Find("maslowanchor"); SetTextVisible(true); // keep just 2 on the screen at any given time, always giving preference to Player triangles. if (aboveHeads.Count >= maxAboveHeads) { for (int i = aboveHeads.Count - 1; i >= 0 && aboveHeads.Count >= maxAboveHeads; --i) { if (aboveHeads[i] == this) { break; } if (aboveHeads[i].maslow.tag != "Player") { aboveHeads[i].SetShow(Show.inChest); aboveHeads.RemoveAt(i); } } } aboveHeads.Add(this); break; } //if (maslowTransform.parent != placeTobe) { if (placeTobe == null) { Debug.Log("no place to be when state is " + triangleShow); } maslowTransform.SetParent(placeTobe); maslowTransform.localScale = Vector3.one; maslowTransform.localPosition = Vector3.zero; maslowTransform.rotation = Quaternion.identity; } }