init uniWindowController 0.9.8
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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<SampleManager>() ?? new SampleManager());
|
||||
|
||||
public Canvas canvas;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 设为单例。若已有实例则销毁自身
|
||||
if (this != Instance)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
DontDestroyOnLoad(Instance);
|
||||
DontDestroyOnLoad(UniWindowController.current);
|
||||
|
||||
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 场景加载时记录主相机
|
||||
/// </summary>
|
||||
/// <param name="arg0"></param>
|
||||
/// <param name="arg1"></param>
|
||||
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
|
||||
{
|
||||
UniWindowController.current.SetCamera(Camera.main);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开指定名称的场景
|
||||
/// </summary>
|
||||
/// <param name="name">场景名</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出
|
||||
/// </summary>
|
||||
public void Quit()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user