using UnityEngine; using UnityEngine.UI; using QFramework; using DG.Tweening; using System.Collections.Generic; namespace QFramework.Example { public class UICameraSwitchData : UIPanelData { public string nearDevice; public string normalDevice; public Vector3 nearPos; public Vector3 nearRot; public Vector3 normalPos; public Vector3 normalRot; public float nearTime; public float normalTime; } public partial class UICameraSwitch : UIPanel { protected override void OnInit(IUIData uiData = null) { mData = uiData as UICameraSwitchData ?? new UICameraSwitchData(); // please add init code here Near.onValueChanged.AddListener(isOn => { if (isOn) { SetNear(); } Near.transform.Find("Bg/Line").gameObject.SetActive(isOn); }); Far.onValueChanged.AddListener(isOn => { if (isOn) { SetNormal(); } Far.transform.Find("Bg/Line").gameObject.SetActive(isOn); }); } public void SetNear() { Camera.main.transform.DOMove(mData.nearPos, mData.nearTime); Camera.main.transform.DORotate(mData.nearRot, mData.nearTime); } public void SetNormal() { Camera.main.transform.DOMove(mData.normalPos, mData.normalTime); Camera.main.transform.DORotate(mData.normalRot, mData.normalTime); } protected override void OnOpen(IUIData uiData = null) { mData = uiData as UICameraSwitchData ?? new UICameraSwitchData(); if (Near.isOn) { SetNear(); } if (Far.isOn) { SetNormal(); } } private void Update() { #if UNITY_STANDALONE_WIN if (Near.isOn == true || Far.isOn == true) { if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.D)) { Near.isOn = false; Far.isOn = false; } } #endif } protected override void OnShow() { } protected override void OnHide() { } protected override void OnClose() { } } }