diff --git a/DungeonShooting_Godot/src/framework/ui/UiBase.cs b/DungeonShooting_Godot/src/framework/ui/UiBase.cs index 86a7934..d3e50ef 100644 --- a/DungeonShooting_Godot/src/framework/ui/UiBase.cs +++ b/DungeonShooting_Godot/src/framework/ui/UiBase.cs @@ -25,6 +25,13 @@ public bool KeepOut = false; /// + /// 创建当前ui时调用 + /// + public virtual void OnCreate() + { + } + + /// /// 当前ui打开时调用,并接收参数 /// public abstract void OnOpen(params object[] args); @@ -35,13 +42,6 @@ public abstract void OnClose(); /// - /// 创建当前ui时调用 - /// - public virtual void OnCreate() - { - } - - /// /// 销毁当前ui时调用 /// public virtual void OnDispose() diff --git a/DungeonShooting_Godot/src/test/TestUi/Test.cs b/DungeonShooting_Godot/src/test/TestUi/Test.cs index 7f13fc1..0932fcf 100644 --- a/DungeonShooting_Godot/src/test/TestUi/Test.cs +++ b/DungeonShooting_Godot/src/test/TestUi/Test.cs @@ -11,12 +11,29 @@ */ public abstract partial class Test : UiBase { - public UiNode2_c1 c1 { get; private set; } - public UiNode3_c2 c2 { get; private set; } + public UiNode2_c1 c1 + { + get + { + if (_c1 == null) _c1 = new UiNode2_c1(GetNode("c1")); + return _c1; + } + } + public UiNode3_c2 c2 + { + get + { + if (_c2 == null) _c2 = new UiNode3_c2(GetNode("c2")); + return _c2; + } + } + + private UiNode2_c1 _c1; + private UiNode3_c2 _c2; public class UiNode1_c11 { - public Control Instance { get; private set; } + public Control Instance { get; } public UiNode1_c11(Control node) { @@ -31,13 +48,22 @@ public class UiNode2_c1 { - public Control Instance { get; private set; } - public UiNode1_c11 c11 { get; private set; } + public Control Instance { get; } + + public UiNode1_c11 c11 + { + get + { + if (_c11 == null) _c11 = new UiNode1_c11(Instance.GetNode("c11")); + return _c11; + } + } + + private UiNode1_c11 _c11; public UiNode2_c1(Control node) { Instance = node; - c11 = new UiNode1_c11(node.GetNode("c11")); } public UiNode2_c1 Clone() @@ -48,7 +74,7 @@ public class UiNode3_c2 { - public Control Instance { get; private set; } + public Control Instance { get; } public UiNode3_c2(Control node) { @@ -60,10 +86,4 @@ return new UiNode3_c2((Control)Instance.Duplicate()); } } - - public sealed override void _Ready() - { - c1 = new UiNode2_c1(GetNode("c1")); - c2 = new UiNode3_c2(GetNode("c2")); - } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestUi/TestPanel.cs b/DungeonShooting_Godot/src/test/TestUi/TestPanel.cs index 0388b86..58f134e 100644 --- a/DungeonShooting_Godot/src/test/TestUi/TestPanel.cs +++ b/DungeonShooting_Godot/src/test/TestUi/TestPanel.cs @@ -2,7 +2,6 @@ public class TestPanel : Test { - public override void OnOpen(params object[] args) {