arthurdiniz0_outer-math/OuterMath Unity Project/Assets/PlayMaker/Actions/UI/EventSystem/EventTriggerActionBase.cs
// (c) Copyright HutongGames, LLC 2010-2021. All rights reserved.

using UnityEngine.EventSystems;

#if UNITY_5_6_OR_NEWER   
namespace HutongGames.PlayMaker.Actions
{
    // Base action for EventTrigger actions
    // Handles boilerplate setup etc.
    public abstract class EventTriggerActionBase : ComponentAction<EventTrigger>
    {
        [DisplayOrder(0)]
        [RequiredField]
        [Tooltip("The GameObject with the UI component.")]
        public FsmOwnerDefault gameObject;

        [DisplayOrder(1)]
        [Tooltip("Where to send the event.")]
        public FsmEventTarget eventTarget;

        protected EventTrigger trigger;
        protected EventTrigger.Entry entry;

        public override void Reset()
        {
            gameObject = null;
            eventTarget = null;
        }

        protected void Init(EventTriggerType eventTriggerType, UnityEngine.Events.UnityAction<BaseEventData> call)
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (UpdateCacheAddComponent(go))
            {
                trigger = cachedComponent;

                if (entry == null)
                {
                    entry = new EventTrigger.Entry ();
                }

                entry.eventID = eventTriggerType;
                entry.callback.AddListener(call);

                trigger.triggers.Add(entry);
            }
        }
		       
        public override void OnExit()
        {
            if (entry != null && entry.callback != null)
            {
                entry.callback.RemoveAllListeners ();
            }

            if (trigger != null && trigger.triggers != null)
            {
                trigger.triggers.Remove(entry);
            }
        }
    }
}

#endif