更新文档
This commit is contained in:
parent
3eae4011b7
commit
078ae04749
BIN
DungeonShooting_Document/文档资源/gif_4.gif
Normal file
BIN
DungeonShooting_Document/文档资源/gif_4.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.6 MiB |
BIN
DungeonShooting_Document/文档资源/image_14.png
Normal file
BIN
DungeonShooting_Document/文档资源/image_14.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
DungeonShooting_Document/文档资源/image_15.png
Normal file
BIN
DungeonShooting_Document/文档资源/image_15.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
BIN
DungeonShooting_Document/文档资源/image_16.png
Normal file
BIN
DungeonShooting_Document/文档资源/image_16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
BIN
DungeonShooting_Document/文档资源/image_17.png
Normal file
BIN
DungeonShooting_Document/文档资源/image_17.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
|
@ -382,7 +382,14 @@ UiManager.DisposeUi(ui);
|
|||
|
||||
##### 创建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.常用功能
|
||||
#### 3.4.3.常用功能
|
||||
|
|
10
DungeonShooting_Godot/prefab/ui/MyUi.tscn
Normal file
10
DungeonShooting_Godot/prefab/ui/MyUi.tscn
Normal file
|
@ -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")
|
|
@ -31,7 +31,7 @@ public static class UiGenerator
|
|||
$"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" +
|
||||
|
|
|
@ -17,6 +17,7 @@ public class ResourcePath
|
|||
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 class ResourcePath
|
|||
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";
|
||||
|
|
|
@ -7,6 +7,7 @@ public static partial class UiManager
|
|||
public static class UiName
|
||||
{
|
||||
public const string EditorTools = "EditorTools";
|
||||
public const string MyUi = "MyUi";
|
||||
public const string RoomUI = "RoomUI";
|
||||
}
|
||||
|
||||
|
@ -26,6 +27,22 @@ public static partial class UiManager
|
|||
return GetUiInstance<UI.EditorTools.EditorToolsPanel>(nameof(UI.EditorTools.EditorTools));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 MyUi, 并返回UI实例
|
||||
/// </summary>
|
||||
public static UI.MyUi.MyUiPanel Open_MyUi()
|
||||
{
|
||||
return OpenUi<UI.MyUi.MyUiPanel>(UiName.MyUi);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有 MyUi 的实例, 如果没有实例, 则返回一个空数组
|
||||
/// </summary>
|
||||
public static UI.MyUi.MyUiPanel[] Get_MyUi_Instance()
|
||||
{
|
||||
return GetUiInstance<UI.MyUi.MyUiPanel>(nameof(UI.MyUi.MyUi));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开 RoomUI, 并返回UI实例
|
||||
/// </summary>
|
||||
|
|
79
DungeonShooting_Godot/src/game/ui/myUi/MyUi.cs
Normal file
79
DungeonShooting_Godot/src/game/ui/myUi/MyUi.cs
Normal file
|
@ -0,0 +1,79 @@
|
|||
namespace UI.MyUi;
|
||||
|
||||
/// <summary>
|
||||
/// Ui代码, 该类是根据ui场景自动生成的, 请不要手动编辑该类, 以免造成代码丢失
|
||||
/// </summary>
|
||||
public abstract partial class MyUi : UiBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用 Instance 属性获取当前节点实例对象, 节点类型: <see cref="Godot.Button"/>, 节点路径: MyUi.Button
|
||||
/// </summary>
|
||||
public UiNode_Button L_Button
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_L_Button == null) _L_Button = new UiNode_Button(GetNodeOrNull<Godot.Button>("Button"));
|
||||
return _L_Button;
|
||||
}
|
||||
}
|
||||
private UiNode_Button _L_Button;
|
||||
|
||||
/// <summary>
|
||||
/// 使用 Instance 属性获取当前节点实例对象, 节点类型: <see cref="Godot.Control"/>, 节点路径: MyUi.Control
|
||||
/// </summary>
|
||||
public UiNode_Control L_Control
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_L_Control == null) _L_Control = new UiNode_Control(GetNodeOrNull<Godot.Control>("Control"));
|
||||
return _L_Control;
|
||||
}
|
||||
}
|
||||
private UiNode_Control _L_Control;
|
||||
|
||||
|
||||
public MyUi() : base(nameof(MyUi))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 类型: <see cref="Godot.Button"/>, 路径: MyUi.Button
|
||||
/// </summary>
|
||||
public class UiNode_Button : IUiNode<Godot.Button, UiNode_Button>
|
||||
{
|
||||
public UiNode_Button(Godot.Button node) : base(node) { }
|
||||
public override UiNode_Button Clone() => new ((Godot.Button)Instance.Duplicate());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 类型: <see cref="Godot.Label"/>, 路径: MyUi.Control.Label
|
||||
/// </summary>
|
||||
public class UiNode_Label : IUiNode<Godot.Label, UiNode_Label>
|
||||
{
|
||||
public UiNode_Label(Godot.Label node) : base(node) { }
|
||||
public override UiNode_Label Clone() => new ((Godot.Label)Instance.Duplicate());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 类型: <see cref="Godot.Control"/>, 路径: MyUi.Control
|
||||
/// </summary>
|
||||
public class UiNode_Control : IUiNode<Godot.Control, UiNode_Control>
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用 Instance 属性获取当前节点实例对象, 节点类型: <see cref="Godot.Label"/>, 节点路径: MyUi.Label
|
||||
/// </summary>
|
||||
public UiNode_Label L_Label
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_L_Label == null) _L_Label = new UiNode_Label(Instance.GetNodeOrNull<Godot.Label>("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());
|
||||
}
|
||||
|
||||
}
|
22
DungeonShooting_Godot/src/game/ui/myUi/MyUiPanel.cs
Normal file
22
DungeonShooting_Godot/src/game/ui/myUi/MyUiPanel.cs
Normal file
|
@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user