public static List <Type> GetAllComponentTypes(ECSContextConfig config) { Assembly assembly = GetECSAssembly(config); if (assembly == null) { return(null); } Type baseInterface = assembly.GetType($"I{config.Name}Component"); if (baseInterface == null) { return(null); } List <Type> types = new List <Type>(); foreach (var type in assembly.GetTypes()) { if (type.IsInterface || type.IsAbstract) { continue; } if (baseInterface.IsAssignableFrom(type)) { types.Add(type); } } return(types); }
public static void GeneratorComponent(ECSContextConfig config) { string folder = Path.Combine(config.DirectoryPath, "Generates"); GeneratorFolder generatorFolder = new GeneratorFolder(folder, "cs"); ComponentGenerator componentGenerator = new ComponentGenerator(config); componentGenerator.Gen(generatorFolder); generatorFolder.WriteFile(); }
public static List <string> GetSystemsCatalog(this ECSContextConfig config) { List <string> results = new List <string>(); string path = Path.Combine(config.DirectoryPath, "Systems"); DirectoryInfo directoryInfo = new DirectoryInfo(path); AddDir(directoryInfo, null, results); return(results); }
public ECSContextConfig AddContext(string name, string path) { do { if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(path)) { if (Contexts.Exists(it => it.Name == name)) { EditorUtility.DisplayDialog("错误", $"已经存在重名的Context => {name}", "ok"); break; } if (Contexts.Exists(it => it.DirectoryPath == path)) { EditorUtility.DisplayDialog("错误", $"已经存在相同的文件夹 => {path}", "ok"); break; } if (!char.IsUpper(name[0])) { EditorUtility.DisplayDialog("错误", "名字首字母应该大写", "ok"); break; } bool validName = true; for (int i = 0; i < name.Length; ++i) { if (!char.IsLetter(name[i])) { EditorUtility.DisplayDialog("错误", $"名字含有非法字符{name[i]}", "ok"); break; } } if (!validName) { break; } MakeModify("add ecs from exits"); ECSContextConfig config = new ECSContextConfig { Name = name, DirectoryPath = path }; Contexts.Add(config); return(config); } } while (false); return(null); }
public ComponentGenerator(ECSContextConfig config) { componentTypes.AddRange(config.ComponentTypes); context = config; }
public static Assembly GetECSAssembly(ECSContextConfig config) { string contextFile = Path.Combine(config.DirectoryPath, $"{config.Name}ECS.cs"); return(MonoScriptUtils.GetScriptAssembly(contextFile)); }