You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRDebugger/Scripts/UI/Controls/Data/ActionControl.cs

53 lines
1.3 KiB
C#

1 month ago
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class ActionControl : OptionsControlBase
{
private SRF.Helpers.MethodReference _method;
[RequiredField] public UnityEngine.UI.Button Button;
[RequiredField] public Text Title;
public SRF.Helpers.MethodReference Method
{
get { return _method; }
}
protected override void Start()
{
base.Start();
Button.onClick.AddListener(ButtonOnClick);
}
private void ButtonOnClick()
{
if (_method == null)
{
Debug.LogWarning("[SRDebugger.Options] No method set for action control", this);
return;
}
try
{
_method.Invoke(null);
}
catch (Exception e)
{
Debug.LogError("[SRDebugger] Exception thrown while executing action.");
Debug.LogException(e);
}
}
public void SetMethod(string methodName, SRF.Helpers.MethodReference method)
{
_method = method;
Title.text = methodName;
}
}
}