rename時にRootnamespaceも変更できるように

This commit is contained in:
naninunenoy 2021-10-13 01:24:51 +09:00
parent 6e87411074
commit 1bfa4d5b41
2 changed files with 14 additions and 3 deletions

View File

@ -21,8 +21,8 @@ namespace AsmdefHelper.CustomCreate.Editor {
if (extension == "asmdef") { if (extension == "asmdef") {
var window = GetWindow<AsmdefRenameView>(); var window = GetWindow<AsmdefRenameView>();
window.titleContent = new GUIContent("AsmdefRenameView"); window.titleContent = new GUIContent("AsmdefRenameView");
window.minSize = new Vector2(200, 80); window.minSize = new Vector2(200, 100);
window.maxSize = new Vector2(2000, 80); window.maxSize = new Vector2(2000, 100);
} }
} }
@ -46,6 +46,7 @@ namespace AsmdefHelper.CustomCreate.Editor {
// UI取得 // UI取得
var PathTextField = root.Q<TextField>(className: "PathTextField"); var PathTextField = root.Q<TextField>(className: "PathTextField");
var NameTextField = root.Q<TextField>(className: "NameTextField"); var NameTextField = root.Q<TextField>(className: "NameTextField");
var RootNamespaceTextField = root.Q<TextField>(className: "RootNamespaceTextField");
var CreateButton = root.Q<Button>(className: "RenameButton"); var CreateButton = root.Q<Button>(className: "RenameButton");
// 既存のasmdef読み込み // 既存のasmdef読み込み
@ -56,11 +57,20 @@ namespace AsmdefHelper.CustomCreate.Editor {
PathTextField.value = asmdefDirectory; PathTextField.value = asmdefDirectory;
NameTextField.value = asmdef.name; NameTextField.value = asmdef.name;
// RootNamespace が設定できるのは2020.2以降
#if UNITY_2020_2_OR_NEWER
RootNamespaceTextField.value = asmdef.rootNamespace;
#else
root.Q<Box>(className: "Box").Remove(RootNamespaceTextField);
#endif
// .asmdefのnameとファイル名を更新して閉じる // .asmdefのnameとファイル名を更新して閉じる
CreateButton.clickable.clicked += () => { CreateButton.clickable.clicked += () => {
// nameのみ更新
var asmdefName = NameTextField.value; var asmdefName = NameTextField.value;
asmdef.name = asmdefName; asmdef.name = asmdefName;
#if UNITY_2020_2_OR_NEWER
asmdef.rootNamespace = RootNamespaceTextField.value;
#endif
var asmdefJson = JsonUtility.ToJson(asmdef, true); var asmdefJson = JsonUtility.ToJson(asmdef, true);
var newAsmdefPath = $"{asmdefDirectory}/{asmdefName}.asmdef"; var newAsmdefPath = $"{asmdefDirectory}/{asmdefName}.asmdef";
// 新asmdef作成 // 新asmdef作成

View File

@ -9,6 +9,7 @@
<engine:Box> <engine:Box>
<engine:TextField class="PathTextField" label="Path" text="ASMDEF_PATH_HERE" readonly="true"/> <engine:TextField class="PathTextField" label="Path" text="ASMDEF_PATH_HERE" readonly="true"/>
<engine:TextField class="NameTextField" label="Name" text="ASMDEF_NAME_HERE"/> <engine:TextField class="NameTextField" label="Name" text="ASMDEF_NAME_HERE"/>
<engine:TextField label="Root Namespace" text="ROOT_NAMESPACE_HERE" class="RootNamespaceTextField" />
<engine:Button class="RenameButton" text="Rename" /> <engine:Button class="RenameButton" text="Rename" />
</engine:Box> </engine:Box>
</engine:UXML> </engine:UXML>