using UnityEngine; using OHM.UnityToolkit.UI; using UnityEngine.Serialization; public class UIRootController : MonoBehaviour { [SerializeField] [FormerlySerializedAs("appController")] private AppController _appController; public UIMainMenu mainMenu; public UICoreGame coreGame; public UIGameOver gameOver; public UIVictory victory; public UIHud hud; private void Awake() { InitSubMenus(); hud.Setup(_appController); _appController.onGameExited.AddListener(OnGameExited); _appController.coreGame.onGameStarted.AddListener(OnCoreGameStarted); _appController.coreGame.onGameOver.AddListener(OnGameOver); _appController.onLevelCleared.AddListener(OnGameWon); } private void Start() { if (mainMenu != null) { mainMenu.Show(); } } private void InitSubMenus() { UIMenu[] menus = GetComponentsInChildren(true); for (int i = 0; i < menus.Length; i++) { menus[i].Setup(_appController); } } public void OnGameExited() { if (mainMenu != null) { mainMenu.Show(); } GetComponent().HideAllExcept(mainMenu); } public void OnCoreGameStarted() { if (coreGame != null) { coreGame.Show(); } GetComponent().HideAllExcept(coreGame); } public void OnGameOver() { if (gameOver != null) { gameOver.Show(); } GetComponent().HideAllExcept(gameOver); } public void OnGameWon() { if (victory != null) { victory.Show(); } GetComponent().HideAllExcept(victory); } }