This can be seen as the initial state of the project after the released demo.
The changes include:
- New ship models
- Singleton manager structure to keep project scaleable in the future
- Managing players, their settings, character choices, statistics, match setups, controls etc. in a separate decoupled scene
- Main menu with transitions to the arena scene
- Beginnings of a custom audio solution
- Logging with Log4Net
It is really a complete overhaul of the projects structure and management.
119 lines
2.8 KiB
C#
119 lines
2.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Serialization;
|
|
using log4net;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace Managers
|
|
{
|
|
/// <summary>
|
|
/// Manages dynamic UI elements which can be triggered from everywhere.
|
|
/// </summary>
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
[SerializeField] public bool IsUIActiveScene { get; set; }
|
|
public HUD hUD { get; private set; }
|
|
public Announcments announcments { get; private set; }
|
|
public PauseMenu pauseMenu { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Globally accessible member to use manager with.
|
|
/// </summary>
|
|
public static UIManager G { get; private set; }
|
|
|
|
void Awake()
|
|
{
|
|
G = this;
|
|
Log.Info("Awake");
|
|
}
|
|
|
|
public bool StartManagingMatchUI()
|
|
{
|
|
if (!StartManagingHUD() || !StartManagingAnnouncements())
|
|
{
|
|
Log.Error("Problems when starting in game match UI.");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingHUD()
|
|
{
|
|
if (hUD == null)
|
|
{
|
|
GameObject go = GameObject.Find("HUD");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find HUD GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
hUD = go.GetComponent<HUD>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingPauseMenu()
|
|
{
|
|
if (pauseMenu == null)
|
|
{
|
|
GameObject go = GameObject.Find("Paused Menu");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find Pause Menu GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
pauseMenu = go.GetComponent<PauseMenu>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingAnnouncements()
|
|
{
|
|
if (announcments == null)
|
|
{
|
|
GameObject go = GameObject.Find("Announcer UI");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find Pause Menu GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
announcments = go.GetComponent<Announcments>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void AssignHUDElementsToPlayers(List<Player> players)
|
|
{
|
|
foreach (Player p in players)
|
|
{
|
|
Ship s = p.spawnedCharacter.GetComponent<Ship>();
|
|
s.boostUI = hUD.boostCapacities[p.playerNumber - 1].GetComponent<BoostCapacityUI>();
|
|
s.boostUI.SetPlayerName(p);
|
|
hUD.boostCapacities[p.playerNumber - 1].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void StartInputPrompt(Dictionary<int, Player> unassignedPlayers)
|
|
{
|
|
foreach (int playerNumber in unassignedPlayers.Keys)
|
|
{
|
|
hUD.StartJoinPrompt(unassignedPlayers[playerNumber]);
|
|
}
|
|
}
|
|
|
|
public void ShowMatchStartPrompt()
|
|
{
|
|
announcments.AnnounceText("Press Start/Enter \n to start the match!");
|
|
}
|
|
public void HideAnnouncement()
|
|
{
|
|
announcments.StopAnnouncement();
|
|
}
|
|
}
|
|
} |