diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs index fbae904..fc17fff 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/NodeMonitor.cs @@ -81,7 +81,7 @@ catch (Exception e) { //检查节点存在报错, 直接跳过该节点的检查 - GD.PrintErr(e.ToString()); + GD.Print(e.Message); } } @@ -117,7 +117,7 @@ catch (Exception e) { //检查节点存在报错, 直接跳过该节点的检查 - GD.PrintErr(e.ToString()); + GD.Print(e.Message); _targetNode = null; } _checkTreeTimer = 0; diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs index d1ad903..3076015 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs @@ -250,10 +250,13 @@ /// private void OnSceneChanged(Node node) { - _uiMonitor.ChangeCurrentNode(null); - if (CheckIsUi(node)) + if (_uiMonitor != null) { - _uiMonitor.ChangeCurrentNode(node); + _uiMonitor.ChangeCurrentNode(null); + if (CheckIsUi(node)) + { + _uiMonitor.ChangeCurrentNode(node); + } } } diff --git a/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs b/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs index 4f8a2a1..723feec 100644 --- a/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs +++ b/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs @@ -14,7 +14,10 @@ { private static Dictionary _nodeNameMap = new Dictionary(); - public static bool CreateUi(string uiName) + /// + /// 根据名称在编辑器中创建Ui, open 表示创建完成后是否在编辑器中打开这个ui + /// + public static bool CreateUi(string uiName, bool open = false) { try { @@ -32,7 +35,7 @@ $" {{\n" + $" \n" + $" }}\n" + - $"" + + $"\n" + $" public override void OnHideUi()\n" + $" {{\n" + $" \n" + @@ -50,6 +53,7 @@ //创建场景资源 var prefabFile = GameConfig.UiPrefabDir + uiName + ".tscn"; + var prefabResPath = "res://" + prefabFile; if (!Directory.Exists(GameConfig.UiPrefabDir)) { Directory.CreateDirectory(GameConfig.UiPrefabDir); @@ -60,10 +64,17 @@ uiNode.SetScript(scriptRes); var scene = new PackedScene(); scene.Pack(uiNode); - ResourceSaver.Save(scene, "res://" + prefabFile); + ResourceSaver.Save(scene, prefabResPath); //生成Ui结构代码 GenerateUiCode(uiNode, scriptPath + "/" + uiName + ".cs"); + +#if TOOLS + if (open) + { + Plugin.Plugin.Instance.GetEditorInterface().OpenSceneFromPath(prefabResPath); + } +#endif } catch (Exception e) { diff --git a/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs b/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs index a9d99b4..249c78a 100644 --- a/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs +++ b/DungeonShooting_Godot/src/game/ui/editorTools/EditorToolsPanel.cs @@ -205,28 +205,28 @@ /// private void OnCreateUI() { - var text = L_ScrollContainer.L_MarginContainer.L_VBoxContainer.L_HBoxContainer3.L_LineEdit.Instance.Text; - ShowConfirm("提示", "是否创建UI:" + text, (result) => + var uiName = L_ScrollContainer.L_MarginContainer.L_VBoxContainer.L_HBoxContainer3.L_LineEdit.Instance.Text; + ShowConfirm("提示", "是否创建UI:" + uiName, (result) => { if (result) { //检查名称是否合规 - if (!Regex.IsMatch(text, "^[A-Z][a-zA-Z0-9]*$")) + if (!Regex.IsMatch(uiName, "^[A-Z][a-zA-Z0-9]*$")) { - ShowTips("错误", "UI名称'" + text + "'不符合名称约束, UI名称只允许大写字母开头, 且名称中只允许出现大小字母和数字!"); + ShowTips("错误", "UI名称'" + uiName + "'不符合名称约束, UI名称只允许大写字母开头, 且名称中只允许出现大小字母和数字!"); return; } //检查是否有同名的Ui - var path = GameConfig.UiCodeDir + text.FirstToLower(); + var path = GameConfig.UiCodeDir + uiName.FirstToLower(); if (Directory.Exists(path)) { - ShowTips("错误", "已经存在相同名称'" + text + "'的UI了, 不能重复创建!"); + ShowTips("错误", "已经存在相同名称'" + uiName + "'的UI了, 不能重复创建!"); return; } //执行创建操作 - if (UiGenerator.CreateUi(text)) + if (UiGenerator.CreateUi(uiName, true)) { ShowTips("提示", "创建UI成功!"); }