| | 1 | | using System; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | public interface ITooltipView |
| | 7 | | { |
| | 8 | | float alphaTranstionSpeed { get; } |
| | 9 | | float currentAlpha { get; } |
| | 10 | |
|
| | 11 | | event Action OnHideTooltip; |
| | 12 | | void SetText(string text); |
| | 13 | | void SetTooltipPosition(Vector3 pos); |
| | 14 | | void SetTooltipAlpha(float alphaValue); |
| | 15 | | } |
| | 16 | |
|
| | 17 | | public class TooltipView : MonoBehaviour, ITooltipView |
| | 18 | | { |
| 0 | 19 | | public float alphaTranstionSpeed => alphaSpeed; |
| 0 | 20 | | public float currentAlpha => tooltipCG.alpha; |
| | 21 | |
|
| | 22 | | public event Action OnHideTooltip; |
| | 23 | |
|
| 44 | 24 | | [SerializeField] internal float alphaSpeed = 3f; |
| | 25 | | [SerializeField] internal RectTransform tooltipRT; |
| | 26 | | [SerializeField] internal CanvasGroup tooltipCG; |
| | 27 | | [SerializeField] internal TextMeshProUGUI tooltipTxt; |
| | 28 | |
|
| | 29 | | private const string VIEW_PATH = "Common/ToolTipView"; |
| | 30 | |
|
| | 31 | | internal static TooltipView Create() |
| | 32 | | { |
| 3 | 33 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<TooltipView>(); |
| 3 | 34 | | view.gameObject.name = "_TooltipView"; |
| | 35 | |
|
| 3 | 36 | | return view; |
| | 37 | | } |
| | 38 | |
|
| 2 | 39 | | public void SetTooltipPosition(Vector3 pos) { tooltipRT.position = pos; } |
| | 40 | |
|
| 2 | 41 | | public void SetText(string text) { tooltipTxt.text = text; } |
| | 42 | |
|
| 2 | 43 | | public void SetTooltipAlpha(float alphaValue) { tooltipCG.alpha = alphaValue; } |
| | 44 | | } |