Ejemplo n.º 1
0
    public static void UnsubscribeFromEvent(EventDataCallback callback, Component component, EventType type)
    {
        CallbackComponentPair pair = new CallbackComponentPair(callback, component);

        if (componentEventsData.ContainsKey(type))
        {
            componentEventsData[type].Unsubscribe(pair);
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Subscribe to an event with a callback. This removes all previous subscriptions for this event.
    /// </summary>
    /// <param name="callback"></param>
    /// <param name="type"></param>
    public static void OverrideSubscription(EventDataCallback callback, Component component, EventType type)
    {
        CallbackComponentPair pair = new CallbackComponentPair(callback, component);

        ComponentEventsContainer cont = new ComponentEventsContainer();

        cont.AddPair(pair);
        componentEventsData.Add(type, cont);
    }
Ejemplo n.º 3
0
 public void Unsubscribe(CallbackComponentPair pair)
 {
     for (int i = 0; i < pairs.Count; i++)
     {
         if (pair.Equals(pairs[i]))
         {
             pairs.RemoveAt(i);
             i--;
             return;
         }
     }
 }
    public override bool Equals(object obj)
    {
        if (GetType() != obj.GetType())
        {
            return(false);
        }

        CallbackComponentPair other = (CallbackComponentPair)obj;

        bool type = CallbackWithData == other.CallbackWithData;
        bool comp = Component.Equals(other.Component);

        return(type && comp);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// Subscribe to an event with a callback from a component. The subscription is removed automatically when the component is destroyed.
    /// </summary>
    /// <param name="callback"></param>
    /// <param name="component"></param>
    /// <param name="type"></param>
    public static void SubscribeToEvent(EventDataCallback callback, Component component, EventType type)
    {
        CallbackComponentPair pair = new CallbackComponentPair(callback, component);

        if (!componentEventsData.ContainsKey(type))
        {
            ComponentEventsContainer cont = new ComponentEventsContainer();
            cont.AddPair(pair);
            componentEventsData.Add(type, cont);
        }
        else
        {
            componentEventsData[type].AddPair(pair);
        }
    }
Ejemplo n.º 6
0
    /// <summary>
    /// Calls callbacks if the component which subscribed to it isn't null. Automatically removes subscriptions for destroyed components/gameobjects.
    /// </summary>
    public void FireIfNotNull(CallbackData data)
    {
        for (int i = 0; i < pairs.Count; i++)
        {
            CallbackComponentPair pair = pairs[i];

            if (pair.Component == null)
            {
                pairs.RemoveAt(i);
                i--;
                continue;
            }

            pair.CallbackWithData(data);
        }
    }
Ejemplo n.º 7
0
 public void AddPair(CallbackComponentPair pair)
 {
     pairs.Add(pair);
 }