diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs new file mode 100644 index 0000000..47f8b10 --- /dev/null +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.cs @@ -0,0 +1,89 @@ +#if TOOLS +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using Godot; +using File = System.IO.File; + +[Tool] +public class Automation : Control +{ + //支持后缀 + private string[] suffix = + { + ".png", ".jpg", ".txt", ".json", ".ini", ".tscn", ".tres", ".otf", ".gdshader", ".tmx", ".tsx", ".ogg", ".mp3", ".wav", ".svg" + }; + //排除第一层的文件夹 + private string[] exclude = + { + ".vscode", ".idea", ".git", ".import", ".mono", "android", "addons" + }; + private string currDir = System.Environment.CurrentDirectory; + + private string resultStr = ""; + + //更新 ResourcePath + private void _on_Button_pressed() + { + resultStr = "/// \n" + + "/// 编辑器下所有资源路径, 该类为 Automation 面板下自动生成的, 请不要手动编辑!\n" + + "/// \n" + + "public class ResourcePath\n" + + "{\n"; + //输出路径 + var path = "src/game/manager/ResourcePath1.cs"; + GD.Print("更新 ResourcePath..."); + + var directoryInfo = new DirectoryInfo(currDir); + + var directories = directoryInfo.GetDirectories(); + for (int i = 0; i < directories.Length; i++) + { + var directory = directories[i]; + if (!exclude.Contains(directory.Name)) + { + EachDir(directory); + } + } + + var fileInfos = directoryInfo.GetFiles(); + for (var i = 0; i < fileInfos.Length; i++) + { + HandleFile(fileInfos[i]); + } + + resultStr += "}"; + File.WriteAllText("src/game/manager/ResourcePath.cs", resultStr); + GD.Print("ResourcePath.cs 写出完成!"); + } + + private void EachDir(DirectoryInfo directoryInfos) + { + var fileInfos = directoryInfos.GetFiles(); + for (var i = 0; i < fileInfos.Length; i++) + { + HandleFile(fileInfos[i]); + } + + var directories = directoryInfos.GetDirectories(); + for (var i = 0; i < directories.Length; i++) + { + EachDir(directories[i]); + } + } + + private void HandleFile(FileInfo fileInfo) + { + if (suffix.Contains(fileInfo.Extension)) + { + var field = fileInfo.FullName.Substring(currDir.Length + 1); + field = field.Replace("\\", "/"); + var resPath = "res://" + field; + field = field.Replace(".", "_"); + field = field.Replace("/", "_"); + field = Regex.Replace(field, "[^\\w_]", ""); + resultStr += $" public const string {field} = \"{resPath}\";\n"; + } + } +} +#endif \ No newline at end of file diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.tscn b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.tscn new file mode 100644 index 0000000..3e3a557 --- /dev/null +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Automation.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/dungeonShooting_plugin/Automation.cs" type="Script" id=1] + +[node name="Automation" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) + +[node name="ScrollContainer" type="ScrollContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"] +margin_right = 1920.0 +margin_bottom = 35.0 +size_flags_horizontal = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="ScrollContainer/VBoxContainer"] +margin_right = 1920.0 +margin_bottom = 35.0 + +[node name="Label" type="Label" parent="ScrollContainer/VBoxContainer/HBoxContainer"] +margin_right = 158.0 +margin_bottom = 35.0 +text = "ResourcePath.cs" + +[node name="Button" type="Button" parent="ScrollContainer/VBoxContainer/HBoxContainer"] +margin_left = 162.0 +margin_right = 246.0 +margin_bottom = 35.0 +text = "重新生成" + +[connection signal="pressed" from="ScrollContainer/VBoxContainer/HBoxContainer/Button" to="." method="_on_Button_pressed"] diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs index b8132c8..f56c18f 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/Plugin.cs @@ -9,6 +9,8 @@ public static Plugin Instance => _instance; private static Plugin _instance; + private Control dock; + public override void _Process(float delta) { _instance = this; @@ -20,11 +22,16 @@ var script = GD.Load