You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.8 KiB
C#

2 weeks ago
using System;
using Unity.BossRoom.ConnectionManagement;
using Unity.BossRoom.UnityServices.Lobbies;
using Unity.BossRoom.Utils;
using Unity.Multiplayer.Samples.Utilities;
using UnityEngine;
using UnityEngine.SceneManagement;
using VContainer;
namespace UUnity.BossRoom.ConnectionManagement
{
/// <summary>
/// Connection state corresponding to when the NetworkManager is shut down. From this state we can transition to the
/// ClientConnecting sate, if starting as a client, or the StartingHost state, if starting as a host.
/// </summary>
class OfflineState : ConnectionState
{
[Inject]
LobbyServiceFacade m_LobbyServiceFacade;
[Inject]
ProfileManager m_ProfileManager;
[Inject]
LocalLobby m_LocalLobby;
const string k_MainMenuSceneName = "MainMenu";
public override void Enter()
{
m_LobbyServiceFacade.EndTracking();
m_ConnectionManager.NetworkManager.Shutdown();
if (SceneManager.GetActiveScene().name != k_MainMenuSceneName)
{
SceneLoaderWrapper.Instance.LoadScene(k_MainMenuSceneName, useNetworkSceneManager: false);
}
}
public override void Exit() { }
public override void StartClientIP(string playerName, string ipaddress, int port)
{
var connectionMethod = new ConnectionMethodIP(ipaddress, (ushort)port, m_ConnectionManager, m_ProfileManager, playerName);
m_ConnectionManager.m_ClientReconnecting.Configure(connectionMethod);
m_ConnectionManager.ChangeState(m_ConnectionManager.m_ClientConnecting.Configure(connectionMethod));
}
public override void StartClientLobby(string playerName)
{
var connectionMethod = new ConnectionMethodRelay(m_LobbyServiceFacade, m_LocalLobby, m_ConnectionManager, m_ProfileManager, playerName);
m_ConnectionManager.m_ClientReconnecting.Configure(connectionMethod);
m_ConnectionManager.ChangeState(m_ConnectionManager.m_ClientConnecting.Configure(connectionMethod));
}
public override void StartHostIP(string playerName, string ipaddress, int port)
{
var connectionMethod = new ConnectionMethodIP(ipaddress, (ushort)port, m_ConnectionManager, m_ProfileManager, playerName);
m_ConnectionManager.ChangeState(m_ConnectionManager.m_StartingHost.Configure(connectionMethod));
}
public override void StartHostLobby(string playerName)
{
var connectionMethod = new ConnectionMethodRelay(m_LobbyServiceFacade, m_LocalLobby, m_ConnectionManager, m_ProfileManager, playerName);
m_ConnectionManager.ChangeState(m_ConnectionManager.m_StartingHost.Configure(connectionMethod));
}
}
}