Hi,
Here we go:
using UnityEngine;
using System;
namespace HutongGames.PlayMaker.Actions
{
public class TestStaticCallback : FsmStateAction
{
/// <summary>
/// The result of the TestStaticCallbackClass.Test() callback
/// </summary>
[UIHint(UIHint.Variable)]
public FsmBool Result;
public override void OnEnter() // when the action starts.
{
TestStaticCallbackClass.Test(HandleAction); // that's the call to the static
}
/// <summary>
/// Handles the action callback from TestStaticCallbackClass.Test()
/// </summary>
/// <param name="obj">If set to <c>true</c> object.</param>
void HandleAction(bool obj)
{
Result.Value = obj; // we set the value of the callback into the Fsm bool variable.
Finish(); // We tell PlayMaker that the action is done ( when all actions are done in a state, FINISH transition is call)
}
}
/// <summary>
/// This is the class that implements a static method with an Action Callback, right now it's synchronous,
/// But it could fire later on after several frames or seconds ( could be calling a web server for example)
/// </summary>
public static class TestStaticCallbackClass
{
public static void Test(Action<bool> callback)
{
callback.Invoke(true);
}
}
}
Let me know if you have questions.
Bye,
Jean