예제 #1
0
        IEnumerator PollForInput()
        {
            while (true)
            {
                while (_buttonConsumer.TryDequeue(out var entity))
                {
                    if (entity.message == ButtonEvents.SELECT)
                    {
                        IGuiViewIndex guiViewIndex = entitiesDB.QueryEntity <GuiViewIndexEntityViewStruct>(entity.ID).guiViewIndex;

                        ExclusiveGroup.ExclusiveGroupStruct group = entity.ID.groupID;
                        if (string.IsNullOrEmpty(guiViewIndex.groupName) == false)
                        {
                            group = ExclusiveGroup.Search(guiViewIndex.groupName);
                        }

                        var entities = entitiesDB.QueryEntities <GUIEntityViewStruct>(group);
                        foreach (var gui in entities)
                        {
                            gui.guiRoot.view = guiViewIndex.index;
                        }
                    }
                }

                yield return(null);
            }
        }
        public static uint CreateAll <T>(uint startIndex, ExclusiveGroup group, Transform contextHolder,
                                         IEntityFactory factory) where T : MonoBehaviour, IEntityDescriptorHolder
        {
            var holders = contextHolder.GetComponentsInChildren <T>(true);

            foreach (var holder in holders)
            {
                var implementors = holder.GetComponents <IImplementor>();

                ExclusiveGroup.ExclusiveGroupStruct realGroup = group;

                if (string.IsNullOrEmpty(holder.groupName) == false)
                {
                    realGroup = ExclusiveGroup.Search(holder.groupName);
                }

                EGID egid;
                var  holderId = holder.id;
                if (holderId == 0)
                {
                    egid = new EGID(startIndex++, realGroup);
                }
                else
                {
                    egid = new EGID(holderId, realGroup);
                }

                var init = factory.BuildEntity(egid, holder.GetDescriptor(), implementors);

                init.Init(new EntityHierarchyStruct(group));
            }

            return(startIndex);
        }
예제 #3
0
        static uint InternalBuildAll(uint startIndex, IEntityDescriptorHolder descriptorHolder,
                                     IEntityFactory factory, ExclusiveGroup group, IImplementor[] implementors, string groupNamePostfix)
        {
            ExclusiveGroup.ExclusiveGroupStruct realGroup = group;

            if (string.IsNullOrEmpty(descriptorHolder.groupName) == false)
            {
                realGroup = ExclusiveGroup.Search(!string.IsNullOrEmpty(groupNamePostfix)
                    ? $"{descriptorHolder.groupName}{groupNamePostfix}"
                    : descriptorHolder.groupName);
            }

            EGID egid;
            var  holderId = descriptorHolder.id;

            if (holderId == 0)
            {
                egid = new EGID(startIndex++, realGroup);
            }
            else
            {
                egid = new EGID(holderId, realGroup);
            }

            var init = factory.BuildEntity(egid, descriptorHolder.GetDescriptor(), implementors);

            init.Init(new EntityHierarchyStruct(group));

            return(startIndex);
        }
예제 #4
0
 public void ExecuteOnEntity <T, W>(int id,
                                    ExclusiveGroup.ExclusiveGroupStruct groupid,
                                    ref W value,
                                    EntityAction <T, W> action) where T : IEntityStruct
 {
     ExecuteOnEntity(id, (int)groupid, ref value, action);
 }
예제 #5
0
        public ref T QueryUniqueEntity <T>(ExclusiveGroup.ExclusiveGroupStruct @group) where T : struct, IEntityStruct
        {
            var entities = QueryEntities <T>(@group, out var count);

            if (count != 1)
            {
                throw new ECSException("Unique entities must be unique! ".FastConcat(typeof(T).ToString()));
            }
            return(ref entities[0]);
예제 #6
0
 /// <summary>
 ///     MovedTo callbacks are enabled by the IReactOnSwap interface
 ///     They are called on entity swap (when leaving a group and moving to the new one)
 /// </summary>
 /// <param name="entityViewStruct"></param>
 public void MovedTo(ref EnemyAttackEntityViewStruct entityViewStruct,
                     ExclusiveGroup.ExclusiveGroupStruct previousGroup, EGID egid)
 {
     if (egid.groupID == ECSGroups.ActiveEnemies)
     {
         entityViewStruct.targetTriggerComponent.hitChange.ResumeNotify();
     }
     else
     {
         entityViewStruct.targetTriggerComponent.hitChange.PauseNotify();
     }
 }
        public static void CreateAll <T>(ExclusiveGroup group, Transform contextHolder,
                                         IEntityFactory factory) where T : MonoBehaviour, IEntityDescriptorHolder
        {
            var holders = contextHolder.GetComponentsInChildren <T>(true);

            foreach (var holder in holders)
            {
                var implementors = holder.GetComponents <IImplementor>();

                ExclusiveGroup.ExclusiveGroupStruct realGroup = group;

                if (string.IsNullOrEmpty(holder.groupName) == false)
                {
                    realGroup = ExclusiveGroup.Search(holder.groupName);
                }

                factory.BuildEntity(holder.GetInstanceID(), realGroup, holder.GetDescriptor(), implementors);
            }
        }
예제 #8
0
        /// <summary>
        ///     Reset all the component values when an Enemy is ready to be recycled.
        ///     it's important to not forget to reset all the states.
        ///     note that the only reason why we pool it the entities here is to reuse the implementors,
        ///     pure entity structs entities do not need pool and can be just recreated
        /// </summary>
        /// <param name="spawnData"></param>
        /// <returns></returns>
        void ReuseEnemy(ExclusiveGroup.ExclusiveGroupStruct fromGroupId, JSonEnemySpawnData spawnData)
        {
            var healths = entitiesDB.QueryEntities <HealthEntityStruct>(fromGroupId, out var count);

            if (count > 0)
            {
                var enemystructs = entitiesDB.QueryEntities <EnemyEntityViewStruct>(fromGroupId, out count);
                healths[0].currentHealth = 100;
                healths[0].dead          = false;

                var spawnInfo = spawnData.enemySpawnData.spawnPoint;

                enemystructs[0].transformComponent.position           = spawnInfo;
                enemystructs[0].movementComponent.navMeshEnabled      = true;
                enemystructs[0].movementComponent.setCapsuleAsTrigger = false;
                enemystructs[0].layerComponent.layer     = GAME_LAYERS.ENEMY_LAYER;
                enemystructs[0].animationComponent.reset = true;

                _entityFunctions.SwapEntityGroup <EnemyEntityDescriptor>(enemystructs[0].ID, ECSGroups.ActiveEnemies);
            }
        }
 public EntityStructInitializer BuildEntity <T>(ExclusiveGroup.ExclusiveGroupStruct groupID, object[] implementors = null) where T : IEntityDescriptor, new()
 {
     return(_weakEngine.Target.BuildEntity <T>(groupID, implementors));
 }
예제 #10
0
 public void MovedTo(ref EntityStruct entityView, ExclusiveGroup.ExclusiveGroupStruct previousGroup, EGID egid)
 {
     Console.Log("Swap happened");
 }
예제 #11
0
 public EntityHierarchyStruct(ExclusiveGroup @group) : this()
 {
     parentGroup = group;
 }
예제 #12
0
 public T[] QueryEntitiesAndIndex <T>(int id, ExclusiveGroup.ExclusiveGroupStruct @group, out uint index) where T : IEntityStruct
 {
     return(QueryEntitiesAndIndex <T>(new EGID(id, group), out index));
 }
 public void ExecuteOnEntities <T, W>(ExclusiveGroup.ExclusiveGroupStruct groupStructId,
                                      ref W value, EntitiesAction <T, W> action) where T : IEntityStruct
 {
     ExecuteOnEntities((uint)groupStructId, ref value, action);
 }
 public void PreallocateEntitySpace <T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId, int size) where T : IEntityDescriptor, new()
 {
     _weakEngine.Target.Preallocate <T>(groupStructId, size);
 }
예제 #15
0
 public bool HasAny <T>(ExclusiveGroup.ExclusiveGroupStruct groupStruct) where T : IEntityStruct
 {
     return(HasAny <T>((int)groupStruct));
 }
예제 #16
0
 public bool TryQueryEntitiesAndIndex <T>(int id, ExclusiveGroup.ExclusiveGroupStruct @group, out uint index, out T[] array) where T : IEntityStruct
 {
     return(TryQueryEntitiesAndIndex <T>(new EGID(id, group), out index, out array));
 }
예제 #17
0
 public void ExecuteOnEntities <T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId,
                                   EntitiesAction <T> action) where T : IEntityStruct
 {
     ExecuteOnEntities((int)groupStructId, action);
 }
예제 #18
0
 public EGIDMapper <T> QueryMappedEntities <T>(ExclusiveGroup.ExclusiveGroupStruct groupStructId) where T : IEntityStruct
 {
     return(QueryMappedEntities <T>((int)groupStructId));
 }
예제 #19
0
 public T[] QueryEntities <T>(ExclusiveGroup.ExclusiveGroupStruct groupStruct, out int targetsCount) where T : IEntityStruct
 {
     return(QueryEntities <T>((int)groupStruct, out targetsCount));
 }
예제 #20
0
 public bool TryQueryEntityView <T>(int id, ExclusiveGroup.ExclusiveGroupStruct @group, out T entityView) where T : class, IEntityStruct
 {
     return(TryQueryEntityViewInGroupInternal(new EGID(id, (int)@group), out entityView));
 }
 public ReadOnlyCollectionStruct <T> QueryEntityViews <T>(ExclusiveGroup.ExclusiveGroupStruct group) where T : class, IEntityStruct
 {
     return(QueryEntityViews <T>((uint)group));
 }
 public EntityStructInitializer BuildEntity <T>(int entityID, ExclusiveGroup.ExclusiveGroupStruct groupStructId, T descriptorEntity, object[] implementors)  where T : IEntityDescriptor
 {
     return(_weakEngine.Target.BuildEntity(new EGID(entityID, (int)groupStructId), descriptorEntity, implementors));
 }
 public T QueryEntityView <T>(uint id, ExclusiveGroup.ExclusiveGroupStruct group) where T : class, IEntityStruct
 {
     return(QueryEntityView <T>(new EGID(id, group)));
 }
예제 #24
0
 //search for the group
 public bool Exists(ExclusiveGroup.ExclusiveGroupStruct gid)
 {
     return(_groupEntityViewsDB.ContainsKey(@gid));
 }