/// <summary> /// Updates navigation state. /// </summary> public void Update() { pitch = head.transform.eulerAngles.x; if (pitch >= ForwardLowerBound && pitch <= ForwardUpperBound) { if (!moving) { if (EnableVibration) { #if UNITY_ANDROID ALPSAndroid.Vibrate(20); #elif UNITY_WP_8_1 ALPSWP8.Vibrate(200); #endif } moving = true; } controller.Move(new Vector3(head.transform.forward.x, 0, head.transform.forward.z) * Time.deltaTime * 20); } else if (pitch >= BackwardUpperBound && pitch <= BackwardLowerBound) { if (!moving) { if (EnableVibration) { #if UNITY_ANDROID ALPSAndroid.Vibrate(20); #elif UNITY_WP_8_1 ALPSWP8.Vibrate(200); #endif } moving = true; } controller.Move(new Vector3(-head.transform.forward.x, 0, -head.transform.forward.z) * Time.deltaTime * 20); } else { if (moving) { moving = false; } } }
/// <summary> /// Updates navigation state. /// </summary> public void Update() { pitch = head.transform.eulerAngles.x; if (pitch >= ForwardLowerBound && pitch <= ForwardUpperBound) { if (Application.platform == RuntimePlatform.Android) { if (!moving) { #if UNITY_ANDROID ALPSAndroid.Vibrate(20); #endif moving = true; } } controller.Move(new Vector3(head.transform.forward.x, 0, head.transform.forward.z) * Time.deltaTime * maxCharacterSpeed); } else if (pitch >= BackwardUpperBound && pitch <= BackwardLowerBound) { if (Application.platform == RuntimePlatform.Android) { if (!moving) { #if UNITY_ANDROID ALPSAndroid.Vibrate(20); #endif moving = true; } } controller.Move(new Vector3(-head.transform.forward.x, 0, -head.transform.forward.z) * Time.deltaTime * maxCharacterSpeed); } else { if (Application.platform == RuntimePlatform.Android) { if (moving) { moving = false; } } } }
//===================================================================================================== // Functions //===================================================================================================== /// <summary> /// Initializes side-by-side rendering and head tracking. /// </summary> public void Awake() { ALPSCamera.deviceConfig = deviceConfig; ALPSBarrelMesh.deviceConfig = deviceConfig; ALPSCrosshairs.deviceConfig = deviceConfig; ALPSGUI.controller = this; head = new GameObject("ALPSHead"); head.transform.parent = transform; head.transform.position = transform.position; #if UNITY_EDITOR head.AddComponent <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(); #elif UNITY_WP_8_1 head.AddComponent(typeof(ALPSGyro)); Screen.orientation = ScreenOrientation.LandscapeLeft; ALPSWP8.Init(); screenWidthPix = ALPSWP8.WidthPixels(); screenHeightPix = ALPSWP8.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 = new GameObject(left?"CameraLeft":"CameraRight"); OneCamera.AddComponent <Camera>(); OneCamera.AddComponent <ALPSCamera>(); OneCamera.GetComponent <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 = GetComponent <Camera>().targetTexture; cameraLeft.GetComponent <Camera>().targetTexture = cameraRight.GetComponent <Camera>().targetTexture = srcTex; // Setting the main camera GetComponent <Camera>().aspect = 1f; GetComponent <Camera>().backgroundColor = Color.black; GetComponent <Camera>().clearFlags = CameraClearFlags.Nothing; GetComponent <Camera>().cullingMask = 0; GetComponent <Camera>().eventMask = 0; GetComponent <Camera>().orthographic = true; GetComponent <Camera>().renderingPath = RenderingPath.Forward; GetComponent <Camera>().useOcclusionCulling = false; cameraLeft.GetComponent <Camera>().depth = 0; cameraRight.GetComponent <Camera>().depth = 1; GetComponent <Camera>().depth = Mathf.Max(cameraLeft.GetComponent <Camera>().depth, cameraRight.GetComponent <Camera>().depth) + 1; cameraLeft.gameObject.AddComponent <ALPSCrosshairs>(); cameraRight.gameObject.AddComponent <ALPSCrosshairs>(); AudioListener[] listeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[]; if (listeners.Length < 1) { gameObject.AddComponent <AudioListener>(); } ClearDirty(); }