登录和输入控件
This commit is contained in:
75
Assets/Scripts/Net/Net.cs
Normal file
75
Assets/Scripts/Net/Net.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using Assets.Scripts.Entity;
|
||||
using Assets.Scripts.Hotfix;
|
||||
using NBC;
|
||||
using NBC.Network;
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Net : EventDispatcher
|
||||
{
|
||||
public static Session Session { get; private set; }
|
||||
|
||||
public const int HeartbeatInterval = 5000;
|
||||
|
||||
#region 单例
|
||||
|
||||
private static Net _inst;
|
||||
|
||||
public static Net Inst => _inst ??= new Net();
|
||||
|
||||
public Net()
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 连接创建和回调
|
||||
|
||||
public static Session CreateSession(string address)
|
||||
{
|
||||
var session = SessionHelper.CreateSession(App.Main, address, OnConnectComplete,
|
||||
OnConnectFail,
|
||||
OnConnectDisconnect);
|
||||
|
||||
Session = session;
|
||||
return session;
|
||||
}
|
||||
|
||||
private static void OnConnectComplete()
|
||||
{
|
||||
Log.Debug("连接成功");
|
||||
Session.AddComponent<SessionHeartbeatComponent>().Start(HeartbeatInterval);
|
||||
}
|
||||
|
||||
private static void OnConnectFail()
|
||||
{
|
||||
Log.Debug("连接失败");
|
||||
// SetLoginState(false);
|
||||
}
|
||||
|
||||
private static void OnConnectDisconnect()
|
||||
{
|
||||
Log.Debug("连接断开");
|
||||
// SetLoginState(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 消息收发
|
||||
|
||||
public static FTask<IResponse> Call(IRequest request, long routeId = 0)
|
||||
{
|
||||
// var response = await Session.Call(request, routeId);
|
||||
// response.DispatchMessage();
|
||||
return Session.Call(request, routeId);;
|
||||
}
|
||||
|
||||
public static void Send(IMessage message, uint rpcId = 0, long routeId = 0)
|
||||
{
|
||||
Session.Send(message, rpcId, routeId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Net/Net.cs.meta
Normal file
3
Assets/Scripts/Net/Net.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1fe56eeffd614eaea7055d1c65f6859f
|
||||
timeCreated: 1755701226
|
||||
12
Assets/Scripts/Net/NetExtends.cs
Normal file
12
Assets/Scripts/Net/NetExtends.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using NBC.Network.Interface;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public static class NetExtends
|
||||
{
|
||||
public static void DispatchMessage(this IResponse response)
|
||||
{
|
||||
Net.Inst.DispatchEventWith(response.OpCode().ToString(), response);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Net/NetExtends.cs.meta
Normal file
3
Assets/Scripts/Net/NetExtends.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25d56f7c87744a199e926365a516b85f
|
||||
timeCreated: 1755702255
|
||||
Reference in New Issue
Block a user