rj-action-library/Runtime/Networking/NetworkManager.cs

65 lines
1.5 KiB
C#

using Godot;
namespace Rokojori
{
[GlobalClass]
public partial class NetworkManager:Node
{
[Export]
public NetworkBackend backend;
NetworkNodeMemberReferences _references = new NetworkNodeMemberReferences();
public NetworkNodeMemberReferences references => _references;
ExtendedNetworkTransport _transport = new ExtendedNetworkTransport();
public NetworkTransport transport => _transport;
ExtendedNetworkSessionManager _sessionManager = new ExtendedNetworkSessionManager();
public NetworkSessionManager sessionManager => _sessionManager;
bool _initialized = false;
[Export]
public Action onStartedSession;
[Export]
public Action onSessionMemberJoined;
[Export]
public Action onSessionMemberLeft;
public static NetworkManager Get()
{
return Unique<NetworkManager>.Get();
}
public static bool IsInSession => Get().sessionManager.isInSession;
public static int ownSessionMemberIndex => Get().sessionManager.ownMemberIndex;
public static int serverSessionMemberIndex =>Get().sessionManager.serverMemberIndex;
public void Initialize()
{
if ( _initialized )
{
return;
}
RJLog.Log( "InitializeBackend:" );
backend.InitializeBackend( this, _sessionManager, _transport );
_initialized = true;
}
public override void _Process( double delta )
{
if ( ! IsInSession )
{
return;
}
_transport.ProcessQueuedMessages();
}
}
}