using UnityEngine;
using UnityEngine.Events;
namespace MacGruber
{
public class TriggerExample : MVRScript
{
JSONStorableAction myAction;
public override void Init()
{
// These are the same fields as when you setup a trigger in VaM's UI.
string atomName = "Person#2";
string receiverName = "plugin#1_MacGruber.Relay";
string receiverTarget = "Trigger";
// For best performance we cache the action once for later use.
myAction = GetAtomById(atomName)?.GetStorableByID(receiverName)?.GetAction(receiverTarget);
// Just setting up some button so we can show how to trigger the action.
SetupButton("Baduum!", OnButtonPressed, false);
}
private void OnButtonPressed()
{
// Note that myAction may end up being null, when the target did not exist at the moment we cached it or was deleted later.
if (myAction != null)
myAction.actionCallback();
}
public void SetupButton(string label, UnityAction callback, bool rightSide)
{
UIDynamicButton button = CreateButton(label, rightSide);
button.button.onClick.AddListener(callback);
}
}
}