Exemple #1
0
 public void Unsubscribe <T>(Events.EventDelegate <T> del) where T : GameEvent
 {
     if (Delegates.ContainsKey(del))
     {
         var info = Delegates[del];
         Events.Instance.RemoveListener(info.Type, info.Delegate);
         Delegates.Remove(del);
     }
 }
Exemple #2
0
        // ---------------------------------------------------------------------------------------------------------
        /// <summary>
        ///  removes a function that listens for the given event when the event is sent to this object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="del"></param>
        /// <param name="o"></param>
        public static void RemoveObjectListener <T>(Events.EventDelegate <T> del, object o) where T : GameEvent
        // ---------------------------------------------------------------------------------------------------------
        {
            DelegateSet delegateSet = Internal.GetDelegates(o);

            Dbg.Assert(delegateSet != null);   // odd otherwise
            RemoveListener(del, delegateSet);

            if (delegateSet.Lookup.Count == 0)
            {
                Internal.RemoveDelegates(o);
            }
        }
Exemple #3
0
    public void Subscribe <T>(Events.EventDelegate <T> del) where T : GameEvent
    {
        if (!Delegates.ContainsKey(del))
        {
            var info = new EventInfo
            {
                Type     = typeof(T),
                Delegate = (e) => del((T)e)
            };

            Delegates.Add(del, info);
            Events.Instance.AddListener(info.Type, info.Delegate);
        }
    }
Exemple #4
0
        // ***************** OBJECT FUNCTIONS ***************************************************************************

        // ---------------------------------------------------------------------------------------------------------
        /// <summary>
        ///  adds a function that listens for the given event when the event is sent to this object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="del"></param>
        /// <param name="o"></param>
        public static void AddObjectListener <T>(Events.EventDelegate <T> del, object o) where T : GameEvent
        // ---------------------------------------------------------------------------------------------------------
        {
            AddListener <T>(del, Internal.GetOrCreateDelegates(o));
        }
Exemple #5
0
        // ---------------------------------------------------------------------------------------------------------
        /// <summary>
        /// removes a function that listens for the given event when the event is sent globally
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="del"></param>
        // ---------------------------------------------------------------------------------------------------------

        public static void RemoveGlobalListener <T>(Events.EventDelegate <T> del) where T : GameEvent
        {
            RemoveListener(del, Internal._globalDelegates);
        }
Exemple #6
0
 protected void Unsubscribe <T>(Events.EventDelegate <T> del) where T : GameEvent
 {
     UnityEventOwner.Unsubscribe(del);
 }