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 tooltipList = new Dictionary(); 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 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; } } }