This is not an action for FSM, it is a MonoBehaviour component used with UGUI button componentsWhen calling an FSM event from outside the FSM graph, you can send a system event or user custom event from the Button without specifying a string
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using HutongGames.PlayMaker;
using System.Collections.Generic;
[RequireComponent(typeof(Button))]
public class ButtonFsmEvents : MonoBehaviour
{
public FsmEvent onClick = FsmEvent.Finished;
private void Awake()
{
GetComponent<Button>().onClick.AddListener(() =>
{
PlayMakerFSM.BroadcastEvent(onClick);
});
}
}
#if UNITY_EDITOR
[CanEditMultipleObjects, CustomEditor(typeof(ButtonFsmEvents))]
public class ButtonFsmEventsEditor : Editor
{
ButtonFsmEvents _buttonFsmEvents;
void OnEnable()
{
_buttonFsmEvents = target as ButtonFsmEvents;
}
public override void OnInspectorGUI()
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.PrefixLabel("OnClick");
if (GUILayout.Button(_buttonFsmEvents.onClick.Name))
{
CreateContextMenu();
}
}
}
void CreateContextMenu()
{
GenericMenu menu = new GenericMenu();
var systemEvents = new List<FsmEvent>();
var customEvents = new List<FsmEvent>();
foreach (var item in FsmEvent.EventList)
{
if (item.IsSystemEvent)
{
// Ignore Events
if (item.IsCollision2DEvent || item.IsTrigger2DEvent || item.IsLegacyNetworkEvent)
{
continue;
}
systemEvents.Add(item);
}
else
{
customEvents.Add(item);
}
}
foreach (var item in customEvents)
{
menu.AddItem(new GUIContent("Custom/" + item.Name), false, Callback, item);
}
menu.AddSeparator("");
foreach (var item in systemEvents)
{
menu.AddItem(new GUIContent("System/" + item.Name), false, Callback, item);
}
menu.ShowAsContext();
}
void Callback(object fsmEvent)
{
_buttonFsmEvents.onClick = (FsmEvent)fsmEvent;
}
}