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 Entity CreateEntityFromTemplate(string entityName) { //Debug.Log($"{entityName} creating from template"); object deserialized = null; entityName = FileOps.GetStringAfterLastSlash(entityName); _serializer.TryDeserialize( _entityTemplates[entityName], typeof(Entity), ref deserialized ); Entity newEntity = (Entity)deserialized; InitializeNewEntity(newEntity); engine?.EntityList.Add(newEntity); engine?.TriggerEntityAdded(newEntity); return(newEntity); }
public static void GenerateCode() { if (!AutoGenerate || IsGenerating) { return; } //Re-entrant code generation no good IsGenerating = true; ComponentListFormatted = ""; ComponentEnums = ""; var allcomp = GetAllComponentList(); foreach (var comp in allcomp) { string entName = FileOps.GetStringAfterLastSlash(comp); string comma = ","; if (comp == allcomp.Last()) //last element { comma = ""; } string newLine = "\n\t\t\t" + "{ComponentTypes." + entName + ", typeof(" + entName + ")}" + comma; ComponentListFormatted += newLine; ComponentEnums += "\n\t\t" + entName + comma; Console.WriteLine(newLine); } ComponentListFormatted += @" }; public static ComponentEcs Create(ComponentTypes type) { if (!ComponentLookup.ContainsKey(type)) return null; return ComponentCache.Instance.Get(type); } public static ComponentEcs Instantiate(ComponentTypes type) { return (ComponentEcs) Activator.CreateInstance(ComponentLookup[type]); } } public enum ComponentTypes {"; ComponentListFormatted += ComponentEnums; string fullString = FileOps.ReplaceLineEndings(HEADER_FORMAT + ComponentListFormatted + FOOTER_FORMAT); //Debug.Log(fullString); using (var file = File.Open(CompFactoryFilePath, FileMode.Truncate)) { using (var writer = new StreamWriter(file)) { writer.Write(fullString); } } int idx = CompFactoryFilePath.IndexOf("Assets"); string newFilePath = CompFactoryFilePath.Substring(idx, CompFactoryFilePath.Length - idx); AssetDatabase.ImportAsset(newFilePath); IsGenerating = false; }
/// <summary> /// Finds an entity from Res.Entity mapping - DO NOT USE IN UPDATE! /// </summary> /// <param name="entityToFind">Res.Entity string mapping</param> /// <returns>The Entity which matches or null</returns> public Entity FindEntity(string entityToFind) { string entName = FileOps.GetStringAfterLastSlash(entityToFind); return(EntityList.Find(x => x.EntityName.Equals(entName))); }