Example #1
0
        public virtual void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            instance       = this;
            _initialized   = true;
            _startingScale = transform.localScale.x;
            TBLogging.LogMessage("Assigned new TBCameraRig instance...");
            ReadInitialCameraSettings();
            if (TBCore.GetActivePlatform() != VRPlatform.None)
            {
                _trackingVolume = new GameObject().transform;
                _trackingVolume.gameObject.name = "Tracking Volume";
                _trackingVolume.MakeZeroedChildOf(transform);
            }
            SetupCameraForPlatform(TBCore.GetActivePlatform());

            if (_useBlackoutSphere)
            {
                _blackoutSphere = (Instantiate(Resources.Load("BlackoutSphere")) as GameObject).transform;
                _blackoutSphere.gameObject.SetActive(false);
                _blackoutSphere.SetParent(_centerEyeTransform);
                _blackoutSphere.localScale    = Vector3.one * 2;
                _blackoutSphere.localPosition = Vector3.zero;
            }
        }
Example #2
0
 private void InitializeCameraAndTracking(TBCameraRig rig)
 {
     if (rig == null)
     {
         TBLogging.LogMessage("TBCameraRig wasn't found at startup. Waiting for TBCameraRig instance.");
         StartCoroutine(WaitForCameraRig());
     }
     else
     {
         rig.Initialize();
         TBTracking.Initialize();
     }
 }
Example #3
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);
            }
        }
Example #4
0
        void Awake()
        {
            instance  = this;
            transform = GetComponent <Transform> ();

            TBHMDSettings.InitializeHMDSettings();

            // Choose which camera we should be using based on what platform we're on.
            ChooseCamera();

            if (cameraObject != gameObject)
            {
                cameraObject.transform.parent        = transform;
                cameraObject.transform.localPosition = Vector3.zero;
                cameraObject.transform.localRotation = Quaternion.identity;
            }

            switch (cameraMode)
            {
            case TBCameraMode.Single:                 // For fancy systems that only show one camera in Unity, like the native integrations.
                centerCamera = centerEye.GetComponent <Camera> ();
                SyncCameraSettings(centerCamera);
                break;

            case TBCameraMode.Dual:                   // For legacy systems that use two cameras in the editor.
                leftCamera  = leftEye.GetComponent <Camera> ();
                rightCamera = rightEye.GetComponent <Camera> ();
                SyncCameraSettings(leftCamera);
                SyncCameraSettings(rightCamera);
                break;
            }

            #if UNITY_EDITOR
            // Setup the screenshot camera. If no screenshot camera already exists, try to create one.
            if (FindObjectOfType <TBScreenshotCamera>() != null)
            {
                TBScreenshotCamera = FindObjectOfType <TBScreenshotCamera>();
            }
            else if (TBScreenshotCamera != null)
            {
                TBScreenshotCamera = Instantiate(TBScreenshotCamera).gameObject.GetComponent <TBScreenshotCamera>();
            }

            // Apply settings to the screenshot camera if it was created.
            if (TBScreenshotCamera != null)
            {
                _screenshotCamera = TBScreenshotCamera.gameObject.GetComponent <Camera>();
                SyncCameraSettings(_screenshotCamera);
                TBScreenshotCamera.transform.position = transform.position;
                TBScreenshotCamera.transform.rotation = transform.rotation;
                TBScreenshotCamera.gameObject.SetActive(false);
            }
            #endif

            // Create TBCenter, the anchor transfom to use if you need to get the camera's position.
            TBCenter = new GameObject().transform;
            TBCenter.gameObject.name = "TBCenter";
            TBCenter.MakeZeroedChildOf(centerEye.transform);

            // If there is no audio listener on the instantiated camera, add one to TBCenter.
            if (GetComponentInChildren <AudioListener>() == null)
            {
                TBCenter.gameObject.AddComponent <AudioListener>();
            }

            if (recenterOnLoad)
            {
                CalibrateCameraPosition();
            }
        }