Пример #1
0
    // GUI

    /// <summary>
    /// Raises the GU event.
    /// </summary>
    void OnGUI()
    {
        // Important to keep from skipping render events
        if (Event.current.type != EventType.Repaint)
        {
            return;
        }

        // Fade in screen
        if (AlphaFadeValue > 0.0f)
        {
            AlphaFadeValue -= Mathf.Clamp01(Time.deltaTime / FadeInTime);
            if (AlphaFadeValue < 0.0f)
            {
                AlphaFadeValue = 0.0f;
            }
            else
            {
                GUI.color = new Color(0, 0, 0, AlphaFadeValue);
                GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), FadeInTexture);
                return;
            }
        }

        // We can turn on the render object so we can render the on-screen menu
        if (GUIRenderObject != null)
        {
            if (ScenesVisible ||
                ShowVRVars ||
                Crosshair.IsCrosshairVisible() ||
                RiftPresentTimeout > 0.0f ||
                DeviceDetectionTimeout > 0.0f ||
                VisionGuide.GetFadeAlphaValue() > 0.0f)
            {
                GUIRenderObject.SetActive(true);
            }
            else
            {
                GUIRenderObject.SetActive(false);
            }
        }

        //***
        // Set the GUI matrix to deal with portrait mode
        Vector3   scale = Vector3.one;
        Matrix4x4 svMat = GUI.matrix;         // save current matrix

        // substitute matrix - only scale is altered from standard
        GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);

        // Cache current active render texture
        RenderTexture previousActive = RenderTexture.active;

        // if set, we will render to this texture
        if (GUIRenderTexture != null)
        {
            RenderTexture.active = GUIRenderTexture;
            GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));
        }

        // Update OVRGUI functions (will be deprecated eventually when 2D renderingc
        // is removed from GUI)
        GuiHelper.SetFontReplace(FontReplace);

        // If true, we are displaying information about the Rift not being detected
        // So do not show anything else
        if (GUIShowRiftDetected() != true)
        {
            GUIShowLevels();
            GUIShowVRVariables();
        }

        // The cross-hair may need to go away at some point, unless someone finds it
        // useful
        Crosshair.OnGUICrosshair();

        // Since we want to draw into the main GUI that is shared within the MainMenu,
        // we call the OVRVisionGuide GUI function here
        VisionGuide.OnGUIVisionGuide();

        // Restore active render texture
        RenderTexture.active = previousActive;

        // ***
        // Restore previous GUI matrix
        GUI.matrix = svMat;
    }