136 lines
3.7 KiB
C#
136 lines
3.7 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 string isOn;
|
|
|
|
}
|
|
public partial class UICameraSwitch : UIPanel
|
|
{
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
|
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();
|
|
|
|
Near.gameObject.SetActive(mData.nearPos != default);
|
|
Far.gameObject.SetActive(mData.normalPos != default);
|
|
|
|
|
|
if (string.IsNullOrEmpty(mData.isOn))
|
|
{
|
|
if (Near.isOn && Near.gameObject.activeSelf)
|
|
{
|
|
SetNear();
|
|
}
|
|
if (Far.isOn && Far.gameObject.activeSelf)
|
|
{
|
|
SetNormal();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (mData.isOn)
|
|
{
|
|
case "near":
|
|
if (Near.isOn == false)
|
|
{
|
|
Near.isOn = true;
|
|
}
|
|
else
|
|
{
|
|
SetNear();
|
|
}
|
|
break;
|
|
case "normal":
|
|
if (Far.isOn == false)
|
|
{
|
|
Far.isOn = true;
|
|
}
|
|
else
|
|
{
|
|
SetNormal();
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
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()
|
|
{
|
|
}
|
|
}
|
|
}
|