81 lines
1.6 KiB
C#
81 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Events;
|
|
|
|
public class SkillHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
|
|
{
|
|
public GameObject image;
|
|
|
|
private Animator anim;
|
|
|
|
public bool isSelected;
|
|
|
|
private AudioSource audioSource;
|
|
|
|
public AudioClip[] audioclips;
|
|
|
|
[Header("Script already has sound events, dont add more")]
|
|
[Space(10f)]
|
|
public UnityEvent OnUISkillHover;
|
|
|
|
public static event Action OnUIHoverSkillGlobal;
|
|
|
|
public static event Action OnUIClickSkillGlobal;
|
|
|
|
private void Start()
|
|
{
|
|
audioSource = GetComponent<AudioSource>();
|
|
anim = GetComponent<Animator>();
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
image.gameObject.SetActive(value: true);
|
|
anim.SetBool("hovered", value: true);
|
|
playHoverSound();
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (!isSelected)
|
|
{
|
|
image.gameObject.SetActive(value: false);
|
|
}
|
|
anim.SetBool("hovered", value: false);
|
|
}
|
|
|
|
private void playHoverSound()
|
|
{
|
|
audioSource.clip = audioclips[0];
|
|
SkillHover.OnUIHoverSkillGlobal?.Invoke();
|
|
}
|
|
|
|
public void click()
|
|
{
|
|
UnselectOtherSlots();
|
|
isSelected = true;
|
|
audioSource.clip = audioclips[1];
|
|
SkillHover.OnUIClickSkillGlobal?.Invoke();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
isSelected = false;
|
|
image.gameObject.SetActive(value: false);
|
|
}
|
|
|
|
private void UnselectOtherSlots()
|
|
{
|
|
SkillHover[] array = UnityEngine.Object.FindObjectsOfType<SkillHover>();
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
if (array[i] != this)
|
|
{
|
|
array[i].isSelected = false;
|
|
array[i].image.gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|
|
}
|