/// Credit drHogan
/// Sourced from - http://forum.unity3d.com/threads/screenspace-camera-tooltip-controller-sweat-and-tears.293991/#post-1938929
/// updated simonDarksideJ - refactored code to be more performant.
/// updated lucasvinbr - mixed with BoundTooltip, should work with Screenspace Camera (non-rotated) and Overlay
/// *Note - only works for non-rotated Screenspace Camera and Screenspace Overlay canvases at present, needs updating to include rotated Screenspace Camera and Worldspace!
//ToolTip is written by Emiliano Pastorelli, H&R Tallinn (Estonia), http://www.hammerandravens.com
//Copyright (c) 2015 Emiliano Pastorelli, H&R - Hammer&Ravens, Tallinn, Estonia.
//All rights reserved.
//Redistribution and use in source and binary forms are permitted
//provided that the above copyright notice and this paragraph are
//duplicated in all such forms and that any documentation,
//advertising materials, and other materials related to such
//distribution and use acknowledge that the software was developed
//by H&R, Hammer&Ravens. The name of the
//H&R, Hammer&Ravens may not be used to endorse or promote products derived
//from this software without specific prior written permission.
//THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
//IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
//WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
namespace UnityEngine.UI.Extensions
{
[RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/Tooltip/Tooltip")]
public class ToolTip : MonoBehaviour
{
//text of the tooltip
#if UNITY_2022_1_OR_NEWER
private TMPro.TMP_Text _text;
#else
private Text _text;
#endif
private RectTransform _rectTransform, canvasRectTransform;
[Tooltip("The canvas used by the tooltip as positioning and scaling reference. Should usually be the root Canvas of the hierarchy this component is in")]
public Canvas canvas;
[Tooltip("Sets if tooltip triggers will run ForceUpdateCanvases and refresh the tooltip's layout group " +
"(if any) when hovered, in order to prevent momentousness misplacement sometimes caused by ContentSizeFitters")]
public bool tooltipTriggersCanForceCanvasUpdate = false;
///
/// the tooltip's Layout Group, if any
///
private LayoutGroup _layoutGroup;
//if the tooltip is inside a UI element
private bool _inside;
private float width, height;//, canvasWidth, canvasHeight;
public float YShift,xShift;
[HideInInspector]
public RenderMode guiMode;
private Camera _guiCamera;
public Camera GuiCamera
{
get
{
if (!_guiCamera) {
_guiCamera = Camera.main;
}
return _guiCamera;
}
}
private Vector3 screenLowerLeft, screenUpperRight, shiftingVector;
///
/// a screen-space point where the tooltip would be placed before applying X and Y shifts and border checks
///
private Vector3 baseTooltipPos;
private Vector3 newTTPos;
private Vector3 adjustedNewTTPos;
private Vector3 adjustedTTLocalPos;
private Vector3 shifterForBorders;
private float borderTest;
// Standard Singleton Access
private static ToolTip instance;
public static ToolTip Instance
{
get
{
if (instance == null)
instance = FindObjectOfType();
return instance;
}
}
void Reset() {
canvas = GetComponentInParent