//===================================================================================================== // Functions //===================================================================================================== /// <summary> /// Initializes side-by-side rendering and head tracking. /// </summary> public void Awake() { //Adding head head = GameObject.Find("ALPSHead"); if (head == null) { head = new GameObject("ALPSHead"); } head.transform.parent = transform; head.transform.position = transform.position; #if UNITY_EDITOR head.AddComponent(typeof(MouseLook)); #else head.AddComponent(typeof(ALPSGyro)); #endif for (var i = 0; i < 2; i++) { bool left = (i == 0); GameObject OneCamera = GameObject.Find(left?"CameraLeft":"CameraRight"); if (OneCamera == null) { OneCamera = new GameObject(left?"CameraLeft":"CameraRight"); } OneCamera.GetComponent <Camera>().rect = new Rect((left?0:0.5f), 0, 0.5f, 1); OneCamera.transform.parent = head.transform; Vector3 OneCamPos = head.transform.position; OneCamPos.z = ALPSConfig.neckPivotToEye.x * 0.001f; OneCamPos.y = ALPSConfig.neckPivotToEye.y * 0.001f; OneCamera.transform.position = OneCamPos; if (left) { cameraLeft = OneCamera; } else { cameraRight = OneCamera; } } AudioListener[] listeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[]; if (listeners.Length < 1) { gameObject.AddComponent(typeof(AudioListener)); } ClearDirty(); }
//===================================================================================================== // Functions //===================================================================================================== /// <summary> /// Initializes side-by-side rendering and head tracking. /// </summary> public void Awake() { cameraRender = GetComponent <Camera> (); PropagateConfig(); ALPSGUI.controller = this; head = GameObject.Find("ALPSHead"); if (head == null) { head = new GameObject("ALPSHead"); } head.transform.parent = transform; head.transform.position = transform.position; #if UNITY_EDITOR head.AddComponent(typeof(MouseLook)); screenWidthPix = Screen.width; screenHeightPix = Screen.height; #elif UNITY_ANDROID head.AddComponent(typeof(ALPSGyro)); Screen.orientation = ScreenOrientation.LandscapeLeft; ALPSAndroid.Init(); screenWidthPix = ALPSAndroid.WidthPixels(); screenHeightPix = ALPSAndroid.HeightPixels(); #endif //Make sure the longer dimension is width as the phone is always in landscape mode if (screenWidthPix < screenHeightPix) { int tmp = screenHeightPix; screenHeightPix = screenWidthPix; screenWidthPix = tmp; } for (var i = 0; i < 2; i++) { bool left = (i == 0); GameObject OneCamera = GameObject.Find(left?"CameraLeft":"CameraRight"); if (OneCamera == null) { OneCamera = new GameObject(left?"CameraLeft":"CameraRight"); } if (OneCamera.GetComponent <Camera>() == null) { OneCamera.AddComponent(typeof(Camera)); } if (OneCamera.GetComponent <ALPSCamera>() == null) { OneCamera.AddComponent(typeof(ALPSCamera)); } (OneCamera.GetComponent("ALPSCamera") as ALPSCamera).leftEye = left; OneCamera.transform.parent = head.transform; OneCamera.transform.position = head.transform.position; if (left) { cameraLeft = OneCamera; } else { cameraRight = OneCamera; } } ALPSCamera[] ALPSCameras = FindObjectsOfType(typeof(ALPSCamera)) as ALPSCamera[]; foreach (ALPSCamera cam in ALPSCameras) { cam.Init(); } mat = Resources.Load("Materials/ALPSDistortion") as Material; DPI = Screen.dpi; //Render Textures srcTex = new RenderTexture(2048, 1024, 16); destTex = cameraRender.targetTexture; cameraLeft.GetComponent <Camera>().targetTexture = cameraRight.GetComponent <Camera>().targetTexture = srcTex; // Setting the main camera cameraRender.aspect = 1f; cameraRender.backgroundColor = Color.black; cameraRender.clearFlags = CameraClearFlags.Nothing; cameraRender.cullingMask = 0; cameraRender.eventMask = 0; cameraRender.orthographic = true; cameraRender.renderingPath = RenderingPath.Forward; cameraRender.useOcclusionCulling = false; cameraLeft.GetComponent <Camera>().depth = 0; cameraRight.GetComponent <Camera>().depth = 1; cameraRender.depth = Mathf.Max(cameraLeft.GetComponent <Camera>().depth, cameraRight.GetComponent <Camera>().depth) + 1; cameraLeft.gameObject.AddComponent(typeof(ALPSCrosshairs)); cameraRight.gameObject.AddComponent(typeof(ALPSCrosshairs)); AudioListener[] listeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[]; if (listeners.Length < 1) { gameObject.AddComponent(typeof(AudioListener)); } ClearDirty(); }