SelectCommand.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. public class SelectCommand : MonoBehaviour
  8. {
  9. public UnityEvent OnClickEvent { get; set; } = new UnityEvent();
  10. [Header("Button List")]
  11. public List<Button> Buttons = new List<Button>();
  12. public void OpenSelectCommandButton(string _text, UnityAction OnClickAction, int ButtonIndex)
  13. {
  14. this.gameObject.SetActive(true);
  15. OnClickEvent.RemoveAllListeners();
  16. OnClickEvent.AddListener(OnClickAction);
  17. OnClickEvent.AddListener(CloseSelectCommandButton);
  18. for(int i=0;i<Buttons.Count;i++)
  19. {
  20. if(i == ButtonIndex)
  21. {
  22. Buttons[i].gameObject.SetActive(true);
  23. Buttons[i].transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = _text;
  24. }
  25. else
  26. {
  27. Buttons[i].gameObject.SetActive(false);
  28. }
  29. }
  30. }
  31. public void CloseSelectCommandButton()
  32. {
  33. this.gameObject.SetActive(false);
  34. }
  35. public void OnClick()
  36. {
  37. GManager.instance.PlayDecisionSE();
  38. OnClickEvent?.Invoke();
  39. }
  40. }