Files
2026-03-04 10:03:45 +08:00

90 lines
1.9 KiB
C#

using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class CosmeticHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
{
public GameObject image;
private AudioSource audioSource;
private Animator animator;
public AudioClip[] audioclips;
[SerializeField]
private GameObject[] ItemButtons;
private CharCreationUIManager charCreation;
private CosmeticItem cosmeticItem;
private void Start()
{
charCreation = Object.FindObjectOfType<CharCreationUIManager>();
cosmeticItem = GetComponentInParent<CosmeticItem>();
audioSource = GetComponent<AudioSource>();
animator = GetComponent<Animator>();
}
private void Update()
{
}
private void playHoverSound()
{
audioSource.clip = audioclips[0];
audioSource.Play();
}
public void click()
{
audioSource.clip = audioclips[1];
audioSource.Play();
}
public void BuyButton()
{
charCreation.CreateCosmeticPopUp("Zakupiæ Przedmiot?", "Czy na pewno chcesz zakupiæ ten przedmiot?", delegate
{
Debug.Log("Zakupiono Przedmiot");
});
}
private void CantBuy()
{
animator.SetTrigger("cantbuy");
}
public void OnPointerEnter(PointerEventData eventData)
{
if (Singleton<SaveDataManager>.Instance.GetCurrentPlayerData().PlayerLevel >= cosmeticItem.Itemlevel)
{
image.gameObject.SetActive(value: true);
for (int i = 0; i < ItemButtons.Length; i++)
{
ItemButtons[i].SetActive(value: false);
}
playHoverSound();
ItemButtons[0].SetActive(value: true);
if (charCreation.RenderPopUp != null)
{
ItemButtons[0].GetComponent<Button>().interactable = false;
}
else
{
ItemButtons[0].GetComponent<Button>().interactable = true;
}
}
}
public void OnPointerExit(PointerEventData eventData)
{
for (int i = 0; i < ItemButtons.Length; i++)
{
ItemButtons[i].SetActive(value: false);
}
image.gameObject.SetActive(value: false);
}
}