Skip to content

Commit 219c200

Browse files
committed
adds button to create assembly definition for user
1 parent 5c6e1db commit 219c200

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

EcsactCsharpSystemImpl/Editor/CsharpSystemImplSettingsEditor.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,47 @@ public override void OnInspectorGUI() {
151151
wide: false
152152
);
153153
}
154+
} else {
155+
GUILayout.BeginHorizontal();
156+
EditorGUILayout.PrefixLabel(" ");
157+
var pressed = GUILayout.Button(
158+
"Create New Assembly Definition",
159+
new[] { GUILayout.MaxWidth(240) }
160+
);
161+
GUILayout.EndHorizontal();
162+
if(pressed) {
163+
var newAsmDefPath = EditorUtility.SaveFilePanelInProject(
164+
title: "Ecsact System Implementations Assembly Definition",
165+
defaultName: "SystemImpls.asmdef",
166+
extension: "asmdef",
167+
message: "Choose a location where your C# system implementations " +
168+
"definition is stored. Make sure to put it in a separate folder."
169+
);
170+
171+
if(!string.IsNullOrEmpty(newAsmDefPath)) {
172+
var newAsmDef = new UnityAssemblyDefinitionFile();
173+
newAsmDef.name = $"{Application.identifier}.EcsactSystemImpls";
174+
newAsmDef.autoReferenced = true;
175+
newAsmDef.noEngineReferences = false;
176+
newAsmDef.references = new();
177+
newAsmDef.references.Add("GUID:2d10fa57d8150f7499b7579b289a41a2");
178+
newAsmDef.references.Add("GUID:6e7029456009ab94da19a8f93d5e3523");
179+
global::System.IO.File.WriteAllText(
180+
path: newAsmDefPath,
181+
contents: JsonUtility.ToJson(newAsmDef, true)
182+
);
183+
AssetDatabase.ImportAsset(
184+
newAsmDefPath,
185+
ImportAssetOptions.ForceSynchronousImport
186+
);
187+
settings.systemImplsAssembly =
188+
AssetDatabase
189+
.LoadAssetAtPath<UnityEditorInternal.AssemblyDefinitionAsset>(
190+
newAsmDefPath
191+
);
192+
AssetDatabase.SaveAssetIfDirty(settings);
193+
}
194+
}
154195
}
155196
}
156197

0 commit comments

Comments
 (0)