playMaker

Author Topic: Setting fsmReceiver on runtime? [SOLVED]  (Read 1437 times)

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Setting fsmReceiver on runtime? [SOLVED]
« 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.



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); });

        }
    }
}
« Last Edit: March 15, 2018, 05:27:22 AM by krmko »
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Setting fsmReceiver on runtime?
« Reply #1 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
 

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Setting fsmReceiver on runtime?
« Reply #2 on: March 14, 2018, 08:14:32 AM »
Great, thanks!
Available for Playmaker work