Example #1
0
    /// <summary>
    /// Enables / Disables the tooltip
    /// </summary>
    /// <param name="enable">true enables, false disables</param>
    public void EnableTooltip(bool enable)
    {
        if (enable)
        {
            PanelUtilities.ActivatePanel(Instance.GetComponent <CanvasGroup>());
        }
        else
        {
            PanelUtilities.DeactivatePanel(Instance.GetComponent <CanvasGroup>());
        }

        active = enable;
    }
 void OnEnable()
 {
     Application.targetFrameRate = 60;
     TooltipTransform            = Tooltip.GetComponent <RectTransform>();
     RectTransform = GetComponent <RectTransform>();
     Instance      = this;
 }
Example #3
0
    /// <summary>
    /// Update the data of the tooltip with the provided source data.
    /// </summary>
    /// <param name="source">Tooltip object to pull the data from.</param>
    public void UpdateTooltip(Tooltip source)
    {
        if (header != null)
        {
            header.text = source.header;
        }
        if (body != null)
        {
            body.text = source.text;
        }
        if (icon != null)
        {
            icon.sprite  = source.icon;
            icon.enabled = (source.icon != null);
        }

        followMouse = source.followMouse;
        alignment   = source.alignment;
        target      = source.GetComponent <RectTransform>();

        if (source.offset == Vector2.zero)
        {
            offset = Vector2.zero;
        }
        else
        {
            if (alignment == TooltipAlignment.Default)
            {
                offset = (target != null) ? (target.position / 2f) - (Input.mousePosition / 2f) : Vector3.zero;
            }
            else if (alignment == TooltipAlignment.Above)
            {
                offset = new Vector2(0f, self.rect.height / 2f) + source.offset;
            }
            else if (alignment == TooltipAlignment.Below)
            {
                offset = new Vector2(0f, -self.rect.height / 2f) + source.offset;
            }
            else if (alignment == TooltipAlignment.Left)
            {
                offset = new Vector2(-self.rect.width / 2f, -self.rect.height / 2f) + source.offset;
            }
            else if (alignment == TooltipAlignment.Right)
            {
                offset = new Vector2(self.rect.width / 2f, -self.rect.height / 2f) + source.offset;
            }
        }
    }
 private void GetInitColors()
 {
     Object[] _allGameObjects = FindObjectsOfType <GameObject>();
     foreach (GameObject obj in _allGameObjects)
     {
         Tooltip _objTooltip = obj?.GetComponent <Tooltip>();
         if (_objTooltip != null)
         {
             Renderer _objRenderer = _objTooltip?.GetComponent <Renderer>();
             if (_objRenderer != null)
             {
                 _storedColors.Add(_objTooltip.GetInstanceID(), _objRenderer.material.color);
             }
         }
     }
 }
Example #5
0
    public static void Show(Tooltip tip)
    {
        if (string.IsNullOrEmpty(tip.text))
        {
            _Hide();
            return;
        }

        displayedTip = tip;

        RectTransform rt = tip.GetComponent <RectTransform>();

        rt.GetWorldCorners(WorldCorners);

        Instance.window.position = WorldCorners[0] + new Vector3(4, -4, 0);

        Instance.window.gameObject.SetActive(true);
        if (Time.realtimeSinceStartup - hideTime < 0.3f)
        {
            Instance.animator.Play("TooltipShow", 0, 0.909f);
        }
        else
        {
            showTime = Time.realtimeSinceStartup;
            Instance.animator.Play("TooltipShow", 0, 0f);
        }

        Instance.field.text = tip.text;
        int textLength = tip.text.Length;

        Instance.layoutElement.enabled = tip.text.Length > Instance.characterWrapLimit;

        Instance.layout.enabled = false;
        Instance.layout.enabled = true;
        LayoutRebuilder.ForceRebuildLayoutImmediate(Instance.layout.GetComponent <RectTransform>());

        Instance.layoutElement.enabled        = tip.text.Length > Instance.characterWrapLimit;
        Instance.layoutElement.preferredWidth = Mathf.Min(500f, Instance.field.preferredWidth + 18f);
    }
 private void ClearSettings()
 {
     Object[] _allGameObjects = FindObjectsOfType <GameObject>();
     foreach (GameObject obj in _allGameObjects)
     {
         foreach (KeyValuePair <int, Color> pairs in _storedColors)
         {
             Tooltip _objTooltip = obj?.GetComponent <Tooltip>();
             if (_objTooltip != null)
             {
                 Renderer _objRenderer = _objTooltip?.GetComponent <Renderer>();
                 if (_objRenderer != null)
                 {
                     if (pairs.Key == _objRenderer.GetInstanceID())
                     {
                         _objRenderer.material.color = pairs.Value;
                     }
                 }
             }
         }
     }
     _storedColors.Clear();
 }
 private void Preset1()
 {
     if (_activeMode == _modes.preset1)
     {
         if (_objHit != null)
         {
             _objHit.material.color = _objInitColor;
             TooltipBox.SetActive(false);
             _objHit = null;
         }
         RaycastHit _rayHit;
         if (Physics.Raycast(new Vector3(_playerScript.transform.position.x, _playerScript.transform.position.y + _heightAdjust, _playerScript.transform.position.z), Camera.transform.forward, out _rayHit, _raycastLength))
         {
             Tooltip _objectHasTooltip = _rayHit.collider?.GetComponent <Tooltip>();
             if (_objectHasTooltip != null)
             {
                 Renderer _objRender = _objectHasTooltip?.GetComponent <Renderer>();
                 if (_objRender != null)
                 {
                     if (_objHit == null)
                     {
                         _objInitColor = _objRender.material.color;
                     }
                     _objRender.material.color = Color.yellow;
                     _objHit = _objRender;
                     TextMeshProUGUI _tooltipText = TooltipText?.GetComponent <TextMeshProUGUI>();
                     if (_tooltipText != null)
                     {
                         TooltipBox.SetActive(true);
                         _tooltipText.text = _objectHasTooltip._toolTipText;
                     }
                 }
             }
         }
     }
 }
 void OnEnable()
 {
     TooltipTransform = Tooltip.GetComponent <RectTransform>();
     RectTransform    = GetComponent <RectTransform>();
     Instance         = this;
 }