/// <summary> /// close tool tip. Provide an optional string showing calling method. 'tooltipType' is the tooltip Type to close (default 'Any' but you can specify a particular type to close and to ignore the rest) /// </summary> public void CloseTooltip(string text = "Unknown", GenericTooltipType tooltipTypeToClose = GenericTooltipType.Any) { bool isProceed = true; /*Debug.LogFormat("[Tst] TooltipGeneric.cs -> CloseTooltip: \"{0}\", tooltipTypeToClose \"{1}\", current tooltipType \"{2}\"", text, tooltipTypeToClose, tooltipType);*/ if (tooltipTypeToClose != GenericTooltipType.Any) { //only close if current tooltip is specified type if (tooltipType != tooltipTypeToClose) { isProceed = false; } } if (isProceed == true) { //close tooltip tooltipGenericObject.SetActive(false); tooltipGenericCanvas.gameObject.SetActive(false); /*Debug.LogFormat("[UI] TooltipGeneric -> CloseTooltip: called by {0}{1}", text, "\n");*/ } }
/// <summary> /// Initialise Generic Tool tip. General Purpose. Can take one to three text segments and auto divides them as necessary. /// Unique to the Generic tool tip, colours are set by the calling method /// </summary> public void SetTooltip(GenericTooltipData data) { //open panel at start tooltipGenericCanvas.gameObject.SetActive(true); tooltipGenericObject.SetActive(true); genericText.gameObject.SetActive(true); genericHeader.gameObject.SetActive(false); genericDetail.gameObject.SetActive(false); dividerTop.gameObject.SetActive(false); dividerBottom.gameObject.SetActive(false); /*//set opacity to zero (invisible) * SetOpacity(0f);*/ //set state of all items in tooltip window genericText.text = data.main; //header if (string.IsNullOrEmpty(data.header) == false) { genericHeader.text = data.header; genericHeader.gameObject.SetActive(true); dividerTop.gameObject.SetActive(true); } //details if (string.IsNullOrEmpty(data.details) == false) { genericDetail.text = data.details; genericDetail.gameObject.SetActive(true); dividerBottom.gameObject.SetActive(true); } //type tooltipType = data.tooltipType; //update rectTransform to get a correct height as it changes every time with the dynamic menu resizing depending on number of buttons Canvas.ForceUpdateCanvases(); rectTransform = tooltipGenericObject.GetComponent <RectTransform>(); //get dimensions of dynamic tooltip float width = rectTransform.rect.width; float height = rectTransform.rect.height; float halfWidth = width * 0.5f; //place tooltip adjacent to the button data.screenPos.y -= height / 4; if (data.screenPos.y + height >= Screen.height) { data.screenPos.y -= (data.screenPos.y + height - Screen.height) + offset; } //to the right if (data.screenPos.x + width >= Screen.width) { data.screenPos.x -= (width * 2 + data.screenPos.x - Screen.width); /*data.screenPos.x -= (data.screenPos.x + width - Screen.width - width / 4);*/ } /*else if (screenPos.x - width <= 0) * { screenPos.x += width - screenPos.x; }*/ //minimum position of tooltip from Left Hand side is half width else if (data.screenPos.x <= halfWidth) { data.screenPos.x = halfWidth; } else { data.screenPos.x += width / 4; } //never applies, dead code //set new position tooltipGenericObject.transform.position = data.screenPos; Debug.LogFormat("[UI] TooltipGeneric.cs -> SetTooltip{0}", "\n"); }