internal void InitPool(string entityName, int count)
        {
            if (unityEntitiesPools.ContainsKey(entityName))
            {
                throw new InvalidOperationException("Pool with name " + entityName + " already exists!");
            }

            var pool = new Stack <UnityEntity>(count);

            for (var i = 0; i < count; i++)
            {
                var entity = UnityEntity.CreateNewEntityInstance(this, entityName);

                pool.Push(entity);
            }

            unityEntitiesPools.Add(entityName, pool);
        }
        private void CreateUnityEntity(Entity entity)
        {
            unityEntitiesPools.TryGetValue(entity.name, out var pool);

            UnityEntity unityEntity;

            if (pool == null || pool.Count == 0)
            {
                unityEntity = UnityEntity.CreateNewEntityInstance(this, entity.name);
            }
            else
            {
                unityEntity = pool.Pop();
            }

            unityActiveEntities[entity.EntityBagIndex] = unityEntity;

            unityEntity.Create(entity);
        }
Exemple #3
0
        //TODO: Can replaced to visual component editor

        public static UnityEntity CreateNewEntityInstance(UnityEntityManager unityEntityManager, string name)
        {
            var unityEntity = new UnityEntity(unityEntityManager, name, 1);

            if (name == "Laser")
            {
                unityEntity.unityComponents[0] = new UnityLaserController(unityEntity);
            }
            else //general logic for other entities (example)
            {
                unityEntity.unityComponents[0] = new UnityTransform(unityEntity, name == "Bullet");
            }

            if (unityEntity == null)
            {
                throw new Exception("Could not create unity entity by name: " + name);
            }

            return(unityEntity);
        }