public void Reset() { ComponentPools.Clear(); #if UNITY_EDITOR GroupedComponents.Clear(); #endif _newEnt = new Entity(); EntityName = ""; UnityDrawerStatics.RefreshPrefabList(); UnityDrawerStatics.RefreshEntityList(); UnityDrawerStatics.RefreshComponentList(); //FindAllComponents(); //OnDataChanged?.Invoke(); IsDirty = false; AvoidDirtyFlag = true; }
public static void GenerateCode() { if (!AutoGenerate) { return; } UnityDrawerStatics.RefreshAll(); EntityListFormatted = @"public static class Entities {" ; foreach (var ent in UnityDrawerStatics.EntityList) { string entName = FileOps.GetStringAfterLastSlash(ent).StripNonAlphanumeric(); EntityListFormatted += "\n\t\t\tpublic const string " + entName + " = \"" + ent + "\";"; } EntityListFormatted += @" } public static class Prefabs {" ; foreach (var pre in UnityDrawerStatics.PrefabList) { string preName = FileOps.GetStringAfterLastSlash(pre).StripNonAlphanumeric(); EntityListFormatted += "\n\t\t\tpublic const string " + preName + " = \"" + pre + "\";"; } EntityListFormatted += @" }" ; string fullString = FileOps.ReplaceLineEndings(HEADER_FORMAT + EntityListFormatted + FOOTER_FORMAT); using (var file = File.Open(ResFilePath, FileMode.Create)) { using (var writer = new StreamWriter(file)) { writer.Write(fullString); } } AssetDatabase.Refresh(); }
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; }