diff --git "a/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/gif_4.gif" "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/gif_4.gif" new file mode 100644 index 0000000..a087451 --- /dev/null +++ "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/gif_4.gif" Binary files differ diff --git "a/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_14.png" "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_14.png" new file mode 100644 index 0000000..a5181fc --- /dev/null +++ "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_14.png" Binary files differ diff --git "a/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_15.png" "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_15.png" new file mode 100644 index 0000000..94ad6d2 --- /dev/null +++ "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_15.png" Binary files differ diff --git "a/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_16.png" "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_16.png" new file mode 100644 index 0000000..d87de83 --- /dev/null +++ "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_16.png" Binary files differ diff --git "a/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_17.png" "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_17.png" new file mode 100644 index 0000000..2ec7c41 --- /dev/null +++ "b/DungeonShooting_Document/\346\226\207\346\241\243\350\265\204\346\272\220/image_17.png" Binary files differ diff --git "a/DungeonShooting_Document/\351\241\271\347\233\256\345\270\256\345\212\251\346\226\207\346\241\243.md" "b/DungeonShooting_Document/\351\241\271\347\233\256\345\270\256\345\212\251\346\226\207\346\241\243.md" index d5fb6d0..cce63f7 100644 --- "a/DungeonShooting_Document/\351\241\271\347\233\256\345\270\256\345\212\251\346\226\207\346\241\243.md" +++ "b/DungeonShooting_Document/\351\241\271\347\233\256\345\270\256\345\212\251\346\226\207\346\241\243.md" @@ -382,7 +382,14 @@ ##### 创建UI 在`Tools`页签下找到`创建游戏UI`, 输入UI名称即可点击创建UI +![](文档资源/image_14.png) +创建完毕后编辑器会离开打开该UI场景 +观察文件系统可以注意到, 编辑器为我创建并保存了场景和代码, 并且还生成了一个`MyUiPanel.cs`的文件, 该文件就是我们写UI逻辑代码的地方, 并且命名方式为`UI名称`+`Panel`, 这个Panel类继承了自动生成出来的UI类 +![](文档资源/image_15.png) +![](文档资源/image_16.png) +创建完成UI后, 编辑器也会在`UiManager`中生成打开该UI和获取UI实例的Api +![](文档资源/image_17.png) +通过以下这个gif就可以直观感受到该功能的便捷之处 +![](文档资源/gif_4.gif) -创建完毕后会离开打开该UI场景 - -#### 3.4.3.常用功能 \ No newline at end of file +#### 3.4.3.常用功能 diff --git a/DungeonShooting_Godot/prefab/ui/MyUi.tscn b/DungeonShooting_Godot/prefab/ui/MyUi.tscn new file mode 100644 index 0000000..70df7ba --- /dev/null +++ b/DungeonShooting_Godot/prefab/ui/MyUi.tscn @@ -0,0 +1,10 @@ +[gd_scene load_steps=2 format=3 uid="uid://buxit3x615xu3"] + +[ext_resource type="Script" path="res://src/game/ui/myUi/MyUiPanel.cs" id="1_bhjxh"] + +[node name="MyUi" type="Control"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource("1_bhjxh") diff --git a/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs b/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs index 23c24a8..7f7e6fa 100644 --- a/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs +++ b/DungeonShooting_Godot/src/framework/generator/UiGenerator.cs @@ -31,7 +31,7 @@ $"public partial class {uiName}Panel : {uiName}\n" + $"{{\n" + $"\n" + - $" public override void OnShowUi(params object[] args)\n" + + $" public override void OnShowUi()\n" + $" {{\n" + $" \n" + $" }}\n" + diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs index ba1e64c..415bfb9 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -17,6 +17,7 @@ public const string prefab_test_MoveComponent_tscn = "res://prefab/test/MoveComponent.tscn"; public const string prefab_test_TestActivity_tscn = "res://prefab/test/TestActivity.tscn"; public const string prefab_ui_EditorTools_tscn = "res://prefab/ui/EditorTools.tscn"; + public const string prefab_ui_MyUi_tscn = "res://prefab/ui/MyUi.tscn"; public const string prefab_ui_RoomUI_tscn = "res://prefab/ui/RoomUI.tscn"; public const string prefab_weapon_Knife_tscn = "res://prefab/weapon/Knife.tscn"; public const string prefab_weapon_Weapon_tscn = "res://prefab/weapon/Weapon.tscn"; @@ -37,9 +38,15 @@ public const string resource_map_tiledata_Room1_json = "res://resource/map/tiledata/Room1.json"; public const string resource_map_tiledata_Room2_json = "res://resource/map/tiledata/Room2.json"; public const string resource_map_tiledata_Room3_json = "res://resource/map/tiledata/Room3.json"; + public const string resource_map_tiledata_Room4_json = "res://resource/map/tiledata/Room4.json"; + public const string resource_map_tiledata_Room5_json = "res://resource/map/tiledata/Room5.json"; + public const string resource_map_tiledata_Room6_json = "res://resource/map/tiledata/Room6.json"; public const string resource_map_tileMaps_Room1_tscn = "res://resource/map/tileMaps/Room1.tscn"; public const string resource_map_tileMaps_Room2_tscn = "res://resource/map/tileMaps/Room2.tscn"; public const string resource_map_tileMaps_Room3_tscn = "res://resource/map/tileMaps/Room3.tscn"; + public const string resource_map_tileMaps_Room4_tscn = "res://resource/map/tileMaps/Room4.tscn"; + public const string resource_map_tileMaps_Room5_tscn = "res://resource/map/tileMaps/Room5.tscn"; + public const string resource_map_tileMaps_Room6_tscn = "res://resource/map/tileMaps/Room6.tscn"; public const string resource_map_tileset_TileSet1_tres = "res://resource/map/tileset/TileSet1.tres"; public const string resource_materlal_Blend_gdshader = "res://resource/materlal/Blend.gdshader"; public const string resource_materlal_Blend_tres = "res://resource/materlal/Blend.tres"; diff --git a/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs b/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs index 91aaa92..f6fa6c3 100644 --- a/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs +++ b/DungeonShooting_Godot/src/game/manager/UiManager_Methods.cs @@ -7,6 +7,7 @@ public static class UiName { public const string EditorTools = "EditorTools"; + public const string MyUi = "MyUi"; public const string RoomUI = "RoomUI"; } @@ -27,6 +28,22 @@ } /// + /// 打开 MyUi, 并返回UI实例 + /// + public static UI.MyUi.MyUiPanel Open_MyUi() + { + return OpenUi(UiName.MyUi); + } + + /// + /// 获取所有 MyUi 的实例, 如果没有实例, 则返回一个空数组 + /// + public static UI.MyUi.MyUiPanel[] Get_MyUi_Instance() + { + return GetUiInstance(nameof(UI.MyUi.MyUi)); + } + + /// /// 打开 RoomUI, 并返回UI实例 /// public static UI.RoomUI.RoomUIPanel Open_RoomUI() diff --git a/DungeonShooting_Godot/src/game/ui/myUi/MyUi.cs b/DungeonShooting_Godot/src/game/ui/myUi/MyUi.cs new file mode 100644 index 0000000..65f9437 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/myUi/MyUi.cs @@ -0,0 +1,79 @@ +namespace UI.MyUi; + +/// +/// Ui代码, 该类是根据ui场景自动生成的, 请不要手动编辑该类, 以免造成代码丢失 +/// +public abstract partial class MyUi : UiBase +{ + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MyUi.Button + /// + public UiNode_Button L_Button + { + get + { + if (_L_Button == null) _L_Button = new UiNode_Button(GetNodeOrNull("Button")); + return _L_Button; + } + } + private UiNode_Button _L_Button; + + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MyUi.Control + /// + public UiNode_Control L_Control + { + get + { + if (_L_Control == null) _L_Control = new UiNode_Control(GetNodeOrNull("Control")); + return _L_Control; + } + } + private UiNode_Control _L_Control; + + + public MyUi() : base(nameof(MyUi)) + { + } + + /// + /// 类型: , 路径: MyUi.Button + /// + public class UiNode_Button : IUiNode + { + public UiNode_Button(Godot.Button node) : base(node) { } + public override UiNode_Button Clone() => new ((Godot.Button)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: MyUi.Control.Label + /// + public class UiNode_Label : IUiNode + { + public UiNode_Label(Godot.Label node) : base(node) { } + public override UiNode_Label Clone() => new ((Godot.Label)Instance.Duplicate()); + } + + /// + /// 类型: , 路径: MyUi.Control + /// + public class UiNode_Control : IUiNode + { + /// + /// 使用 Instance 属性获取当前节点实例对象, 节点类型: , 节点路径: MyUi.Label + /// + public UiNode_Label L_Label + { + get + { + if (_L_Label == null) _L_Label = new UiNode_Label(Instance.GetNodeOrNull("Label")); + return _L_Label; + } + } + private UiNode_Label _L_Label; + + public UiNode_Control(Godot.Control node) : base(node) { } + public override UiNode_Control Clone() => new ((Godot.Control)Instance.Duplicate()); + } + +} diff --git a/DungeonShooting_Godot/src/game/ui/myUi/MyUiPanel.cs b/DungeonShooting_Godot/src/game/ui/myUi/MyUiPanel.cs new file mode 100644 index 0000000..f6d0a04 --- /dev/null +++ b/DungeonShooting_Godot/src/game/ui/myUi/MyUiPanel.cs @@ -0,0 +1,22 @@ +using Godot; + +namespace UI.MyUi; + +public partial class MyUiPanel : MyUi +{ + + public override void OnShowUi() + { + L_Control.L_Label.Instance.Text = "文本"; + L_Button.Instance.Pressed += () => + { + + }; + } + + public override void OnHideUi() + { + + } + +}