Пример #1
0
        public virtual void TrackNode(UnityEngine.XR.XRNode node)
        {
            transform = GetComponent <Transform>();
            transform.MakeZeroedChildOf(TBCameraRig.instance.GetTrackingVolume());
            transform.localScale = Vector3.one;
            _node = node;

#if UNITY_EDITOR
            switch (node)
            {
            case UnityEngine.XR.XRNode.LeftHand:
                gameObject.name = "LeftHand";
                break;

            case UnityEngine.XR.XRNode.RightHand:
                gameObject.name = "RightHand";
                break;

            case UnityEngine.XR.XRNode.GameController:
                gameObject.name = "GameController";
                break;
            }
#endif

            if (TBTracking.OnNodeConnected != null)
            {
                TBTracking.OnNodeConnected(node, transform);
            }
        }
Пример #2
0
        public virtual void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            TBCore.Events.OnVRModeEnabled += EnableVRCamera;

            instance       = this;
            _initialized   = true;
            _startingScale = transform.localScale.x;
            TBLogging.LogMessage("Assigned new TBCameraRig instance...");

            ReadInitialCameraSettings();

            _trackingVolume = new GameObject().transform;
            _trackingVolume.gameObject.name = "Tracking Volume";
            _trackingVolume.MakeZeroedChildOf(transform);

            _centerEyeTransform = new GameObject().transform;
            _centerEyeTransform.gameObject.name = "Standard VR Camera";
            _centerEyeTransform.MakeZeroedChildOf(_trackingVolume);

            if (TBCore.UsingVRMode() && (TBCore.GetActivePlatform() != VRPlatform.None))
            {
                SetupVRCamera();
                SetMainCamera(_primaryCamera, true);
            }
            else
            {
                Setup2DCamera();
                SetMainCamera(_2DCamera, true);
            }

            DestroyTempCamera();

            _audioListenerTransform = new GameObject("AudioListener").transform;
            _audioListener          = _audioListenerTransform.gameObject.AddComponent <AudioListener>();
            _audioListenerTransform.gameObject.AddComponent <TBAudioListener>();

            if (TBTracking.OnNodeConnected != null)
            {
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.CenterEye, _centerEyeTransform);
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.Head, _centerEyeTransform);
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.TrackingReference, _trackingVolume);
            }
        }
Пример #3
0
        private void SetupNativeCamera(VRPlatform platform)
        {
            _centerEyeTransform = new GameObject().transform;
            _centerEyeTransform.MakeZeroedChildOf(_trackingVolume);
            _centerEyeTransform.gameObject.name = "Standard VR Camera";
            _centerEyeTransform.gameObject.tag  = "MainCamera";
            _primaryCamera = _centerEyeTransform.gameObject.AddComponent <Camera>();
            switch (platform)
            {
            case VRPlatform.OculusMobile:
            case VRPlatform.OculusPC:
                _cameraMode = CameraMode.Single;
                _baseCamera = _primaryCamera.gameObject.AddComponent <TBCameraOculus>();
                break;

            case VRPlatform.SteamVR:
                _cameraMode = CameraMode.Single;
                _baseCamera = _primaryCamera.gameObject.AddComponent <TBSteamVRCamera>();
                break;

                #if TB_HAS_UNITY_PS4
            case VRPlatform.PlayStationVR:
                _cameraMode = CameraMode.Single;
                _baseCamera = _primaryCamera.gameObject.AddComponent <TBCameraPSVR>();
                break;
                #endif
            case VRPlatform.Daydream:
                _cameraMode = CameraMode.Single;
                _baseCamera = _primaryCamera.gameObject.AddComponent <TBCameraGoogle>();
                break;

            default:
                _cameraMode = CameraMode.Single;
                _baseCamera = _primaryCamera.gameObject.AddComponent <TBCameraBase>();
                break;
            }
            _baseCamera.Initialize();

            if (TBTracking.OnNodeConnected != null)
            {
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.CenterEye, _centerEyeTransform);
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.Head, _centerEyeTransform);
                TBTracking.OnNodeConnected(UnityEngine.XR.XRNode.TrackingReference, _trackingVolume);
            }

            _trackingVolume.localScale = Vector3.one;
        }