public bool CheckPoolExists(string entity)
 {
     if (entity == null)
     {
         return(false);
     }
     return(EntityMap.ContainsKey(FileOps.GetEntityNameFromFullName(entity)));
 }
        public Entity CreateEntityFromPool(string entityName)
        {
            entityName = FileOps.GetEntityNameFromFullName(entityName);
            if (!EntityPool.Instance.CheckPoolHasFreeItems(entityName))
            {
                return(CreateEntityFromTemplate(entityName));
            }

            //Debug.Log($"{entityName} retrieved from pool");
            Entity e = EntityPool.Instance.RetrieveFromPool(entityName);

            e.Enabled = true;
            InitializeNewEntity(e);
            engine?.EntityList.Add(e);

            engine?.TriggerEntityAdded(e);
            return(e);
        }
Exemple #3
0
        public void SaveEntityToJson()
        {
            _newEnt = new Entity(FileOps.GetEntityNameFromFullName(EntityName));
            //_newEnt = new Entity(EntityName);
            Debug.Log($"Saving entity: {EntityName}");
            foreach (var typ in ComponentPools)
            {
                foreach (var cmp in typ.Value)
                {
                    //Debug.Log($"Adding comp from gui: {cmp.ObjectType.Name}");
                    _newEnt.AddComponentFromGUI(cmp);
                    cmp.SetId(Guid.Empty);                     //Keep this out of prod code
                }
            }
            _newEnt.IsPooled = ShouldPoolEntity;

            Serializer.TrySerialize(typeof(Entity), _newEnt, out _data).AssertSuccess();

            var filePath = Application.dataPath + "/Resources/Entities/" + EntityName + ".json";

            Directory.CreateDirectory(Application.dataPath + "/Resources/Entities/" + FileOps.GetTypeFromFullName(EntityName) + "/");

            using (var file = File.Open(filePath, FileMode.Create))
            {
                using (var writer = new StreamWriter(file))
                {
                    fsJsonPrinter.PrettyJson(_data, writer);
                }
            }
            IsDirty = false;

            AssetDatabase.Refresh();

            UnityDrawerStatics.RefreshEntityList();
            AvoidDirtyFlag = true;
        }