/// <summary> /// Reposition window (takes multiple frames to complete) /// </summary> void Update() { if (!updatedViewports && WindowsUtils.CompletedOperation()) { //we must also defer setting the camera viewports until the screen has the correct resolution if (dualPipe && !dualInstance) { leftCam.pixelRect = new Rect(leftViewport.x, leftViewport.y, leftViewport.width, leftViewport.height); rightCam.pixelRect = new Rect(rightViewport.x, rightViewport.y, rightViewport.width, rightViewport.height); } updatedViewports = true; } }
/// <summary> /// Disable this object if it shouldn't be active /// Otherwise, create and assign cameras, reposition window, etc /// </summary> void Start() { centerCam = null; leftCam = null; rightCam = null; if (loadSettingsAtRuntime) { Debug.Log("Attempting to Load Settings for Display: " + gameObject.name); TryToDeSerialize(serializedLocation); } if (!ShouldBeActive()) { Debug.Log("Deactivating Display: " + gameObject.name); gameObject.SetActive(false); return; } Debug.Log("Display Active: " + gameObject.name); foreach (string er in GetSettingsErrors()) { Debug.Log("Display Warning for Display: " + gameObject.name + ": " + er); } if (head == null) { Debug.Log("Display Error for Display: " + gameObject.name + ": Physical Display has no head object"); } initialized = true; if (exclusiveFullscreen) { if (display < Display.displays.Length) { Display.displays[display].Activate(); } else { Debug.Log("Display Error for Display: " + gameObject.name + ": Physical Display uses display index " + display + " but Unity does not detect that many displays"); } } if (!exclusiveFullscreen) { Debug.Log("Setting Display: " + gameObject.name + " to Windowed Mode..."); if (!is3D || useXRCameras) { centerCam = head.CreateEye(HeadConfiguration.Eyes.Center, gameObject.name); if (useXRCameras) { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); StereoBlit blit = centerCam.gameObject.AddComponent <StereoBlit>(); blit.lcam = leftCam; blit.rcam = rightCam; Debug.Log("Created dummy cams"); } Debug.Log("Setting Display: " + gameObject.name + " to Non-3D Windowed"); #if UNITY_STANDALONE_WIN if (manager == null) { WindowsUtils.SetMyWindowInfo("Non-3D Windowed", windowBounds.x, windowBounds.y, windowBounds.width, windowBounds.height, 441, 411); } #endif } else { if (!dualPipe && !dualInstance) { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); Debug.Log("Setting Display: " + gameObject.name + " to Quad Buffer 3D Windowed"); #if UNITY_STANDALONE_WIN if (manager == null) { WindowsUtils.SetMyWindowInfo("Quad Buffer 3D Windowed", windowBounds.x, windowBounds.y, windowBounds.width, windowBounds.height, 421, 420); } #endif } else if (dualPipe && !dualInstance) { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); Debug.Log("Setting Display: " + gameObject.name + " to Dual-Eye Dual-Pipe-3D Windowed"); #if UNITY_STANDALONE_WIN if (manager == null) { WindowsUtils.SetMyWindowInfo("Dual-Eye Dual-Pipe-3D Windowed", windowBounds.x, windowBounds.y, windowBounds.width, windowBounds.height, 422, 398); } #endif } else if (dualPipe && dualInstance) { if (Util.GetArg("eye") == "left") { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); Debug.Log("Setting Display: " + gameObject.name + " to Left-Eye Dual-Pipe-3D Windowed"); #if UNITY_STANDALONE_WIN if (manager == null) { WindowsUtils.SetMyWindowInfo("Left-Eye Dual-Pipe-3D Windowed", leftViewport.x, leftViewport.y, leftViewport.width, leftViewport.height, 300, 367); } #endif } else if (Util.GetArg("eye") == "right") { rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); Debug.Log("Setting Display: " + gameObject.name + " to Right-Eye Dual-Pipe-3D Windowed"); #if UNITY_STANDALONE_WIN if (manager == null) { WindowsUtils.SetMyWindowInfo("Right-Eye Dual-Pipe-3D Windowed", rightViewport.x, rightViewport.y, rightViewport.width, rightViewport.height, 342, 498); } #endif } } } } else { if (!is3D || useXRCameras) { centerCam = head.CreateEye(HeadConfiguration.Eyes.Center, gameObject.name); if (useXRCameras) { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); StereoBlit blit = centerCam.gameObject.AddComponent <StereoBlit>(); blit.lcam = leftCam; blit.rcam = rightCam; Debug.Log("Created dummy cams"); } } else { if (!dualPipe && !dualInstance) { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); } else if (dualPipe && !dualInstance) { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); } else if (dualPipe && dualInstance) { if (Util.GetArg("eye") == "left") { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); } else if (Util.GetArg("eye") == "right") { rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); } } } } if (useRenderTextures) { if (leftCam != null) { leftTex = new RenderTexture(renderTextureSize.x, renderTextureSize.y, 0); leftCam.targetTexture = leftTex; leftTex.name = Util.ObjectFullName(leftCam.gameObject) + " Target Tex"; } if (centerCam != null) { centerTex = new RenderTexture(renderTextureSize.x, renderTextureSize.y, 0); centerCam.targetTexture = centerTex; centerTex.name = Util.ObjectFullName(centerCam.gameObject) + " Target Tex"; } if (rightCam != null) { rightTex = new RenderTexture(renderTextureSize.x, renderTextureSize.y, 0); rightCam.targetTexture = rightTex; rightTex.name = Util.ObjectFullName(rightCam.gameObject) + " Target Tex"; } } if (exclusiveFullscreen) { if (leftCam != null) { leftCam.targetDisplay = display; } if (centerCam != null) { centerCam.targetDisplay = display; } if (rightCam != null) { rightCam.targetDisplay = display; } } #if UNITY_EDITOR if (rightCam == null && leftCam == null && centerCam == null) { if (!is3D || useXRCameras) { centerCam = head.CreateEye(HeadConfiguration.Eyes.Center, gameObject.name); } else { leftCam = head.CreateEye(HeadConfiguration.Eyes.Left, gameObject.name); rightCam = head.CreateEye(HeadConfiguration.Eyes.Right, gameObject.name); } } #endif }