SetUpSVRForXR.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.InputSystem.XR;
  5. using WCQ.CommonV1_20200325;
  6. [DefaultExecutionOrder(100000)]
  7. public class SetUpSVRForXR : MonoBehaviour
  8. {
  9. [SerializeField]
  10. private Camera XRCamera;
  11. [SerializeField]
  12. private ControllerInputFromAction left;
  13. [SerializeField]
  14. private ControllerInputFromAction right;
  15. private SvrManager svr {
  16. get {
  17. return SvrManager.Instance;
  18. }
  19. }
  20. private SC.InputSystem.InputSystem inputsystem {
  21. get {
  22. return SC.InputSystem.InputSystem.Instant;
  23. }
  24. }
  25. AddOnCamera addonCamera;
  26. private void Awake() {
  27. //DontDestroyOnLoad(gameObject);
  28. DebugMy.Log("SetUpSVR Awake", this, true);
  29. if ( XRCamera == null ) {
  30. DebugMy.LogError("Please Set XRCamera", this);
  31. }
  32. if ( svr != null ) {
  33. svr.gameObject.SetActive(false);
  34. svr.status.running = true;
  35. DebugMy.Log("SetUpSVR Finish", this, true);
  36. addonCamera = XRCamera.gameObject.AddComponent<AddOnCamera>();
  37. return;
  38. }
  39. DebugMy.Log("SetUpSVR Failed", this, true);
  40. }
  41. private void LateUpdate()
  42. {
  43. // DebugMy.isShowNormalLog = true;
  44. //for sync headpose from xr
  45. if ( XRCamera && svr != null ) {
  46. if (Application.platform == RuntimePlatform.Android)
  47. {
  48. svr.head.position = XRCamera.transform.position;
  49. svr.head.rotation = XRCamera.transform.rotation;
  50. }
  51. } else {
  52. //DebugMy.Log("Cannot sync headpose from xr !", this, true);
  53. }
  54. //if (addonCamera )
  55. //{
  56. // addonCamera.LeftController = left.Controller;
  57. // addonCamera.LeftControllerRotation = left.controllerRotation;
  58. //}
  59. //if (addonCamera)
  60. //{
  61. // addonCamera.RightController = right.Controller;
  62. // addonCamera.RightControllerRotation = right.controllerRotation;
  63. //}
  64. }
  65. }