Exemplo n.º 1
0
        public void CreateActivationManagerAndReaderWriterStore(Entity entity)
        {
            if (entityToActivationManager.ContainsKey(entity))
            {
                throw new ActivationManagerAlreadyExistsException($"MonoBehaviourActivationManager already exists for entity {entity.Index}.");
            }

            var gameObject = EntityManager.GetComponentObject <GameObjectReference>(entity).GameObject;
            var store      = new InjectableStore();

            entityToReaderWriterStore.Add(entity, store);
            var manager = new MonoBehaviourActivationManager(gameObject, injector, store, logger);

            entityToActivationManager.Add(entity, manager);
        }
Exemplo n.º 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;
                }
            }
        }