Exemplo n.º 1
0
 private void OnEnable()
 {
     #if !UNITY_EDITOR
     Destroy(gameObject);
     #endif
     instance       = this;
     _camera        = GetComponent <Camera>();
     _toggleObjects = FindObjectsOfType <TBScreenshotToggle>();
 }
Exemplo n.º 2
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();
            }
        }