VirtualFramework/Assets/Scripts/UI/UICameraSwitch.cs

100 lines
2.6 KiB
C#
Raw Normal View History

2024-12-16 15:45:19 +08:00
using UnityEngine;
using UnityEngine.UI;
using QFramework;
using DG.Tweening;
using System.Collections.Generic;
2024-12-16 15:45:19 +08:00
namespace QFramework.Example
{
public class UICameraSwitchData : UIPanelData
{
public string nearDevice;
public string normalDevice;
2024-12-16 15:45:19 +08:00
public Vector3 nearPos;
public Vector3 nearRot;
public Vector3 normalPos;
public Vector3 normalRot;
public float nearTime;
public float normalTime;
2024-12-16 15:45:19 +08:00
}
public partial class UICameraSwitch : UIPanel
{
protected override void OnInit(IUIData uiData = null)
{
2025-01-09 09:43:15 +08:00
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
2024-12-16 15:45:19 +08:00
mData = uiData as UICameraSwitchData ?? new UICameraSwitchData();
// please add init code here
Near.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
SetNear();
2024-12-16 15:45:19 +08:00
}
2024-12-16 15:58:37 +08:00
Near.transform.Find("Bg/Line").gameObject.SetActive(isOn);
2024-12-16 15:45:19 +08:00
});
Far.onValueChanged.AddListener(isOn =>
{
2024-12-16 15:45:19 +08:00
if (isOn)
{
SetNormal();
2024-12-16 15:45:19 +08:00
}
2024-12-16 15:58:37 +08:00
Far.transform.Find("Bg/Line").gameObject.SetActive(isOn);
2024-12-16 15:45:19 +08:00
});
}
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);
}
2024-12-16 15:45:19 +08:00
protected override void OnOpen(IUIData uiData = null)
{
mData = uiData as UICameraSwitchData ?? new UICameraSwitchData();
2024-12-31 16:31:32 +08:00
if (Near.isOn)
{
2024-12-31 16:31:32 +08:00
SetNear();
}
if (Far.isOn)
{
SetNormal();
}
2024-12-16 15:45:19 +08:00
}
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
}
2024-12-16 15:45:19 +08:00
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}