123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.UI;
- using Sirenix.OdinInspector;
- namespace KairoEngine.UI.Tooltips
- {
- public class TooltipSystem : SerializedMonoBehaviour
- {
- public static TooltipSystem instance;
- [ReadOnly] public Tooltip tooltip;
-
- public Dictionary<string, Tooltip> tooltipList = new Dictionary<string, Tooltip>();
- public float delayTime = 0.8f;
- public void Awake()
- {
- if(instance == null) instance = this;
- else Destroy(this.gameObject);
- if(tooltip == null) Debug.LogError("No tooltip is assigned in TooltipSystem", this.gameObject);
- else tooltip.gameObject.SetActive(false);
- }
- public static void Show(string content, string header = "", string tooltipType = "")
- {
- if(!HasInstance()) return;
- foreach(KeyValuePair<string, Tooltip> keyValue in instance.tooltipList)
- {
- string key = keyValue.Key;
- if(key == tooltipType)
- {
- instance.tooltip = keyValue.Value;
- }
- }
- if(instance.tooltip != null)
- {
- instance.tooltip.SetText(content, header);
- instance.tooltip.gameObject.SetActive(true);
- }
- else Debug.LogError($"The Tooltip type named \'{tooltipType}\' could not be found.", instance.gameObject);
- }
- public static void Hide()
- {
- if(!HasInstance()) return;
- if(instance.tooltip == null) return;
- instance.tooltip.gameObject.SetActive(false);
- instance.tooltip = null;
- }
- public static bool HasInstance()
- {
- if(instance == null)
- {
- Debug.LogWarning("There is no active TooltipSystem");
- return false;
- }
- else return true;
- }
- public static float GetDelay()
- {
- if(!HasInstance()) return 0.5f;
- else return instance.delayTime;
- }
- }
- }
|