/// <summary>
    /// Waits for all displays to be initialized, then repositions camera viewports and/or sets up post processing
    /// </summary>
    void Update()
    {
        if (!_initialized)
        {
            bool displaysInitialized = true;
            for (int i = 0; i < displays.Count; i++)
            {
                if (!displays[i].gameObject.activeSelf)
                {
                    continue;
                }

                if (displays[i].enabled && !displays[i].Initialized())
                {
                    displaysInitialized = false;
                    break;
                }
                PhysicalDisplayCalibration cali = displays[i].gameObject.GetComponent <PhysicalDisplayCalibration>();
                if (cali != null && !cali.Initialized())
                {
                    displaysInitialized = false;
                    break;
                }
            }
            //wait until every other display is initialized

            if (displaysInitialized)
            {
                for (int i = 0; i < displays.Count; i++)
                {
                    PhysicalDisplay display = displays[i];

                    PhysicalDisplayCalibration cali = display.gameObject.GetComponent <PhysicalDisplayCalibration>();
                    if (cali == null)
                    {
                        if (!display.useRenderTextures)
                        {
                            if (display.dualPipe)
                            {
                                Vector2Int windowSpaceOffset = display.dualInstance ? new Vector2Int(0, 0) : new Vector2Int(display.windowBounds.x, display.windowBounds.y);
                                display.leftCam.pixelRect = new Rect(
                                    windowSpaceOffset.x + display.leftViewport.x,
                                    windowSpaceOffset.y + display.leftViewport.y,
                                    display.leftViewport.width,
                                    display.leftViewport.height);
                                display.rightCam.pixelRect = new Rect(
                                    windowSpaceOffset.x + display.rightViewport.x,
                                    windowSpaceOffset.y + display.rightViewport.y,
                                    display.rightViewport.width,
                                    display.rightViewport.height);
                            }
                            else
                            {
                                //if stereo blit is enabled, only update the viewport of the center cam (in the future perhaps consolidate this logic with useRenderTextures)
                                if (display.centerCam != null && display.centerCam.GetComponent <StereoBlit>() != null)
                                {
                                    display.centerCam.pixelRect = new Rect(display.windowBounds.x, display.windowBounds.y, display.windowBounds.width, display.windowBounds.height);
                                }
                                else
                                {
                                    foreach (Camera cam in display.GetAllCameras())
                                    {
                                        Debug.Log("Manager [" + name + "] set Camera [" + cam.name + "] viewport to <"
                                                  + display.windowBounds.x + ", " + display.windowBounds.y + ", " + display.windowBounds.width + ", " + display.windowBounds.height + ">");
                                        cam.pixelRect = new Rect(display.windowBounds.x, display.windowBounds.y, display.windowBounds.width, display.windowBounds.height);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //special case for PhysicalDisplayCalibration
                        //Debug.Log("Display:");
                        foreach (Camera cam in cali.postCams)
                        {
                            Rect r = new Rect(display.windowBounds.x, display.windowBounds.y, display.windowBounds.width, display.windowBounds.height);
                            //Debug.Log("Set cam " + cam.name + " to " + r);
                            cam.pixelRect = r;
                        }
                    }
                }

                _initialized = true;
            }
        }
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!_initialized)
        {
            bool displaysInitialized = true;
            for (int i = 0; i < displays.Count; i++)
            {
                if (displays[i].gameObject.activeSelf && displays[i].enabled && !displays[i].Initialized())
                {
                    displaysInitialized = false;
                    break;
                }
                PhysicalDisplayCalibration cali = displays[i].gameObject.GetComponent <PhysicalDisplayCalibration>();
                if (cali != null && !cali.Initialized())
                {
                    displaysInitialized = false;
                    break;
                }
            }
            //wait until every other display is initialized

            if (displaysInitialized)
            {
                for (int i = 0; i < displays.Count; i++)
                {
                    PhysicalDisplay display = displays[i];

                    PhysicalDisplayCalibration cali = display.gameObject.GetComponent <PhysicalDisplayCalibration>();
                    if (cali == null)
                    {
                        if (!display.useRenderTextures)
                        {
                            if (display.dualPipe)
                            {
                                Vector2Int windowSpaceOffset = display.dualInstance ? new Vector2Int(0, 0) : new Vector2Int(display.windowBounds.x, display.windowBounds.y);
                                display.leftCam.pixelRect = new Rect(
                                    windowSpaceOffset.x + display.leftViewport.x,
                                    windowSpaceOffset.y + display.leftViewport.y,
                                    display.leftViewport.width,
                                    display.leftViewport.height);
                                display.rightCam.pixelRect = new Rect(
                                    windowSpaceOffset.x + display.rightViewport.x,
                                    windowSpaceOffset.y + display.rightViewport.y,
                                    display.rightViewport.width,
                                    display.rightViewport.height);
                            }
                            else
                            {
                                foreach (Camera cam in display.GetAllCameras())
                                {
                                    Debug.Log("Manager [" + name + "] set Camera [" + cam.name + "] viewport to <"
                                              + display.windowBounds.x + ", " + display.windowBounds.y + ", " + display.windowBounds.width + ", " + display.windowBounds.height + ">");
                                    cam.pixelRect = new Rect(display.windowBounds.x, display.windowBounds.y, display.windowBounds.width, display.windowBounds.height);
                                }
                            }
                        }
                    }
                    else
                    {
                        //special case for PhysicalDisplayCalibration
                        Debug.Log("Display:");
                        foreach (Camera cam in cali.postCams)
                        {
                            cam.pixelRect = new Rect(display.windowBounds.x, display.windowBounds.y, display.windowBounds.width, display.windowBounds.height);
                        }
                    }
                }



                _initialized = true;
            }
        }
    }