MenuController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Sirenix.OdinInspector;
  5. using KairoEngine.Core.GameActions;
  6. using KairoEngine.UI.InteractionHandler;
  7. namespace KairoEngine.UI
  8. {
  9. /// <summary>
  10. /// Set GameActions to be run when a UI Menu buttom has been clicked
  11. /// </summary>
  12. [HideMonoScript]
  13. public class MenuController : MonoBehaviour, IClickHandler
  14. {
  15. [InlineProperty, HideLabel] public GameActionContext context = new GameActionContext();
  16. [OnCollectionChanged("SetupActions"), PropertySpace(4,0), ListDrawerSettings(DraggableItems = false)]
  17. public List<MenuAction> menuActions = new List<MenuAction>();
  18. public void OnClick(string title)
  19. {
  20. for (int i = 0; i < menuActions.Count; i++)
  21. {
  22. if(menuActions[i].title == title) menuActions[i].Execute();
  23. }
  24. }
  25. private void SetupActions()
  26. {
  27. for (int i = 0; i < menuActions.Count; i++)
  28. {
  29. if(menuActions[i] != null)
  30. {
  31. if(menuActions[i].actionsController != null)
  32. {
  33. menuActions[i].actionsController.context = context;
  34. }
  35. }
  36. }
  37. }
  38. }
  39. }