ActionControl.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. namespace SRDebugger.UI.Controls.Data
  2. {
  3. using System;
  4. using SRF;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class ActionControl : OptionsControlBase
  8. {
  9. private SRF.Helpers.MethodReference _method;
  10. [RequiredField] public UnityEngine.UI.Button Button;
  11. [RequiredField] public Text Title;
  12. public SRF.Helpers.MethodReference Method
  13. {
  14. get { return _method; }
  15. }
  16. protected override void Start()
  17. {
  18. base.Start();
  19. Button.onClick.AddListener(ButtonOnClick);
  20. }
  21. private void ButtonOnClick()
  22. {
  23. if (_method == null)
  24. {
  25. Debug.LogWarning("[SRDebugger.Options] No method set for action control", this);
  26. return;
  27. }
  28. try
  29. {
  30. _method.Invoke(null);
  31. }
  32. catch (Exception e)
  33. {
  34. Debug.LogError("[SRDebugger] Exception thrown while executing action.");
  35. Debug.LogException(e);
  36. }
  37. }
  38. public void SetMethod(string methodName, SRF.Helpers.MethodReference method)
  39. {
  40. _method = method;
  41. Title.text = methodName;
  42. }
  43. }
  44. }