生活随笔
收集整理的這篇文章主要介紹了
Unity全屏切换
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
關鍵代碼:
// 全屏
Screen.SetResolution(1920, 1080, true);// 正常
Screen.SetResolution(1366, 768, false);
封裝:
FullScreenSetup.cs
using UnityEngine;/// <summary> 全屏設置
/// <para>ZhangYu 2018-06-21</para>
/// </summary>
public class FullScreenSetup : MonoBehaviour {/// <summary> 正常分辨率 </summary>public Vector2 normal;/// <summary> 全屏分辨率 </summary>public Vector2 full;/// <summary> 是否已進入全屏 </summary>public static bool isFullScreen;#if UNITY_EDITORprivate void Reset() {normal = new Vector2(Screen.width, Screen.height);full = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);}#endifprivate void Start() {if ((int)normal.x <= 0 || (int)normal.y <= 0) normal = new Vector2(Screen.width, Screen.height);if ((int)full.x <= 0 || (int)full.y <= 0) new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);}/// <summary> 設置是否全屏 </summary>public bool fullScreen {get { return isFullScreen; }set {if (value) {Screen.SetResolution((int)full.x, (int)full.y, true);} else {Screen.SetResolution((int)normal.x, (int)normal.y, false);}isFullScreen = value;}}/// <summary> 全屏狀態(tài)切換 </summary>public void fullScreenSwitch() {fullScreen = !fullScreen;}}
附送腳本皮膚:
FullScreenSetupEditor.cs
using UnityEditor;
using UnityEngine;/// <summary>
/// 全屏設置 編輯器
/// <para>ZhangYu 2018-06-15</para>
/// </summary>
[CanEditMultipleObjects]
[CustomEditor(typeof(FullScreenSetup))]
public class FullScreenSetupEditor : Editor {public override void OnInspectorGUI() {// 重繪GUIEditorGUI.BeginChangeCheck();drawProperty("normal", "正常分辨率");drawProperty("full", "全屏分辨率");if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();}private void drawProperty(string property, string label) {EditorGUILayout.PropertyField(serializedObject.FindProperty(property), new GUIContent(label), true);}}
新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎!定制產品紅包拿不停!
總結
以上是生活随笔為你收集整理的Unity全屏切换的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。