MRCLoader.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using UnityEngine;
  2. using Rokid.UXR.Config;
  3. using Rokid.UXR.Native;
  4. namespace Rokid.UXR.SubModule
  5. {
  6. [DisallowMultipleComponent]
  7. public class MRCLoader : MonoBehaviour
  8. {
  9. public static bool isMRCDriverCreated;
  10. private bool isMRCInited;
  11. void Update()
  12. {
  13. if (isMRCDriverCreated)
  14. {
  15. return;
  16. }
  17. if (!isMRCInited && UXRSDKConfig.Instance.MRCActive)
  18. {
  19. #if !UNITY_EDITOR
  20. if (NativeInterface.NativeAPI.GetHeadTrackingStatus() == HeadTrackingStatus.Tracking)
  21. #endif
  22. {
  23. isMRCInited = true;
  24. //加载MRC启动器Prefab,如果加载不到,说明未安装RokidMRC这个Package
  25. GameObject mrcDriver = Resources.Load<GameObject>("MRCDriver");
  26. if (mrcDriver == null)
  27. {
  28. Debug.LogError("Please Install RokidMRC Package Through NPM");
  29. return;
  30. }
  31. //生成MRC启动器
  32. GameObject driver = Instantiate(mrcDriver);
  33. isMRCDriverCreated = true;
  34. //设置相机cullingMask
  35. Camera renderCam = driver.transform.Find("RenderCamera").GetComponent<Camera>();
  36. if (renderCam == null)
  37. {
  38. Debug.LogError("RokidMRC Package Is Invalid");
  39. return;
  40. }
  41. renderCam.cullingMask = UXRSDKConfig.Instance.MRCCameraRenderLayer;
  42. renderCam.renderingPath = UXRSDKConfig.Instance.MRCCameraRenderingPath;
  43. }
  44. }
  45. }
  46. }
  47. }