54 lines
1.4 KiB
C#
54 lines
1.4 KiB
C#
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.EventSystems;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class SliderItem : MonoBehaviour, IPointerDownHandler
|
|||
|
{
|
|||
|
public event Action<SliderItem> OnClick;
|
|||
|
public bool IsActive => _activeImage.gameObject.activeInHierarchy;
|
|||
|
public Sprite ActiveSprite => _activeImage.sprite;
|
|||
|
|
|||
|
private Image _activeImage;
|
|||
|
private Image _inactiveImage;
|
|||
|
|
|||
|
private Button _button;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
_button = GetComponent<Button>();
|
|||
|
|
|||
|
_activeImage = transform.Find("ActiveItemImg").GetComponent<Image>();
|
|||
|
_inactiveImage = transform.Find("InactiveItemImg").GetComponent<Image>();
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
_button.onClick.AddListener(OnButtonClick);
|
|||
|
SetActiveState(false);
|
|||
|
}
|
|||
|
|
|||
|
public void SetSpritesForStates(Sprite activeSprite, Sprite inactiveSprite)
|
|||
|
{
|
|||
|
_activeImage.sprite = activeSprite;
|
|||
|
_inactiveImage.sprite = inactiveSprite;
|
|||
|
}
|
|||
|
|
|||
|
private void OnButtonClick()
|
|||
|
{
|
|||
|
// OnClick?.Invoke(this);
|
|||
|
}
|
|||
|
|
|||
|
public void SetActiveState(bool isActive)
|
|||
|
{
|
|||
|
_activeImage.gameObject.SetActive(isActive);
|
|||
|
_inactiveImage.gameObject.SetActive(!isActive);
|
|||
|
}
|
|||
|
|
|||
|
public void OnPointerDown(PointerEventData eventData)
|
|||
|
{
|
|||
|
OnClick?.Invoke(this);
|
|||
|
}
|
|||
|
}
|