com.alicizax.unity.network/Runtime/Network/NetworkComponent.cs
2025-02-24 17:35:48 +08:00

40 lines
1.2 KiB
C#

using AlicizaX.Runtime;
using Cysharp.Threading.Tasks;
using Fantasy.Network;
using UnityEngine;
using UnityEngine.Scripting;
namespace AlicizaX.Network.Runtime
{
[DisallowMultipleComponent]
[AddComponentMenu("Game Framework/Network")]
[Preserve]
public sealed class NetworkComponent : GameFrameworkComponent
{
private INetworkManager _networkManager;
protected override void Awake()
{
ImplementationComponentType = Utility.Assembly.GetType(componentType);
InterfaceComponentType = typeof(INetworkManager);
base.Awake();
_networkManager = SysModuleCenter.GetModule<INetworkManager>();
if (_networkManager == null)
{
Log.Fatal("Network Manager is invalid.");
return;
}
}
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);
}
}
}