Skip to content

Commit 99eb639

Browse files
committed
[更新]1. 更新UI代码
1 parent 3e57d33 commit 99eb639

File tree

11 files changed

+243
-89
lines changed

11 files changed

+243
-89
lines changed

Assets/Bundles/UI/UILogin/UILogin_atlas0.png.meta

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Hotfix/UI/FairyGUI/UILogin/Components/UIAnnouncement.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using Cysharp.Threading.Tasks;
55
using FairyGUI.Utils;
66
using GameFrameX.Entity.Runtime;
7+
using GameFrameX.UI.Runtime;
78
using GameFrameX.UI.FairyGUI.Runtime;
89
using GameFrameX.Runtime;
10+
using UnityEngine;
911

1012
namespace Hotfix.UI
1113
{
@@ -34,24 +36,27 @@ private static void CreateGObjectAsync(UIPackage.CreateObjectCallback result)
3436
UIPackage.CreateObjectAsync(UIPackageName, UIResName, result);
3537
}
3638

37-
public static UIAnnouncement CreateInstance(object userData = null)
39+
public static UIAnnouncement CreateInstance()
3840
{
39-
return new UIAnnouncement(CreateGObject(), userData);
41+
return Create(CreateGObject());
4042
}
4143

42-
public static UniTask<UIAnnouncement> CreateInstanceAsync(Entity domain, object userData = null)
44+
public static UniTask<UIAnnouncement> CreateInstanceAsync(Entity domain)
4345
{
4446
UniTaskCompletionSource<UIAnnouncement> tcs = new UniTaskCompletionSource<UIAnnouncement>();
4547
CreateGObjectAsync((go) =>
4648
{
47-
tcs.TrySetResult(new UIAnnouncement(go, userData));
49+
tcs.TrySetResult(Create(go));
4850
});
4951
return tcs.Task;
5052
}
5153

52-
public static UIAnnouncement Create(GObject go, object userData = null)
54+
public static UIAnnouncement Create(GObject go)
5355
{
54-
return new UIAnnouncement(go, userData);
56+
var fui = go.displayObject.gameObject.GetOrAddComponent<UIAnnouncement>();
57+
fui?.SetGObject(go);
58+
fui?.InitView();
59+
return fui;
5560
}
5661

5762
/// <summary>
@@ -82,7 +87,7 @@ protected override void InitView()
8287
if(com != null)
8388
{
8489
m_MaskLayer = (GGraph)com.GetChild("MaskLayer");
85-
m_TextContent = UIAnnouncementContent.Create(com.GetChild("TextContent"), this);
90+
m_TextContent = UIAnnouncementContent.Create(com.GetChild("TextContent"));
8691
m_TextTitle = (GTextField)com.GetChild("TextTitle");
8792
}
8893
}
@@ -102,7 +107,7 @@ public override void Dispose()
102107
self = null;
103108
}
104109

105-
private UIAnnouncement(GObject gObject, object userData) : base(gObject, userData)
110+
private UIAnnouncement(GObject gObject) : base(gObject)
106111
{
107112
// Awake(gObject);
108113
}

Assets/Hotfix/UI/FairyGUI/UILogin/Components/UIAnnouncementContent.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using Cysharp.Threading.Tasks;
55
using FairyGUI.Utils;
66
using GameFrameX.Entity.Runtime;
7+
using GameFrameX.UI.Runtime;
78
using GameFrameX.UI.FairyGUI.Runtime;
89
using GameFrameX.Runtime;
10+
using UnityEngine;
911

1012
namespace Hotfix.UI
1113
{
@@ -23,9 +25,12 @@ public sealed partial class UIAnnouncementContent : FUI
2325
public GRichTextField m_LabelContent { get; private set; }
2426

2527

26-
public static UIAnnouncementContent Create(GObject go, object userData = null)
28+
public static UIAnnouncementContent Create(GObject go)
2729
{
28-
return new UIAnnouncementContent(go, userData);
30+
var fui = go.displayObject.gameObject.GetOrAddComponent<UIAnnouncementContent>();
31+
fui?.SetGObject(go);
32+
fui?.InitView();
33+
return fui;
2934
}
3035

3136
/// <summary>
@@ -72,7 +77,7 @@ public override void Dispose()
7277
self = null;
7378
}
7479

75-
private UIAnnouncementContent(GObject gObject, object userData) : base(gObject, userData)
80+
private UIAnnouncementContent(GObject gObject) : base(gObject)
7681
{
7782
// Awake(gObject);
7883
}

Assets/Hotfix/UI/FairyGUI/UILogin/Components/UILogin.cs

Lines changed: 62 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using Cysharp.Threading.Tasks;
55
using FairyGUI.Utils;
66
using GameFrameX.Entity.Runtime;
7+
using GameFrameX.UI.Runtime;
78
using GameFrameX.UI.FairyGUI.Runtime;
89
using GameFrameX.Runtime;
9-
using GameFrameX.UI.UGUI.Runtime;
1010
using UnityEngine;
1111

1212
namespace Hotfix.UI
@@ -22,31 +22,75 @@ public sealed partial class UILogin : FUI
2222
/// </summary>
2323
public GComponent self { get; private set; }
2424

25-
public GTextField m_ErrorText { get; private set; }
26-
public GButton m_enter { get; private set; }
27-
public GTextInput m_UserName { get; private set; }
28-
public GTextInput m_Password { get; private set; }
25+
public GTextField m_ErrorText { get; private set; }
26+
public GButton m_enter { get; private set; }
27+
public GTextInput m_UserName { get; private set; }
28+
public GTextInput m_Password { get; private set; }
2929

3030
private static GObject CreateGObject()
3131
{
3232
return UIPackage.CreateObject(UIPackageName, UIResName);
3333
}
3434

35+
private static void CreateGObjectAsync(UIPackage.CreateObjectCallback result)
36+
{
37+
UIPackage.CreateObjectAsync(UIPackageName, UIResName, result);
38+
}
39+
40+
public static UILogin CreateInstance()
41+
{
42+
return Create(CreateGObject());
43+
}
44+
45+
public static UniTask<UILogin> CreateInstanceAsync(Entity domain)
46+
{
47+
UniTaskCompletionSource<UILogin> tcs = new UniTaskCompletionSource<UILogin>();
48+
CreateGObjectAsync((go) =>
49+
{
50+
tcs.TrySetResult(Create(go));
51+
});
52+
return tcs.Task;
53+
}
54+
55+
public static UILogin Create(GObject go)
56+
{
57+
var fui = go.displayObject.gameObject.GetOrAddComponent<UILogin>();
58+
fui?.SetGObject(go);
59+
fui?.InitView();
60+
return fui;
61+
}
62+
63+
/// <summary>
64+
/// 通过此方法获取的FUI,在Dispose时不会释放GObject,需要自行管理(一般在配合FGUI的Pool机制时使用)。
65+
/// </summary>
66+
public static UILogin GetFormPool(GObject go)
67+
{
68+
var fui = go.Get<UILogin>();
69+
if(fui == null)
70+
{
71+
fui = Create(go);
72+
}
73+
fui.IsFromPool = true;
74+
return fui;
75+
}
3576

3677
protected override void InitView()
3778
{
38-
if (gameObject == null)
79+
if(GObject == null)
3980
{
4081
return;
4182
}
4283

84+
self = (GComponent)GObject;
85+
self.Add(this);
86+
4387
var com = GObject.asCom;
44-
if (com != null)
88+
if(com != null)
4589
{
46-
m_ErrorText = (GTextField)com.GetChild("ErrorText");
47-
m_enter = (GButton)com.GetChild("enter");
48-
m_UserName = (GTextInput)com.GetChild("UserName");
49-
m_Password = (GTextInput)com.GetChild("Password");
90+
m_ErrorText = (GTextField)com.GetChild("ErrorText");
91+
m_enter = (GButton)com.GetChild("enter");
92+
m_UserName = (GTextInput)com.GetChild("UserName");
93+
m_Password = (GTextInput)com.GetChild("Password");
5094
}
5195
}
5296

@@ -59,16 +103,16 @@ public override void Dispose()
59103

60104
base.Dispose();
61105
self.Remove();
62-
m_ErrorText = null;
63-
m_enter = null;
64-
m_UserName = null;
65-
m_Password = null;
66-
self = null;
106+
m_ErrorText = null;
107+
m_enter = null;
108+
m_UserName = null;
109+
m_Password = null;
110+
self = null;
67111
}
68112

69-
70-
public UILogin(GObject gObject, object userData = null, bool isRoot = false) : base(gObject, userData, isRoot)
113+
private UILogin(GObject gObject) : base(gObject)
71114
{
115+
// Awake(gObject);
72116
}
73117
}
74118
}

Assets/Hotfix/UI/FairyGUI/UILogin/Components/UIPlayerCreate.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using Cysharp.Threading.Tasks;
55
using FairyGUI.Utils;
66
using GameFrameX.Entity.Runtime;
7+
using GameFrameX.UI.Runtime;
78
using GameFrameX.UI.FairyGUI.Runtime;
89
using GameFrameX.Runtime;
10+
using UnityEngine;
911

1012
namespace Hotfix.UI
1113
{
@@ -34,24 +36,27 @@ private static void CreateGObjectAsync(UIPackage.CreateObjectCallback result)
3436
UIPackage.CreateObjectAsync(UIPackageName, UIResName, result);
3537
}
3638

37-
public static UIPlayerCreate CreateInstance(object userData = null)
39+
public static UIPlayerCreate CreateInstance()
3840
{
39-
return new UIPlayerCreate(CreateGObject(), userData);
41+
return Create(CreateGObject());
4042
}
4143

42-
public static UniTask<UIPlayerCreate> CreateInstanceAsync(Entity domain, object userData = null)
44+
public static UniTask<UIPlayerCreate> CreateInstanceAsync(Entity domain)
4345
{
4446
UniTaskCompletionSource<UIPlayerCreate> tcs = new UniTaskCompletionSource<UIPlayerCreate>();
4547
CreateGObjectAsync((go) =>
4648
{
47-
tcs.TrySetResult(new UIPlayerCreate(go, userData));
49+
tcs.TrySetResult(Create(go));
4850
});
4951
return tcs.Task;
5052
}
5153

52-
public static UIPlayerCreate Create(GObject go, object userData = null)
54+
public static UIPlayerCreate Create(GObject go)
5355
{
54-
return new UIPlayerCreate(go, userData);
56+
var fui = go.displayObject.gameObject.GetOrAddComponent<UIPlayerCreate>();
57+
fui?.SetGObject(go);
58+
fui?.InitView();
59+
return fui;
5560
}
5661

5762
/// <summary>
@@ -102,7 +107,7 @@ public override void Dispose()
102107
self = null;
103108
}
104109

105-
private UIPlayerCreate(GObject gObject, object userData) : base(gObject, userData)
110+
private UIPlayerCreate(GObject gObject) : base(gObject)
106111
{
107112
// Awake(gObject);
108113
}

Assets/Hotfix/UI/FairyGUI/UILogin/Components/UIPlayerList.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using Cysharp.Threading.Tasks;
55
using FairyGUI.Utils;
66
using GameFrameX.Entity.Runtime;
7+
using GameFrameX.UI.Runtime;
78
using GameFrameX.UI.FairyGUI.Runtime;
89
using GameFrameX.Runtime;
10+
using UnityEngine;
911

1012
namespace Hotfix.UI
1113
{
@@ -37,24 +39,27 @@ private static void CreateGObjectAsync(UIPackage.CreateObjectCallback result)
3739
UIPackage.CreateObjectAsync(UIPackageName, UIResName, result);
3840
}
3941

40-
public static UIPlayerList CreateInstance(object userData = null)
42+
public static UIPlayerList CreateInstance()
4143
{
42-
return new UIPlayerList(CreateGObject(), userData);
44+
return Create(CreateGObject());
4345
}
4446

45-
public static UniTask<UIPlayerList> CreateInstanceAsync(Entity domain, object userData = null)
47+
public static UniTask<UIPlayerList> CreateInstanceAsync(Entity domain)
4648
{
4749
UniTaskCompletionSource<UIPlayerList> tcs = new UniTaskCompletionSource<UIPlayerList>();
4850
CreateGObjectAsync((go) =>
4951
{
50-
tcs.TrySetResult(new UIPlayerList(go, userData));
52+
tcs.TrySetResult(Create(go));
5153
});
5254
return tcs.Task;
5355
}
5456

55-
public static UIPlayerList Create(GObject go, object userData = null)
57+
public static UIPlayerList Create(GObject go)
5658
{
57-
return new UIPlayerList(go, userData);
59+
var fui = go.displayObject.gameObject.GetOrAddComponent<UIPlayerList>();
60+
fui?.SetGObject(go);
61+
fui?.InitView();
62+
return fui;
5863
}
5964

6065
/// <summary>
@@ -111,7 +116,7 @@ public override void Dispose()
111116
self = null;
112117
}
113118

114-
private UIPlayerList(GObject gObject, object userData) : base(gObject, userData)
119+
private UIPlayerList(GObject gObject) : base(gObject)
115120
{
116121
// Awake(gObject);
117122
}

0 commit comments

Comments
 (0)