Пример #1
0
                public static Handler Rent(SubscriptionAggregate aggregate)
                {
                    var handler = HandlerPool.Count == 0
                        ? new Handler()
                        : HandlerPool.Pop();

                    handler.aggregate = aggregate;
                    return(handler);
                }
        // todo should either special case monobehaviours or not use callbacks
        // for non monobehaviours we could use functors
        public RequiredSubscriptionsInjector(object target, EntityId entityId, SubscriptionSystem subscriptionSystem,
                                             Action onEnable = null, Action onDisable = null)
        {
            info = RequiredSubscriptionsDatabase.GetOrCreateRequiredSubscriptionsInfo(target.GetType());
            if (info.RequiredTypes.Length == 0)
            {
                return;
            }

            this.target    = target;
            this.onEnable  = onEnable;
            this.onDisable = onDisable;

            subscriptions = new SubscriptionAggregate(subscriptionSystem, entityId, info.RequiredTypes);
            subscriptions.SetAvailabilityHandler(Handler.Pool.Rent(this));
        }
        // todo should either special case monobehaviours or not use callbacks
        // for non monobehaviours we could use functors
        public RequiredSubscriptionsInjector(object target, EntityId entityId, SubscriptionSystem subscriptionSystem,
                                             Action onEnable = null, Action onDisable = null)
        {
            this.target    = target;
            this.onEnable  = onEnable;
            this.onDisable = onDisable;

            info = RequiredSubscriptionsDatabase.GetOrCreateRequiredSubscriptionsInfo(target.GetType());

            if (info == null || info.RequiredTypes.Length == 0)
            {
                onEnable?.Invoke();
                return;
            }

            subscriptions = subscriptionSystem.Subscribe(entityId, info.RequiredTypes);
            subscriptions.SetAvailabilityHandler(Handler.Pool.Rent(this));
        }