using System.Collections.Generic; using UnityEngine; using SanAndreasUnity.Behaviours; using UnityEngine.UI; namespace SanAndreasUnity.UI { public class MainMenu : MonoBehaviour { public static MainMenu Instance { get; private set; } public Color openedWindowTextColor = Color.green; public Color ClosedWindowTextColor => this.buttonPrefab.GetComponentInChildren().color; static MenuEntry s_rootMenuEntry = new MenuEntry(); public Canvas canvas; public RectTransform buttonsContainer; public GameObject buttonPrefab; void Awake() { if (null == Instance) Instance = this; // add Exit button RegisterMenuEntry(new MenuEntry { name = "Exit", sortPriority = int.MaxValue, clickAction = () => GameManager.ExitApplication() }); } void OnSceneChanged(SceneChangedMessage sceneChangedMessage) { this.canvas.enabled = GameManager.IsInStartupScene; } public static void RegisterMenuEntry (MenuEntry menuEntry) { int indexOfMenuEntry = s_rootMenuEntry.AddChild (menuEntry); GameObject buttonGo = Instantiate(Instance.buttonPrefab); buttonGo.name = menuEntry.name; buttonGo.GetComponentInChildren().text = menuEntry.name; buttonGo.transform.SetParent(Instance.buttonsContainer.transform, false); buttonGo.transform.SetSiblingIndex(indexOfMenuEntry); buttonGo.GetComponent