private Systems CreateSystems(Pool pool)
        {
#if (UNITY_EDITOR)
            return new DebugSystems()
#else
        return new Systems()
#endif
                .Add(pool.CreateSystem<TickingSystem>())
                .Add(pool.CreateSystem<PositionUpdatingSystem>())
                .Add(pool.CreateSystem<RenderForceSystem>())
                .Add(pool.CreateSystem<BulletCollisionSystem>())
                .Add(pool.CreateSystem<AddViewSystem>())
                .Add(pool.CreateSystem<LevelStartingSystem>())
                .Add(pool.CreateSystem<SpaceshipControlsSystem>())
                .Add(pool.CreateSystem<AddRigidbodySystem>())
                .Add(pool.CreateSystem<AgingSystem>())
                .Add(pool.CreateSystem<MaxAgeSystem>())
                .Add(pool.CreateSystem<AsteroidSplittingSystem>())
                .Add(pool.CreateSystem<RenderRotationSystem>())
                .Add(pool.CreateSystem<GunFiringSystem>())
                .Add(pool.CreateSystem<GunCooldownSystem>())
                .Add(pool.CreateSystem<LevelEndingSystem>())
                .Add(pool.CreateSystem<SpaceshipRespawningSystem>())
                .Add(pool.CreateSystem<SpaceshipCollisionSystem>())
                .Add(pool.CreateSystem<InputDestructionSystem>())
                .Add(pool.CreateSystem<BoundsWrappingSystem>())
                .Add(pool.CreateSystem<RenderPositionSystem>())
                .Add(pool.CreateSystem<RemoveViewSystem>())
                .Add(pool.CreateSystem<DestroyingSystem>());
        }
 public void SetPool(Pool pool)
 {
     _pool = pool;
     _asteroids = pool.GetGroup(Matcher.Asteroid);
     _levels = pool.GetGroup(Matcher.Level);
     _players = pool.GetGroup(Matcher.Player);
 }
Esempio n. 3
0
 public void Init(Pool pool, Entity entity)
 {
     _pool = pool;
     _entity = entity;
     _entity.OnEntityReleased += onEntityReleased;
     Update();
 }
Esempio n. 4
0
 static void animatingComponent(Pool pool)
 {
     var e = pool.animatingEntity;
     var isAnimating = pool.isAnimating;
     pool.isAnimating = true;
     pool.isAnimating = false;
 }
Esempio n. 5
0
        ReactiveSystem(Pool pool, IReactiveExecuteSystem subSystem, TriggerOnEvent[] triggers)
        {
            _subsystem = subSystem;
            var ensureComponents = subSystem as IEnsureComponents;
            if (ensureComponents != null) {
                _ensureComponents = ensureComponents.ensureComponents;
            }
            var excludeComponents = subSystem as IExcludeComponents;
            if (excludeComponents != null) {
                _excludeComponents = excludeComponents.excludeComponents;
            }

            _clearAfterExecute = (subSystem as IClearReactiveSystem) != null;

            var triggersLength = triggers.Length;
            var groups = new Group[triggersLength];
            var eventTypes = new GroupEventType[triggersLength];
            for (int i = 0; i < triggersLength; i++) {
                var trigger = triggers[i];
                groups[i] = pool.GetGroup(trigger.trigger);
                eventTypes[i] = trigger.eventType;
            }
            _observer = new GroupObserver(groups, eventTypes);
            _buffer = new List<Entity>();
        }
 static void moveSystem(Pool pool) {
     var entities = pool.GetEntities(Matcher.AllOf(Matcher.Move, Matcher.Position));
     foreach (var entity in entities) {
         var move = entity.move;
         var pos = entity.position;
         entity.ReplacePosition(pos.x, pos.y + move.speed);
     }
 }
 public void SetPool(Pool pool)
 {
     _pool = pool;
     _pool.GetGroup(Matcher.SpaceshipDeathroes).OnEntityRemoved += OnDeaththroesRemoved;
     _waiting = _pool.GetGroup(Matcher.AllOf(Matcher.WaitingForSpace, Matcher.Spaceship));
     _asteroids = pool.GetGroup(Matcher.AllOf(Matcher.Asteroid, Matcher.CollisionRadius));
     _games = _pool.GetGroup(Matcher.AllOf(Matcher.Game, Matcher.Bounds));
     _lives = _pool.GetGroup(Matcher.Lives);
 }
Esempio n. 8
0
        public void Init(Pool pool, Entity entity)
        {
            _pool = pool;
            _entity = entity;
            _unfoldedComponents = new bool[_pool.totalComponents];
            _entity.OnComponentRemoved += onComponentRemoved;

            UnfoldAllComponents();
        }
        static void groupExample(Pool pool) {
            pool.GetGroup(Matcher.Position).GetEntities();

            // ----------------------------

            pool.GetGroup(Matcher.Position).OnEntityAdded += (group, entity) => {
                // Do something
            };
        }
Esempio n. 10
0
 ReactiveSystem(Pool pool, IReactiveExecuteSystem subSystem, IMatcher[] triggers, GroupEventType[] eventTypes)
 {
     _subsystem = subSystem;
     var groups = new Group[triggers.Length];
     for (int i = 0, triggersLength = triggers.Length; i < triggersLength; i++) {
         groups[i] = pool.GetGroup(triggers[i]);
     }
     _observer = new GroupObserver(groups, eventTypes);
     _buffer = new List<Entity>();
 }
        public void Init(Pool pool, Entity entity, Type[] componentTypes) {
            _pool = pool;
            _entity = entity;
            _componentTypes = componentTypes;
            componentToAdd = -1;
            _unfoldedComponents = new bool[_pool.totalComponents];
            _entity.OnEntityReleased += onEntityReleased;
            Update();

            UnfoldAllComponents();
        }
        public void Init(Pool pool, Entity entity, int debugIndex)
        {
            _pool = pool;
            _entity = entity;
            _debugIndex = debugIndex;
            _unfoldedComponents = new bool[_pool.totalComponents];
            _entity.OnComponentAdded += onEntityChanged;
            _entity.OnComponentRemoved += onEntityChanged;
            updateName();

            UnfoldAllComponents();
        }
        public void Start()
        {
            pool = Pools.pool;

            pool.GetGroup(EntitysToBeViewed).OnEntityAdded += (group, entity, index, component) => OnEntityAdded(entity);

            pool.GetGroup(EntitysToBeViewed).OnEntityRemoved +=
                (group, entity, index, component) => OnEntityRemoved(entity);

            pool.GetGroup(Matcher.GameState).OnEntityAdded +=
                (group, entity, index, component) => OnGameStateUpdated(entity.gameState.GameState);

            tableContents = new Dictionary<int, GameObject>();
        }
Esempio n. 14
0
        static void groupObserverExample(Pool pool)
        {
            var group = pool.GetGroup(Matcher.Position);
            var observer = group.CreateObserver(GroupEventType.OnEntityAdded);

            // ----------------------------
            foreach (var e in observer.collectedEntities) {
                // do something
            }
            observer.ClearCollectedEntities();

            // ----------------------------
            observer.Deactivate();
        }
Esempio n. 15
0
 ReactiveSystem(Pool pool, IReactiveExecuteSystem subSystem, IMatcher[] triggers, GroupEventType[] eventTypes)
 {
     _subsystem = subSystem;
     var ensureComponents = subSystem as IEnsureComponents;
     if (ensureComponents != null) {
         _ensureComponents = ensureComponents.ensureComponents;
     }
     var excludeComponents = subSystem as IExcludeComponents;
     if (excludeComponents != null) {
         _excludeComponents = excludeComponents.excludeComponents;
     }
     var groups = new Group[triggers.Length];
     for (int i = 0, triggersLength = triggers.Length; i < triggersLength; i++) {
         groups[i] = pool.GetGroup(triggers[i]);
     }
     _observer = new GroupObserver(groups, eventTypes);
     _buffer = new List<Entity>();
 }
Esempio n. 16
0
 public static Systems GetSystems(Pool pool)
 {
     #if (UNITY_EDITOR)
     return new DebugSystems()
     #else
         return new Systems()
     #endif
         // Initialize
         .Add(pool.CreateSystem<RemoveViewSystem>())
         .Add(pool.CreateSystem<AddViewSystem>())
         .Add(pool.CreateSystem<CreatePilotsSystem>())
         .Add(pool.CreateSystem<StartGameSystem>())
         .Add(pool.CreateSystem<CreateEventsSystem>())
         .Add(pool.CreateSystem<CreateAircraftSystem>())
         .Add(pool.CreateSystem<PauseSystem>())
         .Add(pool.CreateSystem<TimeSystem>())
         .Add(pool.CreateSystem<UINavigationSystem>())
         .Add(pool.CreateSystem<EventPredicateCheckingSystem>())
         .Add(pool.CreateSystem<EventResolutionSystem>());
 }
Esempio n. 17
0
 public PoolMetaDataException(Pool pool, PoolMetaData poolMetaData) :
     base("Invalid PoolMetaData for '" + pool + "'!\nExpected " + pool.totalComponents + " componentName(s) but got " + poolMetaData.componentNames.Length + ":",
         string.Join("\n", poolMetaData.componentNames)) {
 }
Esempio n. 18
0
 public PoolStillHasRetainedEntitiesException(Pool pool) :
     base("'" + pool + "' detected retained entities although all entities got destroyed!",
         "Did you release all entities? Try calling pool.ClearGroups() and systems.ClearReactiveSystems() before calling pool.DestroyAllEntities() to avoid memory leaks.") {
 }
Esempio n. 19
0
 /// Recommended way to create systems in general: pool.CreateSystem(new MySystem());
 public ReactiveSystem(Pool pool, IMultiReactiveSystem subSystem) :
     this(subSystem, createEntityCollector(pool, subSystem.triggers))
 {
 }
 // ------------------ Methods
 // Implement ISetPool to get the pool used when calling
 // pool.CreateSystem<FooSystem>();
 public void SetPool(Pool pool)
 {
     // Get the group of entities that have these component(s)
     _pool = pool;
 }
Esempio n. 21
0
 public PoolEntityIndexDoesNotExistException(Pool pool, string name) :
     base("Cannot get EntityIndex '" + name + "' from pool '" +
          pool + "'!", "No EntityIndex with this name has been added.")
 {
 }
Esempio n. 22
0
        static void userComponent(Pool pool, UserComponent component)
        {
            var e = pool.userEntity;
            var name = pool.user.name;
            var has = pool.hasUser;

            pool.SetUser("John", 42);
            pool.SetUser(component);

            pool.ReplaceUser("Max", 24);

            pool.RemoveUser();
        }
        public static void DrawComponents(Pool pool, Entity entity)
        {
            bool[] unfoldedComponents;
            if (!_poolToUnfoldedComponents.TryGetValue(pool, out unfoldedComponents)) {
                unfoldedComponents = new bool[pool.totalComponents];
                for (int i = 0; i < unfoldedComponents.Length; i++) {
                    unfoldedComponents[i] = true;
                }
                _poolToUnfoldedComponents.Add(pool, unfoldedComponents);
            }

            EntitasEditorLayout.BeginVerticalBox();
            {
                EntitasEditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Components (" + entity.GetComponents().Length + ")", EditorStyles.boldLabel);
                    if (GUILayout.Button("▸", GUILayout.Width(21), GUILayout.Height(14))) {
                        for (int i = 0; i < unfoldedComponents.Length; i++) {
                            unfoldedComponents[i] = false;
                        }
                    }
                    if (GUILayout.Button("▾", GUILayout.Width(21), GUILayout.Height(14))) {
                        for (int i = 0; i < unfoldedComponents.Length; i++) {
                            unfoldedComponents[i] = true;
                        }
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                EditorGUILayout.Space();

                var componentNames = entity.poolMetaData.componentNames;
                var index = EditorGUILayout.Popup("Add Component", -1, componentNames);
                if (index >= 0) {
                    var componentType = entity.poolMetaData.componentTypes[index];
                    var component = (IComponent)Activator.CreateInstance(componentType);
                    entity.AddComponent(index, component);
                }

                EditorGUILayout.Space();

                EntitasEditorLayout.BeginHorizontal();
                {
                    _componentNameSearchTerm = EditorGUILayout.TextField("Search", _componentNameSearchTerm);

                    const string clearButtonControlName = "Clear Button";
                    GUI.SetNextControlName(clearButtonControlName);
                    if (GUILayout.Button("x", GUILayout.Width(19), GUILayout.Height(14))) {
                        _componentNameSearchTerm = string.Empty;
                        GUI.FocusControl(clearButtonControlName);
                    }
                }
                EntitasEditorLayout.EndHorizontal();

                EditorGUILayout.Space();

                var indices = entity.GetComponentIndices();
                var components = entity.GetComponents();
                for (int i = 0; i < components.Length; i++) {
                    DrawComponent(unfoldedComponents, entity, indices[i], components[i]);
                }
            }
            EntitasEditorLayout.EndVertical();
        }
        /// This is the recommended way to create systems.
        /// It will create a new instance of the type, will inject the pool if ISetPool is implemented
        /// and will automatically create a ReactiveSystem if it is a IReactiveSystem or IMultiReactiveSystem.
        public static ISystem CreateSystem(this Pool pool, Type systemType)
        {
            var system = (ISystem)Activator.CreateInstance(systemType);

            return(pool.CreateSystem(system));
        }
Esempio n. 25
0
 /// Returns all entities matching the specified matcher.
 public static Entity[] GetEntities(this Pool pool, IMatcher matcher)
 {
     return(pool.GetGroup(matcher).GetEntities());
 }
Esempio n. 26
0
 /// This is the recommended way to create systems.
 /// It will inject the pool if ISetPool is implemented.
 /// It will inject the pools if ISetPools is implemented.
 /// It will automatically create a ReactiveSystem if it is a
 /// IReactiveSystem, IMultiReactiveSystem or IEntityCollectorSystem.
 public static ISystem CreateSystem(this Pool pool,
                                    IReactiveExecuteSystem system)
 {
     return(CreateSystem(pool, system, Pools.sharedInstance));
 }
 void switchToPool()
 {
     if (_pool != null) {
         _pool.Reset();
     }
     var targetPool = _allPools[_poolIndex];
     _pool = new Pool(targetPool.totalComponents, 0, targetPool.metaData);
     _entity = _pool.CreateEntity();
 }
        public static void DrawMultipleEntities(Pool pool, Entity[] entities)
        {
            EditorGUILayout.Space();
            EntitasEditorLayout.BeginHorizontal();
            {
                var entity = entities[0];
                var componentNames = entity.poolMetaData.componentNames;
                var index = EditorGUILayout.Popup("Add Component", -1, componentNames);
                if (index >= 0) {
                    var componentType = entity.poolMetaData.componentTypes[index];
                    foreach (var e in entities) {
                        var component = (IComponent)Activator.CreateInstance(componentType);
                        e.AddComponent(index, component);
                    }
                }
            }
            EntitasEditorLayout.EndHorizontal();

            EditorGUILayout.Space();

            var bgColor = GUI.backgroundColor;
            GUI.backgroundColor = Color.red;

            if (GUILayout.Button("Destroy selected entities")) {
                foreach (var e in entities) {
                    pool.DestroyEntity(e);
                }
            }

            GUI.backgroundColor = bgColor;

            EditorGUILayout.Space();

            foreach (var e in entities) {

                EntitasEditorLayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField(e.ToString());

                    bgColor = GUI.backgroundColor;
                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("Destroy Entity")) {
                        pool.DestroyEntity(e);
                    }

                    GUI.backgroundColor = bgColor;
                }
                EntitasEditorLayout.EndHorizontal();
            }
        }
 public void SetPool(Pool pool)
 {
     systemPool = pool;
 }
 /// This is the recommended way to create systems.
 /// It will create a new instance of the type, will inject the pool if ISetPool is implemented
 /// and will automatically create a ReactiveSystem if it is a IReactiveSystem or IMultiReactiveSystem.
 public static ISystem CreateSystem <T>(this Pool pool) where T : ISystem, new()
 {
     return(pool.CreateSystem(typeof(T)));
 }
Esempio n. 31
0
 /// Recommended way to create systems in general: pool.CreateSystem(new MySystem());
 public ReactiveSystem(Pool pool, IReactiveSystem subSystem) :
     this(subSystem, createEntityCollector(pool, new [] { subSystem.trigger }))
 {
 }
Esempio n. 32
0
 static void groupExample(Pool pool)
 {
     pool.GetGroup(Matcher.Position).GetEntities();
 }
 public void SetPool(Pool pool)
 {
     _pool = pool;
     _lives = pool.GetGroup(Matcher.Lives);
     _spaceships = pool.GetGroup(Matcher.AllOf(Matcher.Spaceship, Matcher.View));
 }
Esempio n. 34
0
 public PoolEntityIndexDoesAlreadyExistException(Pool pool, string name) :
     base("Cannot add EntityIndex '" + name + "' to pool '" + pool + "'!",
          "An EntityIndex with this name has already been added.")
 {
 }
        public static void DrawEntity(Pool pool, Entity entity)
        {
            var bgColor = GUI.backgroundColor;
            GUI.backgroundColor = Color.red;
            if (GUILayout.Button("Destroy Entity")) {
                pool.DestroyEntity(entity);
            }
            GUI.backgroundColor = bgColor;

            DrawComponents(pool, entity);

            EditorGUILayout.Space();

            EditorGUILayout.LabelField("Retained by (" + entity.retainCount + ")", EditorStyles.boldLabel);

            #if !ENTITAS_FAST_AND_UNSAFE

            EntitasEditorLayout.BeginVerticalBox();
            {
                foreach (var owner in entity.owners.ToArray()) {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(owner.ToString());
                        if (GUILayout.Button("Release", GUILayout.Width(88), GUILayout.Height(14))) {
                            entity.Release(owner);
                        }
                        EntitasEditorLayout.EndHorizontal();
                    }
                }
            }
            EntitasEditorLayout.EndVertical();

            #endif
        }
Esempio n. 36
0
 public void SetPool(Pool pool)
 {
     ourPool = pool;
 }
 // ------------------ Methods
 // Implement ISetPool to get the pool used when calling
 // pool.CreateSystem<FooSystem>();
 public void SetPool(Pool pool)
 {
     _pool = pool;
 }
Esempio n. 38
0
        static void poolExample()
        {
            // Total components is kindly generated for you by the code generator
            var pool = new Pool(ComponentIds.TotalComponents);
            var entity = pool.CreateEntity();
            entity.isMovable = true;

            // Returns all entities having MovableComponent and PositionComponent.
            // Matchers are also generated for you.
            var entities = pool.GetEntities(Matcher.AllOf(Matcher.Movable, Matcher.Position));
            foreach (var e in entities) {
                // do something
            }
        }