mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 09:57:38 +02:00
Better tooltip
This commit is contained in:
50
Assets/Scripts/Deprecated/OldTooltip.cs
Normal file
50
Assets/Scripts/Deprecated/OldTooltip.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
using RhythmHeavenMania.Common;
|
||||
|
||||
namespace RhythmHeavenMania.Deprecated
|
||||
{
|
||||
public class Tooltip : MonoBehaviour
|
||||
{
|
||||
public static Tooltip instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void OnEnter(string tooltipText)
|
||||
{
|
||||
this.GetComponent<Image>().enabled = true;
|
||||
this.transform.GetChild(0).GetComponent<TMP_Text>().text = tooltipText;
|
||||
this.transform.GetChild(0).gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
{
|
||||
this.GetComponent<Image>().enabled = false;
|
||||
this.transform.GetChild(0).gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void AddTooltip(GameObject g, string tooltipText)
|
||||
{
|
||||
EventTrigger et = g.AddComponent<EventTrigger>();
|
||||
|
||||
EventTrigger.Entry pointerEnter = new EventTrigger.Entry();
|
||||
pointerEnter.eventID = EventTriggerType.PointerEnter;
|
||||
pointerEnter.callback.AddListener((data) => { OnEnter(tooltipText); });
|
||||
|
||||
EventTrigger.Entry pointerExit = new EventTrigger.Entry();
|
||||
pointerExit.eventID = EventTriggerType.PointerExit;
|
||||
pointerExit.callback.AddListener((data) => { OnExit(); });
|
||||
|
||||
et.triggers.Add(pointerEnter);
|
||||
et.triggers.Add(pointerExit);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user