playMaker

Author Topic: Event setup for button listener and warnings  (Read 1577 times)

Amimoller

  • Playmaker Newbie
  • *
  • Posts: 9
Event setup for button listener and warnings
« on: August 26, 2014, 06:33:12 AM »
Hi,
We have an action that listens to a NGUI button and triggers the event when it is pressed. It works as expected but the action will show a warning because the event is not present in the state where the action is run. (We just run this action once when the FSM is first initialized)
I can get it to go away if i put the eventtarget above the event but then the "self" option will not show non-global events which is not ideal.
Is there any way to fix or suppress the warning?
I guess another way would be to register and unregister on enter/exit in the action and put the action everywhere you want to listen for the event. That just seems needlessly ineffecient.

Here is the action:

Code: [Select]
    public class ButtonListenerActionV2 : FsmStateAction
    {
        [RequiredField]
        public FsmEvent OnClick;
        public FsmEventTarget Target;

        [RequiredField]
        [CheckForComponent(typeof(UIButton))]
        public FsmGameObject Button;

        public override void Reset()
        {
            OnClick = null;
            Button = null;
            Target = null;
        }

        public override void OnEnter()
        {
            if (Button.Value != null)
            {
                if(Target != null)
                {
                    var button = Button.Value.GetComponent<UIButton>();

                    EventDelegate.Add(button.onClick, () => Fsm.Event(Target, OnClick));
                }
            }
            Finish();
        }
    }