ActionControl.cs 1.1 KB

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