VirtualFramework/Assets/Scripts/UI/UICameraSwitch.cs

100 lines
2.5 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-31 16:17:48 +08:00
public bool isNear;
2024-12-16 15:45:19 +08:00
}
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();
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:17:48 +08:00
//if (mData.isNear)
//{
// if (Near.isOn == false)
// {
// Near.isOn = true;
// }
// else
// {
// SetNear();
// }
//}
//else
//{
// if (Far.isOn == false)
// {
// Far.isOn = true;
// }
// else
// {
// SetNormal();
// }
//}
2024-12-16 15:45:19 +08:00
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}