|
|
|
|
|
|
/// </summary>
|
|
|
|
public class GameManager : MonoBehaviour, IReceiveMessages |
|
|
|
{ |
|
|
|
[SerializeField] |
|
|
|
[Tooltip("Only logs of this level or higher will appear in the console.")] |
|
|
|
private LogMode m_logMode = LogMode.Critical; |
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
private List<LocalGameStateObserver> m_GameStateObservers = new List<LocalGameStateObserver>(); |
|
|
|
[SerializeField] |
|
|
|
|
|
|
[SerializeField] |
|
|
|
private List<LobbyServiceDataObserver> m_LobbyServiceObservers = new List<LobbyServiceDataObserver>(); |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
private LocalGameState m_localGameState = new LocalGameState(); |
|
|
|
|
|
|
private bool m_coolingDown; |
|
|
|
|
|
|
|
/// <summary>Rather than a setter, this is usable in-editor. It won't accept an enum, however.</summary>
|
|
|
|
public void SetLobbyColorFilter(int color) { m_lobbyColorFilter = (LobbyColor)color; } |
|
|
|
public void SetLobbyColorFilter(int color){ m_lobbyColorFilter = (LobbyColor)color; } |
|
|
|
|
|
|
|
|
|
|
|
private void Awake() |
|
|
|
{ |
|
|
|
// Do some arbitrary operations to instantiate singletons.
|
|
|
|
|
|
|
|
|
|
|
LogHandler.Get().mode = m_logMode; |
|
|
|
Locator.Get.Provide(new Auth.Identity(OnAuthSignIn)); |
|
|
|
Application.wantsToQuit += OnWantToQuit; |
|
|
|
} |
|
|
|
|
|
|
foreach (var userObs in m_LocalUserObservers) |
|
|
|
userObs.BeginObserving(m_localUser); |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
{ |
|
|
|
if (type == MessageType.RenameRequest) |
|
|
|
{ m_localUser.DisplayName = (string)msg; |
|
|
|
{ |
|
|
|
m_localUser.DisplayName = (string)msg; |
|
|
|
} |
|
|
|
else if (type == MessageType.CreateLobbyRequest) |
|
|
|
{ |
|
|
|
|
|
|
var createLobbyData = (LocalLobby)msg; |
|
|
|
LobbyAsyncRequests.Instance.CreateLobbyAsync(createLobbyData.LobbyName, createLobbyData.MaxPlayerCount, createLobbyData.Private, m_localUser, (r) => |
|
|
|
{ lobby.ToLocalLobby.Convert(r, m_localLobby); |
|
|
|
{ |
|
|
|
lobby.ToLocalLobby.Convert(r, m_localLobby); |
|
|
|
OnCreatedLobby(); |
|
|
|
}, |
|
|
|
OnFailedJoin); |
|
|
|
|
|
|
|
|
|
|
LocalLobby.LobbyData lobbyInfo = (LocalLobby.LobbyData)msg; |
|
|
|
LobbyAsyncRequests.Instance.JoinLobbyAsync(lobbyInfo.LobbyID, lobbyInfo.LobbyCode, m_localUser, (r) => |
|
|
|
{ lobby.ToLocalLobby.Convert(r, m_localLobby); |
|
|
|
{ |
|
|
|
lobby.ToLocalLobby.Convert(r, m_localLobby); |
|
|
|
OnJoinedLobby(); |
|
|
|
}, |
|
|
|
OnFailedJoin); |
|
|
|
|
|
|
return; |
|
|
|
m_lobbyServiceData.State = LobbyQueryState.Fetching; |
|
|
|
LobbyAsyncRequests.Instance.RetrieveLobbyListAsync( |
|
|
|
qr => { |
|
|
|
qr => |
|
|
|
{ |
|
|
|
er => { |
|
|
|
er => |
|
|
|
{ |
|
|
|
long errorLong = 0; |
|
|
|
if (er != null) |
|
|
|
errorLong = er.Status; |
|
|
|
|
|
|
} |
|
|
|
else if (type == MessageType.ChangeGameState) |
|
|
|
{ SetGameState((GameState)msg); |
|
|
|
{ |
|
|
|
SetGameState((GameState)msg); |
|
|
|
{ EmoteType emote = (EmoteType)msg; |
|
|
|
{ |
|
|
|
EmoteType emote = (EmoteType)msg; |
|
|
|
{ m_localUser.UserStatus = (UserStatus)msg; |
|
|
|
{ |
|
|
|
m_localUser.UserStatus = (UserStatus)msg; |
|
|
|
{ BeginCountDown(); |
|
|
|
{ |
|
|
|
BeginCountDown(); |
|
|
|
{ m_localLobby.State = LobbyState.Lobby; |
|
|
|
{ |
|
|
|
m_localLobby.State = LobbyState.Lobby; |
|
|
|
{ m_localUser.UserStatus = UserStatus.InGame; |
|
|
|
{ |
|
|
|
m_localUser.UserStatus = UserStatus.InGame; |
|
|
|
{ m_localLobby.State = LobbyState.Lobby; |
|
|
|
{ |
|
|
|
m_localLobby.State = LobbyState.Lobby; |
|
|
|
m_localLobby.CountDownTime = 0; |
|
|
|
SetUserLobbyState(); |
|
|
|
} |
|
|
|
|
|
|
LobbyAsyncRequests.Instance.EndTracking(); |
|
|
|
|
|
|
|
if (m_relaySetup != null) |
|
|
|
{ Component.Destroy(m_relaySetup); |
|
|
|
{ |
|
|
|
Component.Destroy(m_relaySetup); |
|
|
|
|
|
|
|
{ Component.Destroy(m_relayClient); |
|
|
|
{ |
|
|
|
Component.Destroy(m_relayClient); |
|
|
|
m_relayClient = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
StartCoroutine(RetryRelayConnection()); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
m_relayClient = client; |
|
|
|
OnReceiveMessage(MessageType.LobbyUserStatus, UserStatus.Lobby); |
|
|
|
} |
|
|
|
|
|
|
yield break; |
|
|
|
m_localLobby.CountDownTime -= Time.deltaTime; |
|
|
|
} |
|
|
|
|
|
|
|
if (m_relayClient is RelayUtpHost) |
|
|
|
(m_relayClient as RelayUtpHost).SendInGameState(); |
|
|
|
} |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#region Teardown
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// In builds, if we are in a lobby and try to send a Leave request on application quit, it won't go through if we're quitting on the same frame.
|
|
|
|
/// So, we need to delay just briefly to let the request happen (though we don't need to wait for the result).
|
|
|
|
|
|
|
m_localLobby = null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endregion
|
|
|
|
} |
|
|
|
} |