113 lines
2.1 KiB
C#
113 lines
2.1 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
|
|
public class HeaderOptionsBarHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler, IPointerClickHandler
|
|
{
|
|
public bool isMsg;
|
|
|
|
public Sprite hoverSprite;
|
|
|
|
public Sprite hoverMsgSprite;
|
|
|
|
public GameObject msgButtonPanel;
|
|
|
|
public Text msgButtonText;
|
|
|
|
private Image currImage;
|
|
|
|
private Sprite startSprite;
|
|
|
|
private AudioSource audioSource;
|
|
|
|
public bool isSelected;
|
|
|
|
private bool isHover;
|
|
|
|
[Header("Script already has sound events, dont add more")]
|
|
[Space(10f)]
|
|
public UnityEvent OnUIHeaderOptionHover;
|
|
|
|
public UnityEvent OnUIHeaderOptionClick;
|
|
|
|
public static event Action OnUIHeaderOptionHoverGlobal;
|
|
|
|
public static event Action OnUIHeaderOptionClickGlobal;
|
|
|
|
private void Start()
|
|
{
|
|
audioSource = GetComponent<AudioSource>();
|
|
currImage = GetComponent<Image>();
|
|
startSprite = currImage.sprite;
|
|
if (isMsg)
|
|
{
|
|
SetMsgButton(visable: true, "Nowy sprzet");
|
|
}
|
|
else
|
|
{
|
|
SetMsgButton();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (isSelected)
|
|
{
|
|
if (currImage.sprite != hoverSprite)
|
|
{
|
|
currImage.sprite = hoverSprite;
|
|
}
|
|
}
|
|
else if (currImage.sprite != startSprite && !isHover)
|
|
{
|
|
currImage.sprite = startSprite;
|
|
}
|
|
}
|
|
|
|
public void SetMsgButton(bool visable = false, string msgText = "")
|
|
{
|
|
if (visable)
|
|
{
|
|
isMsg = true;
|
|
msgButtonText.text = msgText;
|
|
msgButtonPanel.SetActive(value: true);
|
|
}
|
|
else
|
|
{
|
|
isMsg = false;
|
|
msgButtonText.text = "";
|
|
msgButtonPanel.SetActive(value: false);
|
|
}
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData pointerEventData)
|
|
{
|
|
isHover = true;
|
|
currImage.sprite = hoverSprite;
|
|
playHoverSound();
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData pointerEventData)
|
|
{
|
|
isHover = false;
|
|
if (!isSelected)
|
|
{
|
|
currImage.sprite = startSprite;
|
|
}
|
|
}
|
|
|
|
private void playHoverSound()
|
|
{
|
|
OnUIHeaderOptionHover?.Invoke();
|
|
HeaderOptionsBarHover.OnUIHeaderOptionHoverGlobal?.Invoke();
|
|
}
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
OnUIHeaderOptionClick?.Invoke();
|
|
HeaderOptionsBarHover.OnUIHeaderOptionClickGlobal?.Invoke();
|
|
}
|
|
}
|