190 lines
5.4 KiB
C#
190 lines
5.4 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 Vector3 vrPos;
|
||
public Vector3 vrRot;
|
||
public float nearTime;
|
||
public float normalTime;
|
||
public float vrTime;
|
||
public string isOn;
|
||
|
||
}
|
||
public partial class UICameraSwitch : UIPanel
|
||
{
|
||
bool firstFreeMove = true;
|
||
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()
|
||
{
|
||
Transform trans = null;
|
||
#if VR
|
||
trans = UIRoot.Instance.transform.Find("ZFrame");
|
||
#else
|
||
trans = Camera.main.transform;
|
||
|
||
#endif
|
||
trans.DOMove(mData.nearPos, mData.nearTime);
|
||
trans.DORotate(mData.nearRot, mData.nearTime);
|
||
}
|
||
|
||
public void SetNormal()
|
||
{
|
||
|
||
Transform trans = null;
|
||
#if VR
|
||
trans = UIRoot.Instance.transform.Find("ZFrame");
|
||
#else
|
||
trans = Camera.main.transform;
|
||
|
||
#endif
|
||
|
||
trans.DOMove(mData.normalPos, mData.normalTime);
|
||
trans.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 VR
|
||
// Transform trans = UIRoot.Instance.transform.Find("ZFrame");
|
||
// if (mData.vrPos != default)
|
||
// {
|
||
// mData.nearPos = mData.vrPos;
|
||
// mData.nearRot = mData.vrRot;
|
||
// mData.nearTime = mData.vrTime;
|
||
// mData.isOn = "near";
|
||
// }
|
||
// else
|
||
// {
|
||
|
||
// if (mData.nearPos != default)
|
||
// {
|
||
// mData.isOn = "near";
|
||
// }
|
||
// else if (mData.normalPos != default)
|
||
// {
|
||
// mData.isOn = "normal";
|
||
// }
|
||
// }
|
||
//#endif
|
||
|
||
|
||
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;
|
||
}
|
||
}
|
||
//#if VR
|
||
// Near.gameObject.SetActive(false);
|
||
// Far.gameObject.SetActive(false);
|
||
//#endif
|
||
|
||
}
|
||
|
||
private void Update()
|
||
{
|
||
#if UNITY_STANDALONE_WIN && !VR
|
||
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;
|
||
if (firstFreeMove)
|
||
{
|
||
UITipWindowData data = new UITipWindowData();
|
||
data.txt = "<22><><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>ӽǣ<D3BD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½ǰ<C2BD>ť<EFBFBD>ɻص<C9BB>Ԥ<EFBFBD><D4A4><EFBFBD>ӽǡ<D3BD>";
|
||
data.btns.Add(new UITipWindowData.ItemData() { txt = "ȷ<><C8B7>" });
|
||
UIKit.OpenPanelAsync<UITipWindow>(canvasLevel: UILevel.PopUI, uiData: data).ToAction().StartGlobal();
|
||
firstFreeMove = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
#endif
|
||
}
|
||
|
||
protected override void OnShow()
|
||
{
|
||
}
|
||
|
||
protected override void OnHide()
|
||
{
|
||
}
|
||
|
||
protected override void OnClose()
|
||
{
|
||
}
|
||
}
|
||
}
|