123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using Sirenix.OdinInspector;
- namespace KairoEngine.UI.InteractionHandler
- {
- [HideMonoScript]
- public class SelectedButton : MonoBehaviour
- {
- public Image image;
- public Button button;
-
- public bool selected = false;
- [SerializeField] private Sprite defaultSprite;
- [SerializeField] private Sprite selectedSprite;
- [SerializeField] private Sprite disabledSprite;
- [SerializeField] public bool isInteractable = true;
- private void Start()
- {
- if(defaultSprite == null) defaultSprite = image.sprite;
- }
- public void Select()
- {
- //if(selected) return;
- selected = true;
- if(defaultSprite == null) defaultSprite = image.sprite;
- //image.sprite = button.spriteState.selectedSprite;
- var btnStates = button.spriteState;
- btnStates.disabledSprite = selectedSprite;
- button.spriteState = btnStates;
- button.interactable = false;
-
- }
- public void Deselect()
- {
- //if(!selected) return;
- selected = false;
- //image.sprite = selectedSprite;
- var btnStates = button.spriteState;
- btnStates.disabledSprite = disabledSprite;
- button.spriteState = btnStates;
- button.interactable = isInteractable;
- }
- }
- }
|