//adds or replaces camera in slot i public void SetCamera(HMD.CameraSetup cam, int i) { if (i >= 0 && i < AvailableCameras.Count) { AvailableCameras[i] = cam; } else if (i >= AvailableCameras.Count) { AvailableCameras.Add(cam); } }
//=================================================================================================== //local method to change the dispay type. Should not be called except by OnChangeScreen public void SetHMD(int typeNr) { //check if typeNr is valid if (typeNr < 0 || typeNr > AvailableCameras.Count) { Debug.LogError("Camera index out of range, set camera = 0"); typeNr = 0; } else { Debug.Log("Camera set to " + typeNr); } //check if cammera is not set or something changes if (ActiveCamera == null || AvailableCameras[typeNr] != ActiveCamera) { //check if camera was set if (ActiveCamera != null) { //if yes remove old camera GameObject.Destroy(ActiveCamera.gameObject); } //create new camera ActiveCamera = Instantiate(AvailableCameras[typeNr]) as HMD.CameraSetup; //make the new camera a child of this GameObject ActiveCamera.transform.parent = transform; //set the local position to identity ActiveCamera.transform.localPosition = Vector3.zero; ActiveCamera.transform.localRotation = Quaternion.identity; } //if the camera was set successfully if (ActiveCamera != null) { //find all UIs and set the new camera as the worldCamera UnityEngine.Canvas[] canv = GameObject.FindObjectsOfType <UnityEngine.Canvas>(); for (int i = 0; i < canv.Length; i++) { canv[i].worldCamera = ActiveCamera.MainCamera; } } }