예제 #1
0
        public static StaticEvent <T> .Delegate removeParticularSubscriber <T>(MonoBehaviour component)
        {
            SubscriberList list = (SubscriberList)component
                                  .GetType()
                                  .GetField(
                "subscriberList_",
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static
                )
                                  .GetValue(component);

            StaticEvent <T> .Delegate func = null;
            var index = 0;

            foreach (var subscriber in list)
            {
                if (subscriber is StaticEvent <T> .Subscriber)
                {
                    func = (StaticEvent <T> .Delegate)subscriber
                           .GetType()
                           .GetField(
                        "func_",
                        BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static
                        )
                           .GetValue(subscriber);
                    subscriber.Unsubscribe();
                    break;
                }
                index++;
            }
            if (func != null)
            {
                list.RemoveAt(index);
            }
            return(func);
        }
예제 #2
0
        public static StaticEvent <T> .Delegate removeParticularSubscriber <T>(MonoBehaviour component)
        {
            SubscriberList list = (SubscriberList)PrivateUtilities.getPrivateField(component, "subscriberList_");

            StaticEvent <T> .Delegate func = null;
            var index = 0;

            foreach (var subscriber in list)
            {
                if (subscriber is StaticEvent <T> .Subscriber)
                {
                    func = (StaticEvent <T> .Delegate)PrivateUtilities.getPrivateField(subscriber, "func_");
                    subscriber.Unsubscribe();
                    break;
                }
                index++;
            }
            if (func != null)
            {
                list.RemoveAt(index);
            }
            return(func);
        }