Esempio n. 1
0
        public EntityGameObjectLinker(World world)
        {
            this.world    = world;
            entityManager = world.EntityManager;

            workerSystem    = world.GetExistingSystem <WorkerSystem>();
            lifecycleSystem = world.GetExistingSystem <RequireLifecycleSystem>();

            viewCommandBuffer = new ViewCommandBuffer(entityManager, workerSystem.LogDispatcher);

            workerSystem = world.GetExistingSystem <WorkerSystem>();
            if (workerSystem == null)
            {
                throw new ArgumentException(
                          $"Can not create {nameof(EntityGameObjectLinker)}. {world.Name} does not contain a {nameof(workerSystem)}");
            }

            subscriptionSystem = world.GetExistingSystem <SubscriptionSystem>();

            if (subscriptionSystem == null)
            {
                throw new ArgumentException(
                          $"Can not create {nameof(EntityGameObjectLinker)}. {world.Name} does not contain a {nameof(SubscriptionSystem)}");
            }
        }
        public SubscriptionAggregate(SubscriptionSystem subscriptionSystem, EntityId entityId,
                                     params Type[] typesToSubscribeTo)
        {
            subscriptions = new ISubscription[typesToSubscribeTo.Length];

            for (int i = 0; i < typesToSubscribeTo.Length; ++i)
            {
                var subscription = subscriptionSystem.Subscribe(entityId, typesToSubscribeTo[i]);
                typesToSubscriptionIndexes.Add(typesToSubscribeTo[i], i);
                subscriptions[i] = subscription;

                subscription.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)
        {
            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));
        }