关键代码:
// 全屏
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_EDITOR
private void Reset() {
normal = new Vector2(Screen.width, Screen.height);
full = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
}
#endif
private 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> 全屏状态切换 </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() {
// 重绘GUI
EditorGUI.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);
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。