This commit is contained in:
陈思海 2025-03-20 20:47:48 +08:00
parent 4ee13da099
commit ad8b67acb4
6 changed files with 13 additions and 48 deletions

View File

@ -1,17 +1,17 @@
using AlicizaX.Editor; using System;
using AlicizaX.Editor;
using AlicizaX.Network.Runtime; using AlicizaX.Network.Runtime;
using UnityEditor; using UnityEditor;
namespace AlicizaX.Network.Editor namespace AlicizaX.Network.Editor
{ {
[CustomEditor(typeof(NetworkComponent))] [CustomEditor(typeof(NetworkComponent))]
internal sealed class NetworkComponentInspector : ComponentTypeComponentInspector internal sealed class NetworkComponentInspector : GameFrameworkInspector
{ {
private SerializedProperty m_HeartInterval = null; private SerializedProperty m_HeartInterval = null;
protected override void Enable() private void OnEnable()
{ {
base.Enable();
m_HeartInterval = serializedObject.FindProperty("m_HeartInterval"); m_HeartInterval = serializedObject.FindProperty("m_HeartInterval");
} }
@ -30,10 +30,5 @@ namespace AlicizaX.Network.Editor
EditorGUI.EndDisabledGroup(); EditorGUI.EndDisabledGroup();
Repaint(); Repaint();
} }
protected override void RefreshTypeNames()
{
RefreshComponentTypeNames(typeof(INetworkManager));
}
} }
} }

View File

@ -5,7 +5,7 @@ using Fantasy.Network.Interface;
namespace AlicizaX.Network.Runtime namespace AlicizaX.Network.Runtime
{ {
public interface INetworkManager : IModule public interface INetworkModule : IModule
{ {
public EConnectState ConnectState { get; } public EConnectState ConnectState { get; }
void SetHeartInterval(int heartInterval); void SetHeartInterval(int heartInterval);

View File

@ -10,52 +10,22 @@ namespace AlicizaX.Network.Runtime
[DisallowMultipleComponent] [DisallowMultipleComponent]
[AddComponentMenu("Game Framework/Network")] [AddComponentMenu("Game Framework/Network")]
[Preserve] [Preserve]
public sealed class NetworkComponent : GameFrameworkComponent public sealed class NetworkComponent : MonoBehaviour
{ {
private INetworkManager _networkManager; private INetworkModule _networkModule;
[SerializeField] private int m_HeartInterval = 2000; [SerializeField] private int m_HeartInterval = 2000;
public EConnectState ConnectState => _networkManager.ConnectState; private void Awake()
protected override void Awake()
{ {
ImplementationComponentType = Utility.Assembly.GetType(componentType); _networkModule = ModuleSystem.RegisterModule<INetworkModule>(typeof(NetworkModule));
InterfaceComponentType = typeof(INetworkManager); if (_networkModule == null)
base.Awake();
_networkManager = SysModuleCenter.GetModule<INetworkManager>();
if (_networkManager == null)
{ {
Log.Fatal("Network Manager is invalid."); Log.Fatal("Network Manager is invalid.");
return; return;
} }
_networkManager.SetHeartInterval(m_HeartInterval); _networkModule.SetHeartInterval(m_HeartInterval);
}
public async UniTask Initialize(params System.Reflection.Assembly[] assemblies)
{
await _networkManager.Initialize(assemblies);
}
public void Connect(string remoteAddress, NetworkProtocolType networkProtocolType, bool isHttps)
{
_networkManager.Connect(remoteAddress, networkProtocolType, isHttps);
}
public async UniTask<T> Call<T>(IRequest request, long routeId = 0) where T : IResponse
{
return await _networkManager.Call<T>(request, routeId);
}
public void Send(IMessage message, uint rpcId = 0, long routeId = 0)
{
_networkManager.Send(message, rpcId, routeId);
}
public void Send(IRouteMessage routeMessage, uint rpcId = 0, long routeId = 0)
{
_networkManager.Send(routeMessage, rpcId, routeId);
} }
} }
} }

View File

@ -9,7 +9,7 @@ using Log = AlicizaX.Runtime.Log;
namespace AlicizaX.Network.Runtime namespace AlicizaX.Network.Runtime
{ {
[UnityEngine.Scripting.Preserve] [UnityEngine.Scripting.Preserve]
internal sealed class NetworkManager : INetworkManager internal sealed class NetworkModule : INetworkModule
{ {
private Scene _scene; private Scene _scene;
private Session _session; private Session _session;
@ -38,7 +38,7 @@ namespace AlicizaX.Network.Runtime
allAssemblies[i] = assemblies[i]; allAssemblies[i] = assemblies[i];
} }
allAssemblies[allAssemblies.Length - 1] = typeof(NetworkManager).Assembly; allAssemblies[allAssemblies.Length - 1] = typeof(NetworkModule).Assembly;
await Fantasy.Platform.Unity.Entry.Initialize(allAssemblies); await Fantasy.Platform.Unity.Entry.Initialize(allAssemblies);
_scene = await Scene.Create(SceneRuntimeType.MainThread); _scene = await Scene.Create(SceneRuntimeType.MainThread);