Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Fat Pug Studio on March 13, 2018, 03:16:48 AM

Title: Setting fsmReceiver on runtime? [SOLVED]
Post by: Fat Pug Studio on March 13, 2018, 03:16:48 AM
Hi guys,

i'm using set of actions for Simple Waypoint System, but one of the actions is made quite wrong. It's Add Event At Waypoint and instead referencing the object and FSM name, it uses fsmReceiver which can be only set in editor.

(https://s10.postimg.org/4311wlweh/image.png)

Any idea how could i set this on runtime or change the action so i can add event to a referenced object and FSM, not this crap. I tried fiddling with send event action, but it's too advanced for me.

Here's the action itself

Code: [Select]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using SWS;

//implements a PlayMaker FSM method call via event insert
namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory("Simple Waypoint System")]
    [Tooltip("Adds an event to a walker object for calling your own FSM state at waypoints.")]
    public class SWS_AddEventAtWaypoint : FsmStateAction
    {
        [RequiredField]
        [Tooltip("Walker object")]
        public FsmOwnerDefault walkerObject;

        [UIHint(UIHint.FsmInt)]
        [Tooltip("Waypoint index")]
        public FsmInt wpIndex;

        [RequiredField]
        [UIHint(UIHint.FsmGameObject)]
        [Tooltip("Receiver with the FSM event")]
        public PlayMakerFSM fsmReceiver;

        [RequiredField]
        [UIHint(UIHint.FsmString)]
        [Tooltip("Receiver FSM event to call")]
        public FsmString fsmEvent;
       

        public override void Reset()
        {
            walkerObject = null;
            wpIndex = null;
            fsmReceiver = null;
            fsmEvent = null;

        }


        public override void OnEnter()
        {
            Execute();

            Finish();
        }


        void Execute()
        {
            var go = Fsm.GetOwnerDefaultTarget(walkerObject);
            if (go == null) return;

            List<UnityEvent> events = null;

            splineMove spline = go.GetComponentInChildren<splineMove>();
            if (spline)
                events = spline.events;
            else
            {
                navMove nav = go.GetComponentInChildren<navMove>();
                if (nav)
                    events = nav.events;
            }

            UnityEvent myEvent = events[wpIndex.Value];
            myEvent.AddListener(delegate { fsmReceiver.SendEvent(fsmEvent.Value); });

        }
    }
}
Title: Re: Setting fsmReceiver on runtime?
Post by: jeanfabre on March 14, 2018, 02:59:34 AM
Hi,

 You can create an FsmObject of type PlayMakerFsm, and then you could send event and pass that fsm using SetEventdata and getEventInfo for this.

 Bye,

 Jean
 
Title: Re: Setting fsmReceiver on runtime?
Post by: Fat Pug Studio on March 14, 2018, 08:14:32 AM
Great, thanks!