This commit is contained in:
2025-08-07 09:17:13 +08:00
parent 246ab02390
commit abb211e0da
24 changed files with 492 additions and 8486 deletions

View File

@@ -18,6 +18,7 @@ namespace NBF
UIObjectFactory.SetPackageItemExtension(HomeRankPage.URL, typeof(HomeRankPage));
UIObjectFactory.SetPackageItemExtension(HomeStatisticsPage.URL, typeof(HomeStatisticsPage));
UIObjectFactory.SetPackageItemExtension(HomeButtonGroups.URL, typeof(HomeButtonGroups));
UIObjectFactory.SetPackageItemExtension(ChatItem.URL, typeof(ChatItem));
}
}
}

29
Assets/Scripts/UI/ChatItem.Designer.cs generated Normal file
View File

@@ -0,0 +1,29 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
namespace NBF
{
public partial class ChatItem
{
public const string URL = "ui://hxr7rc7pn5ne1f";
public GTextField TextType;
public GTextField TextUser;
public GTextField TextMessage;
public override void ConstructFromXML(XML xml)
{
base.ConstructFromXML(xml);
TextType = (GTextField)GetChild("TextType");
TextUser = (GTextField)GetChild("TextUser");
TextMessage = (GTextField)GetChild("TextMessage");
OnInited();
UILanguage.TrySetComponentLanguage(this);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8383cf682d2c39f41bc83ea027894ec6

View File

@@ -0,0 +1,15 @@
// 本脚本只在不存在时会生成一次。组件逻辑写在当前脚本内。已存在不会再次生成覆盖
using UnityEngine;
using FairyGUI;
using NBC;
namespace NBF
{
public partial class ChatItem : GComponent
{
private void OnInited()
{
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e369e839256e8464fbdd0922424f36e3

View File

@@ -0,0 +1,46 @@
/**本脚本为自动生成每次生成会覆盖请勿手动修改生成插件文档及项目地址https://git.whoot.com/whoot-games/whoot.fguieditorplugin**/
using FairyGUI;
using FairyGUI.Utils;
using NBC;
using System.Collections.Generic;
namespace NBF
{
/// <summary> </summary>
public partial class ChatTestPanel
{
public GObject this[string aKey] => ContentPane.GetChild(aKey);
public override string UIPackName => "Main";
public override string UIResName => "ChatTestPanel";
[AutoFind(Name = "back")]
public GImage back;
[AutoFind(Name = "TextLoginInfo")]
public GTextField TextLoginInfo;
[AutoFind(Name = "InputAccount")]
public GLabel InputAccount;
[AutoFind(Name = "BtnLogout")]
public GButton BtnLogout;
[AutoFind(Name = "BtnLogin")]
public GButton BtnLogin;
[AutoFind(Name = "InputMessage")]
public GLabel InputMessage;
[AutoFind(Name = "BtnSendMessage")]
public GButton BtnSendMessage;
[AutoFind(Name = "BtnSendFriend")]
public GButton BtnSendFriend;
[AutoFind(Name = "BtnSendWorld")]
public GButton BtnSendWorld;
[AutoFind(Name = "ChatList")]
public GList ChatList;
public override string[] GetDependPackages(){ return new string[] {"Common"}; }
public static void Show(object param = null){ App.UI.OpenUI<ChatTestPanel>(param); }
public static void Hide(){ App.UI.HideUI<ChatTestPanel>(); }
public static void Del(){ App.UI.DestroyUI<ChatTestPanel>(); }
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: c9910a4bd1e1d3b4a8c580bcc2cc34e7

View File

@@ -0,0 +1,137 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using Assets.Scripts.Entity;
using Assets.Scripts.Hotfix;
using FairyGUI;
using UnityEngine;
using NBC;
using NBC.Network;
using UIPanel = NBC.UIPanel;
namespace NBF
{
public partial class ChatTestPanel : UIPanel
{
protected override void OnInit()
{
this.AutoAddClick(OnClick);
}
protected override void OnShow()
{
SetLoginState(false);
}
private void OnClick(GComponent btn)
{
if (btn == BtnLogin)
{
if (string.IsNullOrEmpty(InputAccount.text))
{
Notices.Info("没有输入账号密码");
return;
}
OnLoginButtonClick(InputAccount.text).Coroutine();
}
}
private void SetLoginState(bool isLogin = false, string account = "")
{
if (isLogin)
{
BtnLogin.visible = false;
BtnLogout.visible = true;
TextLoginInfo.text = account;
}
else
{
BtnLogin.visible = true;
BtnLogout.visible = false;
}
}
#region
private Session _session;
private async FTask OnLoginButtonClick(string account)
{
// NBC.Platform.Unity.Entry.Initialize(GetType().Assembly);
// 根据用户名来选择目标的鉴权服务器
// 根据鉴权服务器地址来创建一个新的网络会话
_session = SessionHelper.CreateSession(App.Main, "127.0.0.1:20001", OnConnectComplete,
OnConnectFail,
OnConnectDisconnect);
var acc = account;
// 发送登录的请求给服务器
var response = (A2C_LoginResponse)await _session.Call(new C2A_LoginRequest()
{
Username = acc,
Password = acc,
LoginType = 1
});
if (response.ErrorCode != 0)
{
Log.Error($"登录发生错误{response.ErrorCode}");
return;
}
if (!App.Main.GetComponent<JWTParseComponent>().Parse(response.ToKen, out var payload))
{
return;
}
// 根据ToKen返回的Address登录到Gate服务器
_session = SessionHelper.CreateSession(App.Main, payload.Address, OnConnectComplete, OnConnectFail,
OnConnectDisconnect);
// 发送登录请求到Gate服务器
var loginResponse = (G2C_LoginResponse)await _session.Call(new C2G_LoginRequest()
{
ToKen = response.ToKen
});
if (loginResponse.ErrorCode != 0)
{
Log.Error($"登录发生错误{loginResponse.ErrorCode}");
return;
}
SetLoginState(true, InputAccount.text);
Log.Debug(
$"登录到Gate服务器成功ErrorCode:{loginResponse.ErrorCode}");
// Log.Debug(
// $"登录到Gate服务器成功LoginTime:{loginResponse.GameAccountInfo.LoginTime} CreateTime:{loginResponse.GameAccountInfo.CreateTime}");
// var getResponse = (G2C_GetAccountInfoResponse)await _session.Call(new C2G_GetAccountInfoRequest());
// var gameAcc = getResponse.GameAccountInfo;
// Log.Info($"gameAcc LoginTime:{gameAcc.LoginTime} CreateTime:{gameAcc.CreateTime}");
// getResponse.GameAccountInfo.LoginTime.ToString()
}
private void OnConnectComplete()
{
Log.Debug("连接成功");
// 添加心跳组件给Session。
// Start(2000)就是2000毫秒。
_session.AddComponent<SessionHeartbeatComponent>().Start(5000);
}
private void OnConnectFail()
{
Log.Debug("连接失败");
SetLoginState(false);
}
private void OnConnectDisconnect()
{
Log.Debug("连接断开");
SetLoginState(false);
}
#endregion
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 2f05d713b2557a945b45a81473963207