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); }