From 5a7bed3295c8e6f259e5b83a82f959a7b0145c13 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 24 Mar 2025 14:32:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84VR=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/CameraSwitchAction.cs | 25 +++++++++++++-- Assets/Scripts/Item/DeviceItem.cs | 17 +++++++--- Assets/Scripts/Launch.cs | 3 ++ Assets/Scripts/TimeScaleController.cs | 6 ++-- Assets/Scripts/UI/UICameraSwitch.cs | 33 ++++++++++++++++++-- Assets/Scripts/Xml/XmlParser.cs | 24 ++++++++++++++ Doc/Xml配置文档.xml | 4 ++- 7 files changed, 99 insertions(+), 13 deletions(-) diff --git a/Assets/Scripts/Actions/CameraSwitchAction.cs b/Assets/Scripts/Actions/CameraSwitchAction.cs index beaa5066..e9ecaeed 100644 --- a/Assets/Scripts/Actions/CameraSwitchAction.cs +++ b/Assets/Scripts/Actions/CameraSwitchAction.cs @@ -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(uiData: data, canvasLevel: UILevel.RightBottom).ToAction().StartGlobal(() => this.Finish()); } diff --git a/Assets/Scripts/Item/DeviceItem.cs b/Assets/Scripts/Item/DeviceItem.cs index 9ff9f6fc..81b8a599 100644 --- a/Assets/Scripts/Item/DeviceItem.cs +++ b/Assets/Scripts/Item/DeviceItem.cs @@ -47,12 +47,14 @@ public class DeviceItem : MonoBehaviour tipItem = gameObject.GetOrAddComponent(); tipItem.Set(device.Tip); } +#if VR UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectEntered.AddListener(OnObjEnter); UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectEntered.AddListener(OnObjEnter); UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectExited.AddListener(OnObjExit); UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectExited.AddListener(OnObjExit); UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnClick.AddListener(OnClick); UIRoot.Instance.transform.Find("ZStylus").GetComponent().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(); if (effect != null) { @@ -75,12 +75,17 @@ public class DeviceItem : MonoBehaviour { if (gameObject == arg1) { - Debug.LogError("OnObjExit:" + arg1.name); + var trigger = gameObject.GetComponent(); + if (trigger == null || trigger.enabled == false) + { + return; + } var effect = gameObject.GetComponent(); 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(); + if (trigger == null || trigger.enabled == false) + { + return; + } var effect = gameObject.GetComponent(); if (effect) { diff --git a/Assets/Scripts/Launch.cs b/Assets/Scripts/Launch.cs index cfe71e87..acfb8991 100644 --- a/Assets/Scripts/Launch.cs +++ b/Assets/Scripts/Launch.cs @@ -12,6 +12,9 @@ public class Launch : MonoBehaviour { loader = ResLoader.Allocate(); StartCoroutine(StartApp()); +#if VR + Utility.FindObj("FlyCamera")?.SetActive(false); +#endif } diff --git a/Assets/Scripts/TimeScaleController.cs b/Assets/Scripts/TimeScaleController.cs index 00b299e2..bb0134f2 100644 --- a/Assets/Scripts/TimeScaleController.cs +++ b/Assets/Scripts/TimeScaleController.cs @@ -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() { diff --git a/Assets/Scripts/UI/UICameraSwitch.cs b/Assets/Scripts/UI/UICameraSwitch.cs index 5ff424ad..b9149925 100644 --- a/Assets/Scripts/UI/UICameraSwitch.cs +++ b/Assets/Scripts/UI/UICameraSwitch.cs @@ -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 } diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 1d795f54..1acb3558 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -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; diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index b8f57467..fc8e3bb7 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -112,8 +112,10 @@ - +