Files
source/Assets/Scripts/AccountMenu/AccountHandler.cs

132 lines
6.1 KiB
C#

using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
public class AccountHandler : MonoBehaviour
{
public static AccountHandler instance;
public AccountLoggedIn accountLoggedIn;
[SerializeField] private AccountLoggedOut accountLoggedOut;
[SerializeField] private AccountLogin accountLogin;
[SerializeField] private AccountRegister accountRegister;
[SerializeField] private AccountChangeUsername accountChangeUsername;
[SerializeField] private AccountChangePassword accountChangePassword;
[SerializeField] private AccountRefreshLogin accountRefreshLogin;
[SerializeField] internal AccountForgotDetails accountForgotDetails;
void Awake()
{
instance = this;
}
void Start()
{
if (BazookaManager.Instance.GetAccountID() != null && BazookaManager.Instance.GetAccountName() != null && BazookaManager.Instance.GetAccountSession() != null)
{
SwitchPanel(0);
}
else
{
SwitchPanel(1);
}
}
public void SwitchPanel(int panel)
{
switch (panel)
{
case 0:
accountLoggedIn.gameObject.SetActive(true);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 1:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(true);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 2:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(true);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 3:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(true);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 4:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(true);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 5:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(true);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(false);
break;
case 6:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(true);
accountForgotDetails.gameObject.SetActive(false);
break;
case 7:
accountLoggedIn.gameObject.SetActive(false);
accountLoggedOut.gameObject.SetActive(false);
accountLogin.gameObject.SetActive(false);
accountRegister.gameObject.SetActive(false);
accountChangeUsername.gameObject.SetActive(false);
accountChangePassword.gameObject.SetActive(false);
accountRefreshLogin.gameObject.SetActive(false);
accountForgotDetails.gameObject.SetActive(true);
break;
}
foreach (CustomColorObject customColorObject in FindObjectsByType<CustomColorObject>(FindObjectsSortMode.None)) customColorObject.SetColor();
}
async void Update()
{
if (Keyboard.current.escapeKey.wasPressedThisFrame)
{
if (accountChangePassword.gameObject.activeSelf || accountChangeUsername.gameObject.activeSelf || accountRefreshLogin.gameObject.activeSelf) SwitchPanel(0);
else if (accountLogin.gameObject.activeSelf || accountRegister.gameObject.activeSelf) SwitchPanel(1);
else if (accountForgotDetails.gameObject.activeSelf) accountForgotDetails.forgotDetailsBackButton.onClick.Invoke();
else await SceneManager.LoadSceneAsync("MainMenu");
}
}
}