using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UIElements; namespace Kirurobo { public class SampleManager : MonoBehaviour { private static SampleManager _instance; public static SampleManager Instance => _instance ?? (_instance = GameObject.FindAnyObjectByType() ?? new SampleManager()); public Canvas canvas; private void Awake() { // 设为单例。若已有实例则销毁自身 if (this != Instance) { Destroy(this.gameObject); return; } DontDestroyOnLoad(Instance); DontDestroyOnLoad(UniWindowController.current); SceneManager.sceneLoaded += SceneManager_sceneLoaded; } /// /// 场景加载时记录主相机 /// /// /// private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1) { UniWindowController.current.SetCamera(Camera.main); } /// /// 打开指定名称的场景 /// /// 场景名 public void LoadScene(string name) { if (name == "SimpleSample") { // SimpleSample 时无脚本控制,在此处设置透明 UniWindowController.current.isTransparent = true; } else if (name == "FullScreenSample") { // FullScreenSample 时强制最大化 UniWindowController.current.shouldFitMonitor = true; } SceneManager.LoadScene(name); } /// /// 退出 /// public void Quit() { #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } }