1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/UI/Scripts/WebGLFullscreenLogic.cs

66 lines
1.5 KiB
C#

using UniRx;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_WEBGL
using WebGLSupport;
#endif
public class WebGLFullscreenLogic : BaseBehaviour
{
[SerializeField]
private Button[] _btns;
private void Reset()
{
this._btns = GetComponentsInChildren<Button>(true);
}
private void Start()
{
// 全屏Btn
#if UNITY_WEBGL
this._btns[0]
.OnClickAsObservable()
.Where(_ => Screen.fullScreen == false)
.Subscribe(_ => {
Debug.Log("全屏");
WebGLFullscreen.SetFullscreen();
})
.AddTo(this);
#else
this._btns[0]
.OnClickAsObservable()
.Subscribe(_ => {
Debug.Log("全屏");
Screen.fullScreen = true;
Screen.SetResolution(1920, 1080, true);
})
.AddTo(this);
#endif
this._btns[1]
.OnClickAsObservable()
.Subscribe(_ => {
Debug.Log("退出全屏");
Screen.fullScreen = false;
#if !UNITY_WEBGL
Screen.SetResolution(1440, 810, false);
#endif
})
.AddTo(this);
}
private void Update()
{
if (Screen.fullScreen == true)
{
this._btns[0].gameObject.SetActive(false);
this._btns[1].gameObject.SetActive(true);
}
else
{
this._btns[0].gameObject.SetActive(true);
this._btns[1].gameObject.SetActive(false);
}
}
}