Skip to content

feat: simpler quitting flow #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Assets/BossRoom/Prefabs/UI/SettingsPanelCanvas.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &7464515512587493124
RectTransform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1641,7 +1641,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 063abc7eeacd3df4db23e185d26aab43, type: 3}
m_Name:
m_EditorClassIdentifier:
m_QuitButtonText: {fileID: 1810020744250180940}
m_QuitMode: 0
--- !u!1 &7139291127274050927
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2025,7 +2025,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'Exit Game?
m_Text: 'Return to Menu?

'
--- !u!1 &8177924889016445002
Expand Down Expand Up @@ -2693,6 +2693,17 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: addf3685293c35d48a673397c748f116, type: 3}
--- !u!114 &3993040222486159765 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 7721113380232533813, guid: addf3685293c35d48a673397c748f116, type: 3}
m_PrefabInstance: {fileID: 6650909944053036704}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!224 &3993040222838124397 stripped
RectTransform:
m_CorrespondingSourceObject: {fileID: 7721113380319664589, guid: addf3685293c35d48a673397c748f116, type: 3}
Expand All @@ -2715,4 +2726,4 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1106bff381881f94187fe4be82e21554, type: 3}
m_Name:
m_EditorClassIdentifier:
m_QualityBtnText: {fileID: 0}
m_QualityBtnText: {fileID: 3993040222486159765}
4 changes: 2 additions & 2 deletions Assets/BossRoom/Scenes/BossRoom.unity
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/BossRoom/Scenes/CharSelect.unity
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/BossRoom/Scenes/MainMenu.unity
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/BossRoom/Scenes/PostGame.unity
Git LFS file not shown
4 changes: 2 additions & 2 deletions Assets/BossRoom/Scenes/Startup.unity
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,9 @@ enum LobbyMode

Dictionary<LobbyMode, List<GameObject>> m_LobbyUIElementsByMode;

[SerializeField] GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
DIScope m_Scope;

void Awake()
protected override void Awake()
{
//creating a child scope just to have manual control over the lifetime of the things
//that shouldn't live past the current scene existence
m_Scope = new DIScope(DIScope.RootScope);

m_Scope.FinalizeScopeConstruction();
base.Awake();

Instance = this;
CharSelectData = GetComponent<CharSelectData>();
Expand All @@ -121,16 +114,6 @@ void Awake()
{ LobbyMode.LobbyEnding, m_UIElementsForLobbyEnding },
{ LobbyMode.FatalError, m_UIElementsForFatalError },
};

foreach (var autoInjectedGameObject in m_GameObjectsThatWillBeInjectedAutomatically)
{
m_Scope.InjectIn(autoInjectedGameObject);
}
}

public override void OnDestroy()
{
m_Scope.Dispose();
}

protected override void Start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,30 @@ public class ClientMainMenuState : GameStateBehaviour
{
public override GameState ActiveState { get { return GameState.MainMenu; } }

[SerializeField] GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;
DIScope m_Scope;

[SerializeField] NameGenerationData m_NameGenerationData;
[SerializeField] LobbyUIMediator m_LobbyUIMediator;
[SerializeField] IPUIMediator m_IPUIMediator;

[SerializeField] CanvasGroup m_MainMenuButtonsCanvasGroup;
[SerializeField] GameObject m_SignInSpinner;

void Awake()
protected override void Awake()
{
m_MainMenuButtonsCanvasGroup.interactable = false;
m_LobbyUIMediator.Hide();
DIScope.RootScope.InjectIn(this);
base.Awake();
}

protected override void InitializeScope()
{
Scope.BindInstanceAsSingle(m_NameGenerationData);
Scope.BindInstanceAsSingle(m_LobbyUIMediator);
Scope.BindInstanceAsSingle(m_IPUIMediator);
}

[Inject]
void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFacade, LocalLobbyUser localUser, LocalLobby localLobby)
{
m_Scope = new DIScope(DIScope.RootScope);

m_Scope.BindInstanceAsSingle(m_NameGenerationData);
m_Scope.BindInstanceAsSingle(m_LobbyUIMediator);
m_Scope.BindInstanceAsSingle(m_IPUIMediator);

var unityAuthenticationInitOptions = new InitializationOptions();
var profile = ProfileManager.Profile;
if (profile.Length > 0)
Expand All @@ -56,13 +54,6 @@ void InjectDependenciesAndInitialize(AuthenticationServiceFacade authServiceFaca

authServiceFacade.DoSignInAsync(OnAuthSignIn, OnSignInFailed, unityAuthenticationInitOptions);

m_Scope.FinalizeScopeConstruction();

foreach (var autoInjectedGameObject in m_GameObjectsThatWillBeInjectedAutomatically)
{
m_Scope.InjectIn(autoInjectedGameObject);
}

void OnAuthSignIn()
{
m_MainMenuButtonsCanvasGroup.interactable = true;
Expand All @@ -81,11 +72,6 @@ void OnSignInFailed()
}
}

public override void OnDestroy()
{
m_Scope?.Dispose();
}

public void OnStartClicked()
{
m_LobbyUIMediator.ToggleJoinLobbyUI();
Expand Down
35 changes: 18 additions & 17 deletions Assets/BossRoom/Scripts/Client/UI/UIQuitPanel.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
using System;
using Unity.Multiplayer.Samples.BossRoom.Shared;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

namespace Unity.Multiplayer.Samples.BossRoom.Client
{
public class UIQuitPanel : MonoBehaviour
{
enum QuitMode
{
ReturnToMenu,
QuitApplication
}

[SerializeField]
Text m_QuitButtonText;
QuitMode m_QuitMode = QuitMode.ReturnToMenu;

ApplicationController m_ApplicationController;

private bool m_QuitMode = true;

[Inject]
private void InjectDependencies(ApplicationController applicationController)
void InjectDependencies(ApplicationController applicationController)
{
m_ApplicationController = applicationController;
}

void OnEnable()
{
m_QuitMode = NetworkManager.Singleton == null || !NetworkManager.Singleton.IsListening;
m_QuitButtonText.text = m_QuitMode ? "Exit Game?" : "Leave session?";
}

public void Quit()
{
if (m_QuitMode)
{
m_ApplicationController.QuitGame();
}
else
switch (m_QuitMode)
{
m_ApplicationController.LeaveSession();
case QuitMode.ReturnToMenu:
m_ApplicationController.LeaveSession();
break;
case QuitMode.QuitApplication:
m_ApplicationController.QuitGame();
break;
default:
throw new ArgumentOutOfRangeException();
}

gameObject.SetActive(false);
Expand Down
17 changes: 0 additions & 17 deletions Assets/BossRoom/Scripts/Client/UI/UISettingsCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,8 @@ public class UISettingsCanvas : MonoBehaviour

void Awake()
{
// the settings canvas should exist in all scenes!
DontDestroyOnLoad(gameObject);

// hide the settings window at startup (this is just to handle the common case where an artist forgets to disable the window in the prefab)
DisablePanels();
SceneManager.sceneLoaded += OnSceneLoaded;
}

void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
}

void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if (loadSceneMode == LoadSceneMode.Single)
{
DisablePanels();
}
}

void DisablePanels()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class ServerCharSelectState : GameStateBehaviour

Coroutine m_WaitToEndLobbyCoroutine;

void Awake()
protected override void Awake()
{
base.Awake();
CharSelectData = GetComponent<CharSelectData>();
}

Expand Down
30 changes: 30 additions & 0 deletions Assets/BossRoom/Scripts/Shared/Game/State/GameStateBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;
using Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure;
using Unity.Netcode;
using UnityEngine;

Expand Down Expand Up @@ -53,6 +55,29 @@ public virtual bool Persists
/// </summary>
private static GameObject s_ActiveStateGO;

public DIScope Scope
{
get => m_Scope;
private set => m_Scope = value;
}

DIScope m_Scope;

[SerializeField]
GameObject[] m_GameObjectsThatWillBeInjectedAutomatically;

protected virtual void Awake()
{
DIScope.RootScope.InjectIn(this);
Scope = new DIScope(DIScope.RootScope);
InitializeScope();
Scope.FinalizeScopeConstruction();
foreach (var autoInjectedGameObject in m_GameObjectsThatWillBeInjectedAutomatically)
{
Scope.InjectIn(autoInjectedGameObject);
}
}

// Start is called before the first frame update
protected virtual void Start()
{
Expand Down Expand Up @@ -87,8 +112,13 @@ protected virtual void Start()
}
}

protected virtual void InitializeScope()
{
}

public override void OnDestroy()
{
Scope?.Dispose();
base.OnDestroy();
if (!Persists)
{
Expand Down