using UnityEngine; namespace KirbyAdventures { /// /// Ensures a single bootstrap exists and builds the Phase A greybox level. /// public class GameBootstrap : MonoBehaviour { static bool _initialized; [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] static void AutoBootstrap() { if (_initialized) return; if (FindFirstObjectByType() != null) { _initialized = true; return; } var go = new GameObject("GameBootstrap"); go.AddComponent(); _initialized = true; } void Awake() { DontDestroyOnLoad(gameObject); if (GameFlow.Instance == null) { var flowGo = new GameObject("GameFlow"); flowGo.AddComponent(); DontDestroyOnLoad(flowGo); } if (FindFirstObjectByType() == null) { var cp = new GameObject("CheckpointSystem"); cp.AddComponent(); DontDestroyOnLoad(cp); } BuildUi(); Level01ForestBuilder.Build(); } void BuildUi() { var dialogue = DialogueUI.EnsureExists(); var pause = CreateOverlay("PauseOverlay", "ПАУЗА\nEsc — продолжить", new Color(0f, 0f, 0f, 0.65f)); pause.SetActive(false); var win = CreateOverlay("WinOverlay", "Ворота открыты!\nДеревня ждёт Кирби.\n\nПобеда среза Phase A", new Color(0.05f, 0.2f, 0.1f, 0.8f)); win.SetActive(false); if (GameFlow.Instance != null) { GameFlow.Instance.SetPauseOverlay(pause); GameFlow.Instance.SetWinOverlay(win); } // silence unused _ = dialogue; } static GameObject CreateOverlay(string name, string text, Color bg) { var canvasGo = new GameObject(name); var canvas = canvasGo.AddComponent(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.sortingOrder = 100; canvasGo.AddComponent().uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize; canvasGo.AddComponent(); DontDestroyOnLoad(canvasGo); var panel = new GameObject("Panel"); panel.transform.SetParent(canvasGo.transform, false); var img = panel.AddComponent(); img.color = bg; var rt = panel.GetComponent(); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.offsetMin = Vector2.zero; rt.offsetMax = Vector2.zero; var textGo = new GameObject("Text"); textGo.transform.SetParent(panel.transform, false); var uiText = textGo.AddComponent(); uiText.text = text; uiText.alignment = TextAnchor.MiddleCenter; uiText.fontSize = 36; uiText.color = Color.white; uiText.font = Resources.GetBuiltinResource("LegacyRuntime.ttf"); if (uiText.font == null) uiText.font = Resources.GetBuiltinResource("Arial.ttf"); var trt = textGo.GetComponent(); trt.anchorMin = new Vector2(0.1f, 0.2f); trt.anchorMax = new Vector2(0.9f, 0.8f); trt.offsetMin = Vector2.zero; trt.offsetMax = Vector2.zero; return canvasGo; } } }