From 37d0e6e64afeb577e3e1f7ab99dc4c41c49b6beb Mon Sep 17 00:00:00 2001 From: "PS2022BEIQYLQO\\Admin" <1159790761@qq.com> Date: Sat, 18 May 2024 11:48:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EmergencyEvacuation/Assets/HMDControl.cs | 26 ++++++++---- EmergencyEvacuation/Assets/Scenes/Main.unity | 25 ++++++++++- EmergencyEvacuation/Assets/XRControl.cs | 44 ++++++++++++++++++++ EmergencyEvacuation/Assets/XRControl.cs.meta | 11 +++++ 4 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 EmergencyEvacuation/Assets/XRControl.cs create mode 100644 EmergencyEvacuation/Assets/XRControl.cs.meta diff --git a/EmergencyEvacuation/Assets/HMDControl.cs b/EmergencyEvacuation/Assets/HMDControl.cs index 9eda9b5..d3e9b85 100644 --- a/EmergencyEvacuation/Assets/HMDControl.cs +++ b/EmergencyEvacuation/Assets/HMDControl.cs @@ -10,27 +10,37 @@ public class HMDControl : MonoBehaviour public GameObject handleft; public GameObject handright; private int speed=1; - + public float moveSpeed = 5f; + public float turnSpeed = 100f; // Start is called before the first frame update void Start() { head.transform.position +=new Vector3(0,1,0) * 2.8f; - handright.transform.position = new Vector3(-0.77f, 0.94f, 2.1f); - handleft.transform.position = new Vector3(-0.47f, 0.94f, 1.5f); + //handright.transform.position = new Vector3(-0.77f, 0.94f, 2.1f); + //handleft.transform.position = new Vector3(-0.47f, 0.94f, 1.5f); } // Update is called once per frame void Update() { - // 获取水平和垂直输入 - float h = Input.GetAxis("Horizontal"); - float v = Input.GetAxis("Vertical"); + //// 获取水平和垂直输入 + //float h = Input.GetAxis("Horizontal"); + //float v = Input.GetAxis("Vertical"); // 根据输入移动物体 - Vector3 movement = new Vector3(h, 0f, v); - head.transform.Translate(movement * speed * Time.deltaTime); + //Vector3 movement = new Vector3(h, 0f, v); + //head.transform.Translate(movement * speed * Time.deltaTime); //handleft.transform.position = new Vector3(0.063f, 2.022f, 0.745f) ; //handleft.transform.eulerAngles = new Vector3(-110, -80, -179); + + float moveDirection = Input.GetAxis("Vertical"); // W 和 S 键 + float turnDirection = Input.GetAxis("Horizontal"); // A 和 D 键 + + // 移动 + head.transform.Translate(Vector3.forward * moveDirection * moveSpeed * Time.deltaTime, Space.Self); + + // 转向 + head.transform.Rotate(Vector3.up, turnDirection * turnSpeed * Time.deltaTime, Space.Self); } } diff --git a/EmergencyEvacuation/Assets/Scenes/Main.unity b/EmergencyEvacuation/Assets/Scenes/Main.unity index e559856..9e966f4 100644 --- a/EmergencyEvacuation/Assets/Scenes/Main.unity +++ b/EmergencyEvacuation/Assets/Scenes/Main.unity @@ -1115,7 +1115,7 @@ MonoBehaviour: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 509285653} - m_Enabled: 1 + m_Enabled: 0 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: 6d6e19972d8984547b7008d21841fe57, type: 3} m_Name: @@ -2172,10 +2172,18 @@ PrefabInstance: propertyPath: m_Constraints value: 112 objectReference: {fileID: 0} + - target: {fileID: 8834320319295017361, guid: fdc3ba53f4e81a040b0471bbbafbb10a, type: 3} + propertyPath: m_IsKinematic + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8834320319295017362, guid: fdc3ba53f4e81a040b0471bbbafbb10a, type: 3} propertyPath: m_Name value: HandPlayer objectReference: {fileID: 0} + - target: {fileID: 8834320319295017362, guid: fdc3ba53f4e81a040b0471bbbafbb10a, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 8834320319295017374, guid: fdc3ba53f4e81a040b0471bbbafbb10a, type: 3} propertyPath: m_Material value: @@ -4383,6 +4391,7 @@ GameObject: - component: {fileID: 1687875735} - component: {fileID: 1687875734} - component: {fileID: 1687875736} + - component: {fileID: 1687875737} m_Layer: 0 m_Name: Manager m_TagString: Untagged @@ -4434,6 +4443,20 @@ MonoBehaviour: head: {fileID: 509285653} handleft: {fileID: 2053242896} handright: {fileID: 1724965350} + moveSpeed: 5 + turnSpeed: 100 +--- !u!114 &1687875737 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1687875733} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 769b401939dd60141b0d748e39469b2a, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1724965350 GameObject: m_ObjectHideFlags: 0 diff --git a/EmergencyEvacuation/Assets/XRControl.cs b/EmergencyEvacuation/Assets/XRControl.cs new file mode 100644 index 0000000..2d79b7a --- /dev/null +++ b/EmergencyEvacuation/Assets/XRControl.cs @@ -0,0 +1,44 @@ +using System.Collections; +using UnityEngine; +using UnityEngine.XR.Management; + +public class XRControl : MonoBehaviour +{ + private XRManagerSettings xrManager; + + void Start() + { + xrManager = XRGeneralSettings.Instance.Manager; + if (XRGeneralSettings.Instance.Manager.activeLoader == null) { StopXR(); } + } + + public void StartXR() + { + StartCoroutine(StartXRLoader()); + } + + public void StopXR() + { + StartCoroutine(StopXRLoader()); + } + + private IEnumerator StartXRLoader() + { + if (!xrManager.isInitializationComplete) + { + xrManager.InitializeLoader(); + yield return new WaitUntil(() => xrManager.isInitializationComplete); + xrManager.StartSubsystems(); + } + } + + private IEnumerator StopXRLoader() + { + if (xrManager.isInitializationComplete) + { + xrManager.StopSubsystems(); + xrManager.DeinitializeLoader(); + yield return null; + } + } +} diff --git a/EmergencyEvacuation/Assets/XRControl.cs.meta b/EmergencyEvacuation/Assets/XRControl.cs.meta new file mode 100644 index 0000000..15c7007 --- /dev/null +++ b/EmergencyEvacuation/Assets/XRControl.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 769b401939dd60141b0d748e39469b2a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: