using AlicizaX.Runtime; using Cysharp.Threading.Tasks; using Fantasy.Network; using Fantasy.Network.Interface; using UnityEngine; using UnityEngine.Scripting; namespace AlicizaX.Network.Runtime { [DisallowMultipleComponent] [AddComponentMenu("Game Framework/Network")] [Preserve] public sealed class NetworkComponent : GameFrameworkComponent { private INetworkManager _networkManager; [SerializeField] private int m_HeartInterval = 2000; public EConnectState ConnectState => _networkManager.ConnectState; protected override void Awake() { ImplementationComponentType = Utility.Assembly.GetType(componentType); InterfaceComponentType = typeof(INetworkManager); base.Awake(); _networkManager = SysModuleCenter.GetModule(); if (_networkManager == null) { Log.Fatal("Network Manager is invalid."); return; } _networkManager.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 Call(IRequest request, long routeId = 0) where T : IResponse { return await _networkManager.Call(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); } } }