// Update is called once per frame void Update() { if (currentTarget) { var name = currentTarget.name; var hoverInfo = currentTarget.GetComponent <HoverInfo>(); if (hoverInfo != null && hoverInfo.Display != "") { name = hoverInfo.Display; } var c = currentTarget.GetComponent <Collider>(); UIBounds uibounds = UIBounds.fromBounds(c.bounds); BoundsBox.gameObject.SetActive(true); BoundsBox.anchoredPosition = uibounds.ScreenPointBounds.BottomLeft; BoundsBox.sizeDelta = uibounds.ScreenPointBounds.Size; BoundsBox.ForceUpdateRectTransforms(); Label.gameObject.SetActive(true); Label.SetText(name); if (uibounds.ViewportBounds.center.y > 0.5f) { Label.alignment = TMPro.TextAlignmentOptions.Top; Label.rectTransform.anchoredPosition = uibounds.ScreenPointBounds.Bottom; Label.rectTransform.pivot = new Vector2(0.5f, 1f); } else { Label.alignment = TMPro.TextAlignmentOptions.Bottom; Label.rectTransform.anchoredPosition = uibounds.ScreenPointBounds.Top; Label.rectTransform.pivot = new Vector2(0.5f, 0f); } Label.rectTransform.ForceUpdateRectTransforms(); } else { BoundsBox.gameObject.SetActive(false); Label.gameObject.SetActive(false); } }
/// <summary> /// Returns a new Rectangle. /// </summary> /// <param name="bounds">The UIBounds.</param> /// <returns>Rectangle</returns> public static Rectangle ToRectangle(this UIBounds bounds) { return(new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height)); }