Exemple #1
0
        protected override void OnCreateManager(int capacity)
        {
            base.OnCreateManager(capacity);

            FindGameObjectComponentDispatchers();
            GenerateComponentGroups();

            var entityManager = World.GetOrCreateManager <EntityManager>();

            logger   = World.GetExistingManager <WorkerSystem>().LogDispatcher;
            injector = new RequiredFieldInjector(entityManager, logger);
        }
Exemple #2
0
        public MonoBehaviourActivationManager(GameObject gameObject, RequiredFieldInjector injector,
                                              InjectableStore store, ILogDispatcher logger)
        {
            this.logger   = logger;
            this.store    = store;
            this.injector = injector;

            var spatialComponent = gameObject.GetComponent <SpatialOSComponent>();

            entity    = spatialComponent.Entity;
            spatialId = spatialComponent.SpatialEntityId;

            foreach (var behaviour in gameObject.GetComponents <MonoBehaviour>())
            {
                var behaviourType = behaviour.GetType();
                if (injector.HasRequiredFields(behaviourType))
                {
                    var componentReadRequirements = injector.GetComponentPresenceRequirements(behaviourType);
                    var componentAuthRequirements = injector.GetComponentAuthorityRequirements(behaviourType);
                    var readRequirementCount      = componentReadRequirements.Count;
                    var authRequirementCount      = componentAuthRequirements.Count;

                    if (readRequirementCount == 0 && authRequirementCount == 0)
                    {
                        behavioursToEnable.Add(behaviour);
                    }

                    if (readRequirementCount > 0)
                    {
                        AddBehaviourForComponentIds(behaviour, componentReadRequirements, behavioursRequiringComponentsPresent);
                    }

                    if (authRequirementCount > 0)
                    {
                        AddBehaviourForComponentIds(behaviour, componentAuthRequirements, behavioursRequiringComponentsWithAuth);
                    }

                    numUnsatisfiedRequirements[behaviour] = componentReadRequirements.Count + componentAuthRequirements.Count;

                    behaviour.enabled = false;
                }
            }
        }