完善VR逻辑

This commit is contained in:
shenjianxing 2025-03-24 14:32:22 +08:00
parent 77ebcb713b
commit 5a7bed3295
7 changed files with 99 additions and 13 deletions

View File

@ -74,12 +74,33 @@ namespace QFramework
data.normalRot = Utility.GetVector3FromStrArray(datas["normalRot"]);
}
}
if (datas.ContainsKey("vrPos"))
{
data.vrPos = Utility.GetVector3FromStrArray(datas["vrPos"]);
}
if (datas.ContainsKey("vrRot"))
{
data.vrRot = Utility.GetVector3FromStrArray(datas["vrRot"]);
}
if (datas.ContainsKey("isOn"))
{
data.isOn = datas["isOn"];
}
float.TryParse(datas["nearTime"], out data.nearTime);
float.TryParse(datas["normalTime"], out data.normalTime);
if (datas.ContainsKey("nearTime"))
{
float.TryParse(datas["nearTime"], out data.nearTime);
}
if (datas.ContainsKey("normalTime"))
{
float.TryParse(datas["normalTime"], out data.normalTime);
}
if (datas.ContainsKey("vrTime"))
{
float.TryParse(datas["vrTime"], out data.vrTime);
}
UIKit.OpenPanelAsync<UICameraSwitch>(uiData: data, canvasLevel: UILevel.RightBottom).ToAction().StartGlobal(() => this.Finish());
}

View File

@ -47,12 +47,14 @@ public class DeviceItem : MonoBehaviour
tipItem = gameObject.GetOrAddComponent<TipItem>();
tipItem.Set(device.Tip);
}
#if VR
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
#endif
}
@ -60,10 +62,8 @@ public class DeviceItem : MonoBehaviour
private void OnClick(ZPointer arg0, int arg1, GameObject arg2)
{
Debug.LogError($"当前物体:{gameObject.name} 目标物体:{arg2.name}");
if (gameObject == arg2)
{
Debug.LogError("OnClick:" + arg2.name);
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
@ -75,12 +75,17 @@ public class DeviceItem : MonoBehaviour
{
if (gameObject == arg1)
{
Debug.LogError("OnObjExit:" + arg1.name);
var trigger = gameObject.GetComponent<HighlightTrigger>();
if (trigger == null || trigger.enabled == false)
{
return;
}
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect)
{
effect.highlighted = false;
}
}
}
@ -88,7 +93,11 @@ public class DeviceItem : MonoBehaviour
{
if (gameObject == arg1)
{
Debug.LogError("OnObjEnter:" + arg1.name);
var trigger = gameObject.GetComponent<HighlightTrigger>();
if (trigger == null || trigger.enabled == false)
{
return;
}
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect)
{

View File

@ -12,6 +12,9 @@ public class Launch : MonoBehaviour
{
loader = ResLoader.Allocate();
StartCoroutine(StartApp());
#if VR
Utility.FindObj("FlyCamera")?.SetActive(false);
#endif
}

View File

@ -14,9 +14,9 @@ public class TimeScaleController : MonoBehaviour
private void Awake()
{
#if VR
gameObject.SetActive(false);
#endif
//#if VR
// gameObject.SetActive(false);
//#endif
}
private void Update()
{

View File

@ -14,8 +14,11 @@ namespace QFramework.Example
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;
}
@ -79,10 +82,31 @@ namespace QFramework.Example
Near.gameObject.SetActive(mData.nearPos != default);
Far.gameObject.SetActive(mData.normalPos != default);
#if VR
Near.gameObject.SetActive(false);
Far.gameObject.SetActive(false);
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)
@ -120,7 +144,10 @@ namespace QFramework.Example
break;
}
}
#if VR
Near.gameObject.SetActive(false);
Far.gameObject.SetActive(false);
#endif
}

View File

@ -824,6 +824,30 @@ namespace XMLTool
{
act.args.Add("isOn", isOn.Value);
}
XAttribute vrPos = action.Attribute("vrPos");
if (vrPos != null)
{
act.args.Add("vrPos", vrPos.Value);
}
XAttribute vrRot = action.Attribute("vrRot");
if (vrRot != null)
{
act.args.Add("vrRot", vrRot.Value);
}
XAttribute vrTime = action.Attribute("vrTime");
if (vrTime != null)
{
act.args.Add("vrTime", vrTime.Value);
}
else
{
act.args.Add("vrTime", "0");
}
newAction = act;
}
break;

View File

@ -112,8 +112,10 @@
<!--镜头切换 近距离和默认 如果有了nearDevice就可以不用nearPos和nearRot了 按照device的坐标和旋转来处理镜头 normalDevice同理
只设置坐标 不执行镜头切换 是否执行要根据UI的按钮操作来
如果不配置 nearPos或者normalPos 则自动隐藏对应的视角UI按钮
VR版 单独的相机位置使用vrPos和vrRot来配置
-->
<Action type="CameraSwitch" nearDevice="肠钳" normalDevice="组织钳" nearPos="-3.942,3.24,-4.319" nearRot="16.42331,180,0" nearTime="1" normalPos="-3.942,3.24,-3.946" normalRot="16.42331,180,-5.305351E-14" normalTime="1"></Action>
<Action type="CameraSwitch" nearDevice="肠钳" normalDevice="组织钳" nearPos="-3.942,3.24,-4.319" nearRot="16.42331,180,0" nearTime="1" normalPos="-3.942,3.24,-3.946" normalRot="16.42331,180,-5.305351E-14" normalTime="1" vrPos="0,0,0" vrRot="0,0,0" vrTime="0"></Action>
<!--文字弹窗 按钮可以多个 点击事件使用UIClick
alpha 0-1 背景的透明度
-->