From 76462dadbdb399aed9b208b66c86c1f27698f866 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Wed, 19 Mar 2025 16:31:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9vr=E4=B8=80=E4=BD=93=E6=9C=BA?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UIKit/Scripts/Resources/VRUIRoot.prefab | 84 +++----- .../Toolkits/UIKit/Scripts/UIPanel.cs | 194 +++++++++--------- Assets/Scripts/Actions/TextWindowAction.cs | 1 - Assets/Scripts/FreeCameraController.cs | 33 +-- Assets/Scripts/UI/UICameraSwitch.cs | 23 ++- 5 files changed, 168 insertions(+), 167 deletions(-) diff --git a/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab b/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab index 05498737..d70a6ba9 100644 --- a/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab +++ b/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab @@ -123,7 +123,7 @@ Transform: m_GameObject: {fileID: 598348144801550191} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 2.1975, z: -2.25} + m_LocalPosition: {x: 0, y: 2.1975, z: 0} m_LocalScale: {x: 15, y: 15, z: 15} m_ConstrainProportionsScale: 0 m_Children: @@ -172,7 +172,7 @@ Transform: m_GameObject: {fileID: 765259898297824089} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -2.25} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 15, y: 15, z: 15} m_ConstrainProportionsScale: 0 m_Children: @@ -428,7 +428,6 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - - {fileID: 4206005111461178323} - {fileID: 1943472158707926008} - {fileID: 4955625632054724442} - {fileID: 2220253086530989832} @@ -570,7 +569,7 @@ Transform: m_GameObject: {fileID: 3400309332038407868} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -0.000000059604645} + m_LocalPosition: {x: 0.030000001, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1064,7 +1063,7 @@ Transform: m_GameObject: {fileID: 4951725383111470759} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -0.000000059604645} + m_LocalPosition: {x: -0.030000001, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -1165,53 +1164,6 @@ MonoBehaviour: mipBias: 0 varianceClampScale: 0.9 contrastAdaptiveSharpening: 0 ---- !u!1 &5295768088636320424 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4206005111461178323} - - component: {fileID: 7751590708231362653} - m_Layer: 0 - m_Name: ZProvider - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &4206005111461178323 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5295768088636320424} - serializedVersion: 2 - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 6541928711621635503} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &7751590708231362653 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 5295768088636320424} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ae9977e6c48cd7040b272527034d9de1, type: 3} - m_Name: - m_EditorClassIdentifier: - _displayReferenceProfile: 2 - _displayReferenceSize: {x: 0.521, y: 0.293} - _displayReferenceResolution: {x: 1920, y: 1080} --- !u!1 &5647687646066518589 GameObject: m_ObjectHideFlags: 0 @@ -1440,6 +1392,8 @@ GameObject: - component: {fileID: 6835854032803285639} - component: {fileID: 263436429275714491} - component: {fileID: 6027451431851870885} + - component: {fileID: 5140476435316401990} + - component: {fileID: 1546245213169538227} m_Layer: 0 m_Name: ZCamera m_TagString: MainCamera @@ -1456,7 +1410,7 @@ Transform: m_GameObject: {fileID: 8487585372649695129} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: -0.59773743} + m_LocalPosition: {x: 0, y: 0, z: -0.41000003} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: @@ -1584,6 +1538,30 @@ MonoBehaviour: mipBias: 0 varianceClampScale: 0.9 contrastAdaptiveSharpening: 0 +--- !u!114 &5140476435316401990 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8487585372649695129} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 0} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &1546245213169538227 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8487585372649695129} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 0} + m_Name: + m_EditorClassIdentifier: --- !u!1 &8683029409827073046 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/QFramework/Toolkits/UIKit/Scripts/UIPanel.cs b/Assets/QFramework/Toolkits/UIKit/Scripts/UIPanel.cs index 0d2a2965..d99a6250 100644 --- a/Assets/QFramework/Toolkits/UIKit/Scripts/UIPanel.cs +++ b/Assets/QFramework/Toolkits/UIKit/Scripts/UIPanel.cs @@ -11,124 +11,132 @@ namespace QFramework { - using UnityEngine; + using UnityEngine; - /// - /// 每个 UIPanel 对应的Data - /// - public interface IUIData - { - } + /// + /// 每个 UIPanel 对应的Data + /// + public interface IUIData + { + } - public class UIPanelData : IUIData - { - } - - public abstract partial class UIPanel : QMonoBehaviour, IPanel - { - public Transform Transform => transform; + public class UIPanelData : IUIData + { + } - IPanelLoader IPanel.Loader { get; set; } + public abstract partial class UIPanel : QMonoBehaviour, IPanel + { + public Transform Transform => transform; - public PanelInfo Info { get; set; } + IPanelLoader IPanel.Loader { get; set; } - public PanelState State { get; set; } + public PanelInfo Info { get; set; } - protected IUIData mUIData; + public PanelState State { get; set; } - public override IManager Manager => UIManager.Instance; + protected IUIData mUIData; - protected override void OnBeforeDestroy() - { - ClearUIComponents(); - } + public override IManager Manager => UIManager.Instance; - protected virtual void ClearUIComponents() - { - } + protected override void OnBeforeDestroy() + { + ClearUIComponents(); + } - public void Init(IUIData uiData = null) - { - mUIData = uiData; - OnInit(uiData); - } + protected virtual void ClearUIComponents() + { + } - public void Open(IUIData uiData = null) - { - State = PanelState.Opening; - OnOpen(uiData); - } + public void Init(IUIData uiData = null) + { + mUIData = uiData; + OnInit(uiData); + } - public override void Hide() - { - State = PanelState.Hide; - base.Hide(); - } + public void Open(IUIData uiData = null) + { + State = PanelState.Opening; + OnOpen(uiData); + } + + public override void Hide() + { + State = PanelState.Hide; + base.Hide(); + } - protected virtual void OnInit(IUIData uiData = null) - { + protected virtual void OnInit(IUIData uiData = null) + { - } + } - protected virtual void OnOpen(IUIData uiData = null) - { + protected virtual void OnOpen(IUIData uiData = null) + { - } + } - /// - /// avoid override in child class - /// - protected sealed override void OnDestroy() - { - base.OnDestroy(); - } + /// + /// avoid override in child class + /// + protected sealed override void OnDestroy() + { + base.OnDestroy(); + } - /// - /// 关闭,不允许子类调用 - /// - void IPanel.Close(bool destroyed) - { - Info.UIData = mUIData; - mOnClosed?.Invoke(); - mOnClosed = null; - Hide(); - State = PanelState.Closed; - OnClose(); + /// + /// 关闭,不允许子类调用 + /// + void IPanel.Close(bool destroyed) + { + Info.UIData = mUIData; + mOnClosed?.Invoke(); + mOnClosed = null; + Hide(); + State = PanelState.Closed; + OnClose(); - if (destroyed) - { - Destroy(gameObject); - } + if (destroyed) + { + Destroy(gameObject); + } - var panelInterface = this as IPanel; - panelInterface.Loader.Unload(); - UIKit.Config.PanelLoaderPool.RecycleLoader(panelInterface.Loader); - panelInterface.Loader = null; + var panelInterface = this as IPanel; + panelInterface.Loader.Unload(); + UIKit.Config.PanelLoaderPool.RecycleLoader(panelInterface.Loader); + panelInterface.Loader = null; - mUIData = null; - } + mUIData = null; + } - protected void CloseSelf() - { - UIKit.ClosePanel(this); - } + protected void CloseSelf() + { + UIKit.ClosePanel(this); + } - protected void Back() - { - UIKit.Back(name); - } + protected void Back() + { + UIKit.Back(name); + } - /// - /// 必须使用这个 - /// - protected abstract void OnClose(); + /// + /// 必须使用这个 + /// + protected abstract void OnClose(); - private System.Action mOnClosed; + private System.Action mOnClosed; - public void OnClosed(System.Action onPanelClosed) - { - mOnClosed = onPanelClosed; - } - } + public void OnClosed(System.Action onPanelClosed) + { + mOnClosed = onPanelClosed; + } + + +#if VR + private void Update() + { + transform.localEulerAngles = Vector3.zero; + } +#endif + } } \ No newline at end of file diff --git a/Assets/Scripts/Actions/TextWindowAction.cs b/Assets/Scripts/Actions/TextWindowAction.cs index 984f2a07..50a12bbf 100644 --- a/Assets/Scripts/Actions/TextWindowAction.cs +++ b/Assets/Scripts/Actions/TextWindowAction.cs @@ -5,7 +5,6 @@ using QFramework; using System; using QFramework.Example; using System.Linq; -using TreeEditor; public class TextWindowAction : IAction { public ulong ActionID { get; set; } diff --git a/Assets/Scripts/FreeCameraController.cs b/Assets/Scripts/FreeCameraController.cs index 0e4c3bf4..a31e2d0d 100644 --- a/Assets/Scripts/FreeCameraController.cs +++ b/Assets/Scripts/FreeCameraController.cs @@ -27,27 +27,27 @@ public class FreeCameraController : MonoBehaviour { instance = this; DontDestroyOnLoad(this); - - // Cm = GameObject.Find("Mcam"); + + // Cm = GameObject.Find("Mcam"); ctrlor = GetComponent(); Global.appSetting.MouseMoveSpeed.RegisterWithInitValue(v => rotateSpeed = v); } - /// - /// QEƶ - /// - /// + /// + /// QEƶ + /// + /// Vector3 GetInputTranslationDirection() { Vector3 direction = new Vector3(); - - if ( Input.GetKey(KeyCode.Q)) + + if (Input.GetKey(KeyCode.Q)) { direction += Vector3.up; } - if ( Input.GetKey(KeyCode.E)) + if (Input.GetKey(KeyCode.E)) { direction += Vector3.down; } @@ -58,14 +58,15 @@ public class FreeCameraController : MonoBehaviour { if (isMov) { - //// ƶ - //float horizontal = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime; - //float vertical = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime; +#if VR + // ƶ + float horizontal = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime; + float vertical = Input.GetAxis("Vertical") * moveSpeed * Time.deltaTime; - //Vector3 move = transform.right * horizontal + transform.forward * vertical; - - //transform.position += move; + Vector3 move = transform.right * horizontal + transform.forward * vertical; + transform.position += move; +#else //Wǰ if (Input.GetKey(KeyCode.W)) @@ -107,7 +108,7 @@ public class FreeCameraController : MonoBehaviour } ////QEƶ //transform.position+= GetInputTranslationDirection()*0.01f; - +#endif } if (isRot) { diff --git a/Assets/Scripts/UI/UICameraSwitch.cs b/Assets/Scripts/UI/UICameraSwitch.cs index 89079724..ba02ad78 100644 --- a/Assets/Scripts/UI/UICameraSwitch.cs +++ b/Assets/Scripts/UI/UICameraSwitch.cs @@ -47,15 +47,30 @@ namespace QFramework.Example public void SetNear() { - Camera.main.transform.DOMove(mData.nearPos, mData.nearTime); - Camera.main.transform.DORotate(mData.nearRot, mData.nearTime); + 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() { - Camera.main.transform.DOMove(mData.normalPos, mData.normalTime); - Camera.main.transform.DORotate(mData.normalRot, mData.normalTime); + 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) {