2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.4 KiB

5 years ago
  1. //========= Copyright 2016-2020, HTC Corporation. All rights reserved. ===========
  2. using HTC.UnityPlugin.Utility;
  3. using HTC.UnityPlugin.VRModuleManagement;
  4. using UnityEngine;
  5. #if UNITY_2017_2_OR_NEWER
  6. using UnityEngine.XR;
  7. #endif
  8. namespace HTC.UnityPlugin.Vive
  9. {
  10. // This script set custom device height depends on loaded VR device,
  11. // Daydream need additional height for device so
  12. // we can control camera-rig like using room-scale VR devices
  13. public class CustomDeviceHeight : MonoBehaviour
  14. {
  15. [SerializeField]
  16. private float m_height = 1.3f;
  17. public float height
  18. {
  19. get { return m_height; }
  20. set { if (ChangeProp.Set(ref m_height, value)) { UpdateHeight(); } }
  21. }
  22. #if UNITY_EDITOR
  23. private void OnValidate()
  24. {
  25. if (Application.isPlaying && isActiveAndEnabled && VRModule.Active)
  26. {
  27. UpdateHeight();
  28. }
  29. }
  30. #endif
  31. private void OnEnable()
  32. {
  33. VRModule.onActiveModuleChanged += OnActiveModuleChanged;
  34. VRModule.Initialize();
  35. UpdateHeight();
  36. }
  37. private void OnDisable()
  38. {
  39. VRModule.onActiveModuleChanged -= OnActiveModuleChanged;
  40. }
  41. private void OnActiveModuleChanged(VRModuleActiveEnum activeModule)
  42. {
  43. UpdateHeight();
  44. }
  45. public void UpdateHeight()
  46. {
  47. var pos = transform.localPosition;
  48. switch (VRModule.activeModule)
  49. {
  50. case VRModuleActiveEnum.DayDream:
  51. transform.localPosition = new Vector3(pos.x, m_height, pos.z);
  52. break;
  53. #if VIU_OCULUSVR && !VIU_OCULUSVR_19_0_OR_NEWER
  54. case VRModuleActiveEnum.OculusVR:
  55. if (OVRPlugin.GetSystemHeadsetType().Equals(OVRPlugin.SystemHeadset.Oculus_Go))
  56. {
  57. transform.localPosition = new Vector3(pos.x, m_height, pos.z);
  58. }
  59. break;
  60. #endif
  61. #if UNITY_2019_2_OR_NEWER && !UNITY_2019_3_OR_NEWER
  62. case VRModuleActiveEnum.UnityNativeVR:
  63. if (XRDevice.model.Equals("Oculus Go"))
  64. {
  65. transform.localPosition = new Vector3(pos.x, m_height, pos.z);
  66. }
  67. break;
  68. #endif
  69. }
  70. }
  71. }
  72. }