622 lines
22 KiB
C#
622 lines
22 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using DG.Tweening;
|
|
using Object = UnityEngine.Object;
|
|
|
|
|
|
public enum GameInstanceType
|
|
{
|
|
Zombie,
|
|
Fumarole,
|
|
Waves,
|
|
Duo,
|
|
Squad,
|
|
Base
|
|
}
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
|
|
|
|
//Singleton Instance
|
|
public static UIManager Instance { get; private set; }
|
|
|
|
[SerializeField] OptionsCanvas optionsCanvas;
|
|
|
|
private GameObject exitGameCanvas;
|
|
private GameObject loginScreenCanvas;
|
|
private GameObject escapeMenu;
|
|
private GameObject instanceFinderCanvas;
|
|
|
|
public TMP_Text objectInteractMessage;
|
|
public TMP_Text itemInteractMessage;
|
|
public GameInstanceType GameInstanceType = GameInstanceType.Base;
|
|
public Action OnGameInstancePress;
|
|
|
|
[System.NonSerialized] public TMP_InputField ChatInputField;
|
|
[System.NonSerialized] public GameObject Inventory;
|
|
[System.NonSerialized] public GameObject OnScreenKeyboardGO;
|
|
[System.NonSerialized] public TextMeshProUGUI ReloadIndicator;
|
|
[System.NonSerialized] public GameObject[] GamePadInputBlockers = new GameObject[6];
|
|
[System.NonSerialized] public TMP_InputField UserNameInputField;
|
|
[System.NonSerialized] public TMP_InputField PasswordInputField;
|
|
[System.NonSerialized] public GameObject LoginButton;
|
|
[System.NonSerialized] public GameObject SetIPParent;
|
|
[System.NonSerialized] public TMP_InputField IP_InputField;
|
|
[System.NonSerialized] public GameObject BankVaultCanvas;
|
|
[System.NonSerialized] public GameObject CharacterSelectCanvas;
|
|
|
|
[System.NonSerialized] public GameObject CryptoWalletMenu;
|
|
|
|
[System.NonSerialized] public GameObject CreateAccountMenu;
|
|
[System.NonSerialized] public Button CreateAccountRegisterButton;
|
|
|
|
[System.NonSerialized] public Transform SoloInstanceParent;
|
|
[System.NonSerialized] public Transform DuoInstanceParent;
|
|
[System.NonSerialized] public Transform SquadInstanceParent;
|
|
|
|
[System.NonSerialized] public UnderWaterTimer UnderWaterSystem;
|
|
|
|
[System.NonSerialized] public TMP_Text LoginMessage;
|
|
|
|
[System.NonSerialized] public TMP_Text clipCapacityText;
|
|
[System.NonSerialized] public TMP_Text rocketCapacityText;
|
|
[System.NonSerialized] public Image flameWeaponHud;
|
|
[System.NonSerialized] public Image rocketWeaponHud;
|
|
[System.NonSerialized] public Image ammoWeaponHud;
|
|
[System.NonSerialized] public GameObject VoiceChatTabMenu;
|
|
[System.NonSerialized] public Image SpeakingMicrophoneIcon;
|
|
[SerializeField] private Sprite microphoneOn;
|
|
[SerializeField] private Sprite microphoneOff;
|
|
[System.NonSerialized] public bool IsInGameInstance = false;
|
|
|
|
[System.NonSerialized] public TMP_Text CollectedDiviText;
|
|
|
|
public WaveText waveTextController;
|
|
[System.NonSerialized] public ForgeController ForgeController;
|
|
[System.NonSerialized] public WeaponExchangeController WeaponExchangeController;
|
|
[System.NonSerialized] public WeaponStatsManager WeaponStatsManager;
|
|
|
|
[System.NonSerialized] public ChatBox ChatBox;
|
|
[System.NonSerialized] public InGameStatsController InGameStatsController;
|
|
|
|
private KillMessage fanfair_KillMessage;
|
|
public Queue<string> fanfairMessageQueue = new Queue<string>();
|
|
|
|
public static string defaultIP = Config.SERVER_IP;
|
|
[System.NonSerialized] public string ipInputData = "";
|
|
[System.NonSerialized] public string MostRecentCanvasOpenedName = "LoginScreen";
|
|
|
|
private readonly Color32 localMicOnColour = new Color32(35, 173, 93, 255);
|
|
private readonly Color32 localMicOffColour = new Color32(183, 75, 68, 255);
|
|
#region VictoryScreen
|
|
[Header("Victory Canvas Attributes")]
|
|
[SerializeField] private CanvasGroup backgroundCanvasGroup;
|
|
public TextMeshProUGUI VictoryText;
|
|
[SerializeField] private GameObject statsContainer;
|
|
[SerializeField] private GameObject jackpotHeading;
|
|
[SerializeField] private TextMeshProUGUI jackpotText;
|
|
[SerializeField] private GameObject continueButton;
|
|
[System.NonSerialized] public string victoryScreenAudioClip;
|
|
[System.NonSerialized] public GameObject VictoryCanvas;
|
|
#endregion
|
|
public GameObject StatsCanvas { get; private set; }
|
|
private GameObject tutorialCanvas;
|
|
private CSVReader csvReader;
|
|
|
|
private bool toggleMobileMenu = false;
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
|
|
//these need to be in awake, because they are used in OnEnable. We don't want any race conditions.
|
|
GamePadInputBlockers[0] = getInterface<GameObject>("usernameButton_ForGamepad");
|
|
GamePadInputBlockers[1] = getInterface<GameObject>("passwordButton_ForGamepad");
|
|
GamePadInputBlockers[2] = getInterface<GameObject>("CA_usernameButton_ForGamepad");
|
|
GamePadInputBlockers[3] = getInterface<GameObject>("CA_emailButton_ForGamepad");
|
|
GamePadInputBlockers[4] = getInterface<GameObject>("CA_mobileButton_ForGamepad");
|
|
GamePadInputBlockers[5] = getInterface<GameObject>("CA_passwordButton_ForGamepad");
|
|
|
|
csvReader = GetComponent<CSVReader>();
|
|
|
|
ipInputData = defaultIP;
|
|
|
|
FindAllUIElements();
|
|
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
public void Start()
|
|
{
|
|
getInterface<GameObject>("Crosshair");
|
|
getInterface<GameObject>("ChatBox");
|
|
getInterface<GameObject>("ScreenFlash");
|
|
getInterface<GameObject>("WaveInfo");
|
|
getInterface<GameObject>("DebugData");
|
|
getInterface<GameObject>("QuickInventoryAccess");
|
|
getInterface<GameObject>("PlayerCanvas");
|
|
getInterface<GameObject>("RespawnWaitCanvas");
|
|
getInterface<GameObject>("PaymentConfirmationCanvas");
|
|
getInterface<GameObject>("OptionsCanvas");
|
|
getInterface<GameObject>("DiviGoCanvas");
|
|
getInterface<GameObject>("DiviFlipFountainCanvas");
|
|
getInterface<GameObject>("ChallengeModeCanvas");
|
|
|
|
BankVaultCanvas = getInterface<GameObject>("BankVaultCanvas");
|
|
SetIPParent = getInterface<GameObject>("Set_IP");
|
|
LoginButton = getInterface<GameObject>("loginButton_LoginScreen");
|
|
OnScreenKeyboardGO = getInterface<GameObject>("OnScreenKeyboard");
|
|
escapeMenu = getInterface<GameObject>("EscapeMenu");
|
|
ReloadIndicator = getInterface<GameObject>("ReloadTextIndicator").GetComponent<TextMeshProUGUI>();
|
|
Inventory = getInterface<GameObject>("Inventory");
|
|
loginScreenCanvas = getInterface<GameObject>("LoginScreen");
|
|
exitGameCanvas = getInterface<GameObject>("ExitGameCanvas");
|
|
ChatInputField = getInterface<GameObject>("ChatBoxInputField").GetComponent<TMP_InputField>();
|
|
UserNameInputField = getInterface<GameObject>("usernameInputField").GetComponent<TMP_InputField>();
|
|
PasswordInputField = getInterface<GameObject>("passwordInputField").GetComponent<TMP_InputField>();
|
|
IP_InputField = getInterface<GameObject>("IP_InputField").GetComponent<TMP_InputField>();
|
|
CryptoWalletMenu = getInterface<GameObject>("CryptoWallet");
|
|
CreateAccountMenu = getInterface<GameObject>("CreateAccountCanvas");
|
|
CreateAccountRegisterButton = getInterface<GameObject>("CA_RegisterButton").GetComponent<Button>();
|
|
SoloInstanceParent = getInterface<GameObject>("Solo_Instance_Contents").transform;
|
|
DuoInstanceParent = getInterface<GameObject>("Duo_Instance_Contents").transform;
|
|
SquadInstanceParent = getInterface<GameObject>("Squad_Instance_Contents").transform;
|
|
CharacterSelectCanvas = getInterface<GameObject>("PreGameCanvas");
|
|
instanceFinderCanvas = getInterface<GameObject>("InstanceFinderCanvas");
|
|
VictoryCanvas = getInterface<GameObject>("VictoryOrDefeatCanvas");
|
|
|
|
clipCapacityText = getInterface<GameObject>("TextCurrentAmmo_HUD").GetComponent<TMP_Text>();
|
|
flameWeaponHud = GameObject.Find("FlameWeapon_HUD").GetComponent<Image>();
|
|
rocketWeaponHud = GameObject.Find("RocketLauncher_HUD").GetComponent<Image>();
|
|
ammoWeaponHud = GameObject.Find("CurrentWeapon_HUD").GetComponent<Image>();
|
|
rocketCapacityText = getInterface<GameObject>("Rocket_CurrentAmmo_HUD").GetComponent<TMP_Text>();
|
|
|
|
|
|
LoginMessage = getInterface<GameObject>("loginMessage").GetComponent<TMP_Text>();
|
|
|
|
fanfair_KillMessage = getInterface<GameObject>("kill_message").GetComponent<KillMessage>();
|
|
UnderWaterSystem = getInterface<GameObject>("UnderWaterTimer").GetComponent<UnderWaterTimer>();
|
|
|
|
VoiceChatTabMenu = getInterface<GameObject>("VoiceMenuCanvas");
|
|
SpeakingMicrophoneIcon = getInterface<GameObject>("LocalPlayerMicrophoneIcon").GetComponent<Image>();
|
|
SpeakingMicrophoneIcon.enabled = false;
|
|
|
|
CollectedDiviText = getInterface<GameObject>("Collected_Divi_Amount").GetComponent<TMP_Text>();
|
|
|
|
ChatBox = getInterface<GameObject>("ChatBox").GetComponent<ChatBox>();
|
|
waveTextController = getInterface<GameObject>("WaveCounter").GetComponent<WaveText>();
|
|
|
|
StatsCanvas = getInterface<GameObject>("StatsCanvas");
|
|
|
|
tutorialCanvas = getInterface<GameObject>("TutorialCanvas");
|
|
this.InGameStatsController = getInterface<GameObject>("InGameStatsCanvas").GetComponent<InGameStatsController>();
|
|
this.ForgeController = getInterface<GameObject>("ForgeCanvas").GetComponent<ForgeController>();
|
|
this.WeaponExchangeController = getInterface<GameObject>("WeaponExchangeCanvas").GetComponent<WeaponExchangeController>();
|
|
this.WeaponStatsManager = getInterface<GameObject>("WeaponStatsCanvas").transform.GetChild(0)
|
|
.GetComponent<WeaponStatsManager>();
|
|
SetInitialHiddenMenus();
|
|
}
|
|
|
|
private void FindAllUIElements()
|
|
{
|
|
Button[] buttons = FindObjectsOfType<Button>();
|
|
foreach (Button b in buttons)
|
|
{
|
|
b.onClick.AddListener(new UnityAction(() => ActionButton.ButtonPressed(b.gameObject.name)));
|
|
}
|
|
|
|
TMP_Dropdown[] dropdowns = FindObjectsOfType<TMP_Dropdown>();
|
|
foreach (TMP_Dropdown d in dropdowns)
|
|
{
|
|
d.onValueChanged.AddListener(delegate
|
|
{
|
|
ActionButton.DropdownValueChanged(d);
|
|
});
|
|
}
|
|
|
|
Toggle[] toggles = FindObjectsOfType<Toggle>();
|
|
foreach (Toggle t in toggles)
|
|
{
|
|
t.onValueChanged.AddListener(delegate
|
|
{
|
|
ActionButton.ToggleValueChanged(t);
|
|
});
|
|
}
|
|
|
|
Slider[] sliders = FindObjectsOfType<Slider>();
|
|
foreach (Slider s in sliders)
|
|
{
|
|
s.onValueChanged.AddListener(delegate
|
|
{
|
|
ActionButton.SliderValueChanged(s);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void SetInitialHiddenMenus()
|
|
{
|
|
hideInterface("EscapeMenu");
|
|
hideInterface("Crosshair");
|
|
hideInterface("ChatBox");
|
|
hideInterface("OptionsCanvas");
|
|
hideInterface("ScreenFlash");
|
|
hideInterface("CryptoWallet");
|
|
hideInterface("WaveInfo");
|
|
hideInterface("DiviUI");
|
|
hideInterface("Inventory");
|
|
hideInterface("DebugData");
|
|
hideInterface("QuickInventoryAccess");
|
|
hideInterface("PlayerCanvas");
|
|
hideInterface("VictoryOrDefeatCanvas");
|
|
hideInterface("ExitGameCanvas");
|
|
hideInterface("RespawnWaitCanvas");
|
|
hideInterface("OnScreenKeyboard");
|
|
hideInterface("CreateAccountCanvas");
|
|
hideInterface("Set_IP");
|
|
hideInterface("BankVaultCanvas");
|
|
hideInterface("PreGameCanvas");
|
|
hideInterface("InstanceFinderCanvas");
|
|
hideInterface("PaymentConfirmationCanvas");
|
|
hideInterface("UnderWaterTimer");
|
|
hideInterface("VoiceMenuCanvas");
|
|
hideInterface("DiviGoCanvas");
|
|
hideInterface("TutorialCanvas");
|
|
hideInterface("StatsCanvas");
|
|
hideInterface("InGameStatsCanvas");
|
|
hideInterface("ForgeCanvas");
|
|
hideInterface("WeaponExchangeCanvas");
|
|
hideInterface("DiviFlipFountainCanvas");
|
|
hideInterface("ChallengeModeCanvas");
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void Update()
|
|
{
|
|
if (loginScreen)
|
|
{
|
|
if (escapeMenu.activeInHierarchy) { hideInterface("EscapeMenu"); }
|
|
Player.Instance.updatePlayer = false;
|
|
HandleSetIPMenu();
|
|
HandleQuitGame();
|
|
//CloseForge();
|
|
//CloseWeaponExchange();
|
|
return;
|
|
}
|
|
|
|
if (Player.Instance.GetInputHandler().InventoryKeyPressed)
|
|
{
|
|
Player.Instance.GetInputHandler().InventoryKeyPressed = false;
|
|
|
|
//check that none of these UI elements are active, to enable the inventory.
|
|
if (!MenusAreOpen())
|
|
{
|
|
//button north to toggle inventory
|
|
if (!ChatBox.UsingChatBox)
|
|
{
|
|
InventoryManager.Instance.ToggleInventory();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.P))
|
|
{
|
|
//check that none of these UI elements are active, to enable the inventory.
|
|
if (!MenusAreOpen())
|
|
{
|
|
//button north to toggle inventory
|
|
if (!ChatBox.UsingChatBox)
|
|
{
|
|
PacketManager.sendChatMessage("/pickuppet");
|
|
}
|
|
}
|
|
}
|
|
|
|
if (MenusAreOpen()) { Player.Instance.updatePlayer = false; }
|
|
|
|
|
|
if (fanfairMessageQueue.Count > 0)
|
|
{
|
|
if (!fanfair_KillMessage.gameObject.activeInHierarchy)
|
|
{
|
|
string message = fanfairMessageQueue.Dequeue();
|
|
fanfair_KillMessage.gameObject.SetActive(true);
|
|
fanfair_KillMessage.SetText(message);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool MenusAreOpen()
|
|
{
|
|
if (escapeMenu.activeSelf ||
|
|
optionsCanvas.GetGraphicsMenu().activeInHierarchy ||
|
|
optionsCanvas.GetAudioMenu().activeInHierarchy ||
|
|
optionsCanvas.GetGameplayMenu().activeInHierarchy ||
|
|
optionsCanvas.GetControlsMenu().activeInHierarchy ||
|
|
StatsCanvas.activeSelf ||
|
|
CryptoWalletMenu.activeSelf ||
|
|
CharacterSelectCanvas.activeSelf ||
|
|
instanceFinderCanvas.activeSelf ||
|
|
VictoryCanvas.activeSelf ||
|
|
tutorialCanvas.activeSelf ||
|
|
ForgeController.gameObject.activeSelf ||
|
|
WeaponExchangeController.gameObject.activeSelf
|
|
)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public Sprite RenderItem(int item)
|
|
{
|
|
if (item == -1) return null;
|
|
|
|
Texture2D tex = OnDemandLoader.Load<Texture2D>($"Sprites/ItemSprites/{item}");
|
|
Rect imageSize = new Rect(0.0f, 0.0f, tex.width, tex.height);
|
|
Vector2 imagePivot = new Vector2(0.5f, 0.5f);
|
|
Sprite itemSprite = Sprite.Create(tex, imageSize, imagePivot, pixelsPerUnit: 100, extrude: 0, SpriteMeshType.FullRect);
|
|
|
|
return itemSprite;
|
|
}
|
|
|
|
public void AssignInputFieldsToOnScreenKeyboard(TMP_InputField clickedField) //used in the inspector
|
|
{
|
|
showInterface("OnScreenKeyboard");
|
|
OnScreenKeyboard.Instance.currentInputField = clickedField;
|
|
OnScreenKeyboard.Instance.isPassWordField = clickedField.contentType == TMP_InputField.ContentType.Password;
|
|
}
|
|
|
|
public bool InGameInstance(bool insideInstance) => IsInGameInstance = insideInstance;
|
|
|
|
public void HandleVoiceTabMenu(bool isInputPressed)
|
|
{
|
|
if (!IsInGameInstance || Player.Instance.InSoloInstance) return;
|
|
|
|
if (isInputPressed)
|
|
{
|
|
showInterface(VoiceChatTabMenu.name);
|
|
}
|
|
else
|
|
{
|
|
hideInterface(VoiceChatTabMenu.name);
|
|
}
|
|
}
|
|
|
|
|
|
public void SetIPInputData()
|
|
{
|
|
ipInputData = IP_InputField.text;
|
|
hideInterface("Set_IP");
|
|
}
|
|
|
|
public bool IsGameLobbyCanvasesActive()
|
|
{
|
|
if (instanceFinderCanvas.activeInHierarchy || CharacterSelectCanvas.activeInHierarchy)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private void HandleQuitGame()
|
|
{
|
|
if (Player.Instance.GetInputHandler().PauseKeyPressed)
|
|
{
|
|
Player.Instance.GetInputHandler().PauseKeyPressed = false;
|
|
exitGameCanvas.SetActive(!exitGameCanvas.activeSelf);
|
|
}
|
|
}
|
|
|
|
private void HandleSetIPMenu()
|
|
{
|
|
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.F))
|
|
{
|
|
if (SetIPParent.activeInHierarchy)
|
|
{
|
|
hideInterface(SetIPParent.name);
|
|
}
|
|
else
|
|
{
|
|
showInterface(SetIPParent.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void CloseForge()
|
|
{
|
|
hideInterface(ForgeController.gameObject.name);
|
|
hideInterface(WeaponStatsManager.gameObject.name);
|
|
Player.Instance.UpdatePlayerOnMenuClose();
|
|
//if (!GISocket.Instance.closed)
|
|
// PacketManager.sendChatMessage("/closeForge");
|
|
}
|
|
|
|
public void CloseWeaponExchange()
|
|
{
|
|
hideInterface(WeaponExchangeController.gameObject.name);
|
|
Player.Instance.UpdatePlayerOnMenuClose();
|
|
}
|
|
|
|
public void ResetDefaultCanvasesOnVaultClose()
|
|
{
|
|
hideInterface(Inventory.name);
|
|
hideInterface(BankVaultCanvas.name);
|
|
showInterface("PlayerCanvas");
|
|
showInterface("ChatBox");
|
|
Player.Instance.UpdatePlayerOnMenuClose();
|
|
PacketManager.sendChatMessage("/closeVault");
|
|
}
|
|
|
|
public CSVReader GetCSVReader() => csvReader;
|
|
|
|
public void DisablePlayerCanvasesOnBankVaultOpen()
|
|
{
|
|
hideInterface("PlayerCanvas");
|
|
hideInterface("ChatBox");
|
|
}
|
|
|
|
public void DeleteGameRoomButtons()
|
|
{
|
|
if (DuoInstanceParent.childCount != 0)
|
|
{
|
|
foreach (Transform child in DuoInstanceParent)
|
|
{
|
|
if (child == DuoInstanceParent.GetChild(0)) continue;
|
|
|
|
Destroy(child.gameObject);
|
|
}
|
|
}
|
|
|
|
if (SquadInstanceParent.childCount != 0)
|
|
{
|
|
foreach (Transform child in SquadInstanceParent)
|
|
{
|
|
if (child == SquadInstanceParent.GetChild(0)) continue;
|
|
|
|
Destroy(child.gameObject);
|
|
}
|
|
}
|
|
}
|
|
public void ResetIPToDefault()
|
|
{
|
|
IP_InputField.text = defaultIP;
|
|
hideInterface("Set_IP");
|
|
}
|
|
|
|
|
|
|
|
public void SetUIForJoiningLobby()
|
|
{
|
|
waveTextController.ResetWaveText();
|
|
//ChatBox.ClearChat();
|
|
|
|
}
|
|
|
|
public void ShowEndScreen()
|
|
{
|
|
hideInterface(Inventory.name);
|
|
backgroundCanvasGroup.alpha = 0;
|
|
statsContainer.transform.localScale = new Vector3(0.75f, 0, 0.75f);
|
|
continueButton.transform.localScale = Vector3.zero;
|
|
jackpotHeading.transform.localScale = Vector3.zero;
|
|
|
|
backgroundCanvasGroup.alpha = 0;
|
|
backgroundCanvasGroup.DOFade(1.0f, 2.25f)
|
|
.SetEase(Ease.InSine)
|
|
.SetUpdate(true)
|
|
.OnComplete(() => TweenJackpotContainer());
|
|
|
|
StartCoroutine(DelayVictoryAudio());
|
|
}
|
|
|
|
private IEnumerator DelayVictoryAudio()
|
|
{
|
|
yield return new WaitForSeconds(0.75f);
|
|
AudioManager.Instance.playSound(victoryScreenAudioClip);
|
|
}
|
|
private void TweenJackpotContainer()
|
|
{
|
|
jackpotHeading.transform.localScale = Vector3.zero;
|
|
jackpotHeading.transform.DOScale(Vector3.one, 0.5f)
|
|
.SetEase(Ease.OutBack)
|
|
.SetUpdate(true)
|
|
.OnComplete(() => TweenEndScreen());
|
|
}
|
|
private void TweenEndScreen()
|
|
{
|
|
statsContainer.transform.localScale = new Vector3(0.75f, 0, 1);
|
|
statsContainer.transform.DOScaleY(0.75f, 0.35f)
|
|
.SetEase(Ease.OutBack)
|
|
.SetUpdate(true)
|
|
.OnComplete(() => TweenVictoryContinueButton());
|
|
|
|
SetUIForJoiningLobby();
|
|
}
|
|
private void TweenVictoryContinueButton()
|
|
{
|
|
continueButton.transform.localScale = Vector3.zero;
|
|
continueButton.transform.DOScale(Vector3.one, 0.5f)
|
|
.SetEase(Ease.OutBack)
|
|
.SetUpdate(true);
|
|
}
|
|
|
|
public void showInterface(string name)
|
|
{
|
|
getInterface<GameObject>(name)?.SetActive(true);
|
|
MostRecentCanvasOpenedName = name;
|
|
}
|
|
|
|
public void hideInterface(string name)
|
|
{
|
|
if (name == "CreateAccountCanvas" || name == "ExitGameCanvas") { MostRecentCanvasOpenedName = "LoginScreen"; }
|
|
getInterface<GameObject>(name)?.SetActive(false);
|
|
}
|
|
|
|
//Call to show the login screen
|
|
public void displayLoginScreen()
|
|
{
|
|
GameObject loginInterface = getInterface<GameObject>("LoginScreen");
|
|
loginInterface.SetActive(true);
|
|
loginScreen = true;
|
|
Player.Instance.updatePlayer = false;
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
hideInterface("PaymentConfirmationCanvas");
|
|
hideInterface("WeaponExchangeCanvas");
|
|
hideInterface("ForgeCanvas");
|
|
hideInterface("Inventory");
|
|
}
|
|
|
|
|
|
//repeat for ints
|
|
public static int Repeat(int value, int max) => (value % max + max) % max;
|
|
|
|
//call to close the login screen
|
|
public void closeLoginScreen()
|
|
{
|
|
GameObject loginInterface = getInterface<GameObject>("LoginScreen");
|
|
loginInterface.SetActive(false);
|
|
Client.Instance.mainPlayer.SetActive(true);
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
loginScreen = false;
|
|
Cursor.visible = false;
|
|
|
|
// Finally, launch the HUD interface
|
|
//displayHUD();
|
|
|
|
showInterface("Crosshair");
|
|
showInterface("WaveInfo");
|
|
showInterface("ChatBox");
|
|
showInterface("QuickInventoryAccess");
|
|
showInterface("PlayerCanvas");
|
|
//close game esc menu here
|
|
hideInterface("EscapeMenu");
|
|
|
|
//close interface here
|
|
InventoryManager.Instance.hideInventory();
|
|
}
|
|
|
|
|
|
//get an interface which is in the UI scene
|
|
public T getInterface<T>(string name) where T : Object
|
|
{
|
|
if (!interfaceCache.ContainsKey(name))
|
|
interfaceCache[name] = GameObject.Find(name);
|
|
return (T)interfaceCache[name];
|
|
}
|
|
|
|
|
|
//Stores references to interfaces to allow getInterface to access inactive game objects
|
|
private Dictionary<string, Object> interfaceCache = new Dictionary<string, Object>();
|
|
|
|
//this is true when login screen is visible
|
|
public bool loginScreen = true;
|
|
|
|
}
|