VirtualFramework/Assets/Scripts/UI/UICameraSwitch.cs

102 lines
2.5 KiB
C#

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 bool isNear = false;
}
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 (mData.isNear)
{
if (Near.isOn == false)
{
Near.isOn = true;
}
else
{
SetNear();
}
}
else
{
if (Far.isOn == false)
{
Far.isOn = true;
}
else
{
SetNormal();
}
}
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}