Skip to content

Commit 62e8fbd

Browse files
committed
2023.6.1-a Initial Commit
1 parent 09b9aec commit 62e8fbd

File tree

789 files changed

+54767
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

789 files changed

+54767
-0
lines changed

ME.BECS/Addons.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ME.BECS/Addons/Features.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ME.BECS/Addons/Features/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
2+
namespace ME.BECS.Features.Editor {
3+
4+
public abstract class CreateProjectDefaultModule {
5+
6+
public abstract string CreateModule(string projectPath, string projectName);
7+
8+
}
9+
10+
public static class CreateProjectMenu {
11+
12+
[UnityEditor.MenuItem("ME.BECS/Features Graph...")]
13+
public static void ShowFeaturesGraph() {
14+
15+
ME.BECS.Editor.FeaturesGraph.FeaturesGraphEditorWindow.ShowWindow();
16+
17+
}
18+
19+
public class EndCreateProject : UnityEditor.ProjectWindowCallback.EndNameEditAction {
20+
21+
public System.Action<string> onCreated;
22+
23+
public override void Action(int instanceId, string pathName, string resourceFile) {
24+
this.onCreated.Invoke(pathName);
25+
}
26+
27+
}
28+
29+
[UnityEditor.MenuItem("Assets/Create/ME.BECS/Create Project")]
30+
public static void CreateProject() {
31+
32+
var dirObject = UnityEditor.Selection.activeObject;
33+
string pathRoot = "Assets";
34+
if (dirObject != null) {
35+
pathRoot = UnityEditor.AssetDatabase.GetAssetPath(dirObject);
36+
}
37+
if (pathRoot != null) {
38+
var newProject = UnityEngine.ScriptableObject.CreateInstance<EndCreateProject>();
39+
newProject.onCreated = (path) => {
40+
path = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(path);
41+
var newName = System.IO.Path.GetFileName(path);
42+
var dirGuid = UnityEditor.AssetDatabase.CreateFolder(pathRoot, newName);
43+
var dirPath = UnityEditor.AssetDatabase.GUIDToAssetPath(dirGuid);
44+
{
45+
newName = newName.Replace(" ", string.Empty);
46+
CreateAssembly(dirPath, newName);
47+
var guid = CreateTemplateScript(dirPath, newName);
48+
var graph = CreateDefaultFeaturesGraph(dirPath, newName);
49+
var modules = new System.Collections.Generic.List<string>();
50+
var customModules = UnityEditor.TypeCache.GetTypesDerivedFrom<CreateProjectDefaultModule>();
51+
foreach (var moduleType in customModules) {
52+
var instance = (CreateProjectDefaultModule)System.Activator.CreateInstance(moduleType);
53+
modules.Add(instance.CreateModule(dirPath, newName));
54+
}
55+
CreateObjectOnScene(dirPath, newName, graph, guid, modules);
56+
}
57+
};
58+
UnityEditor.ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, newProject, pathRoot + "/NewProject", UnityEditor.EditorGUIUtility.FindTexture("d_Folder Icon"), "", true);
59+
}
60+
61+
}
62+
63+
private static ME.BECS.FeaturesGraph.SystemsGraph CreateDefaultFeaturesGraph(string path, string name) {
64+
65+
var graph = ME.BECS.FeaturesGraph.SystemsGraph.CreateInstance<ME.BECS.FeaturesGraph.SystemsGraph>();
66+
var assetPath = $"{path}/{name}-FeaturesGraph.asset";
67+
UnityEditor.AssetDatabase.CreateAsset(graph, assetPath);
68+
graph = UnityEditor.AssetDatabase.LoadAssetAtPath<ME.BECS.FeaturesGraph.SystemsGraph>(assetPath);
69+
return graph;
70+
71+
}
72+
73+
private static void CreateObjectOnScene(string path, string name, ME.BECS.FeaturesGraph.SystemsGraph graph, string guid, System.Collections.Generic.List<string> modules) {
74+
75+
UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(graph, out var guidGraph, out long localId);
76+
var prefabContent = ME.BECS.Editor.EditorUtils.LoadResource<UnityEngine.TextAsset>("ME.BECS.Resources/Templates/DefaultPrefab-Template.txt").text;
77+
prefabContent = prefabContent.Replace("{{PROJECT_NAME}}", name);
78+
prefabContent = prefabContent.Replace("{{GUID}}", guid);
79+
prefabContent = prefabContent.Replace("{{GUID_GRAPH}}", guidGraph);
80+
var str = " - enabled: 1\n obj: {fileID: 11400000, guid: {{GUID}}, type: 2}";
81+
var guids = new System.Collections.Generic.List<string>();
82+
foreach (var module in modules) {
83+
guids.Add(str.Replace("{{GUID}}", module));
84+
}
85+
prefabContent = prefabContent.Replace("{{GUID_MODULES}}", string.Join("\n", guids));
86+
87+
var assetPath = $"{path}/{name}Initializer.prefab";
88+
System.IO.File.WriteAllText(assetPath, prefabContent);
89+
UnityEditor.AssetDatabase.ImportAsset(assetPath);
90+
91+
UnityEditor.PrefabUtility.InstantiatePrefab(UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.GameObject>(assetPath));
92+
93+
}
94+
95+
private static string CreateTemplateScript(string path, string name) {
96+
97+
var scriptContent = ME.BECS.Editor.EditorUtils.LoadResource<UnityEngine.TextAsset>("ME.BECS.Resources/Templates/DefaultScript-Template.txt").text;
98+
scriptContent = scriptContent.Replace("{{PROJECT_NAME}}", name);
99+
100+
var assetPath = $"{path}/{name}Initializer.cs";
101+
System.IO.File.WriteAllText(assetPath, scriptContent);
102+
UnityEditor.AssetDatabase.ImportAsset(assetPath);
103+
104+
UnityEditor.AssetDatabase.TryGetGUIDAndLocalFileIdentifier(UnityEditor.AssetDatabase.LoadAssetAtPath<UnityEngine.TextAsset>(assetPath), out var guid, out long localId);
105+
var metaAssetPath = $"{assetPath}.meta";
106+
var meta = ME.BECS.Editor.EditorUtils.LoadResource<UnityEngine.TextAsset>("ME.BECS.Resources/Templates/DefaultScriptMeta-Template.txt").text;
107+
meta = meta.Replace("{{GUID}}", guid);
108+
System.IO.File.WriteAllText(metaAssetPath, meta);
109+
110+
return guid;
111+
112+
}
113+
114+
private static void CreateAssembly(string path, string name) {
115+
116+
var asmContent = ME.BECS.Editor.EditorUtils.LoadResource<UnityEngine.TextAsset>("ME.BECS.Resources/Templates/DefaultAssembly-Template.txt").text;
117+
asmContent = asmContent.Replace("{{PROJECT_NAME}}", name);
118+
119+
var assetPath = $"{path}/{name}.asmdef";
120+
System.IO.File.WriteAllText(assetPath, asmContent);
121+
UnityEditor.AssetDatabase.ImportAsset(assetPath);
122+
123+
}
124+
125+
}
126+
127+
}

ME.BECS/Addons/Features/Editor/CreateProjectMenu.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ME.BECS/Addons/Features/Editor/EditorResources.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ME.BECS/Addons/Features/Editor/EditorResources/ME.BECS.Resources.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ME.BECS/Addons/Features/Editor/EditorResources/ME.BECS.Resources/Styles.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.systems-graph-field {
2+
margin: 0px;
3+
border-radius: 8px;
4+
background-color: rgba(0, 0, 0, 0.1);
5+
margin-top: 2px;
6+
margin-bottom: 2px;
7+
padding: 8px;
8+
border-left-width: 2px;
9+
border-color: #af3733;
10+
}
11+
12+
.systems-graph-field.set {
13+
border-color: #82af33;
14+
}

ME.BECS/Addons/Features/Editor/EditorResources/ME.BECS.Resources/Styles/FeaturesGraph.uss.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)