/// <summary>
    /// Render the dialog according to the context.
    /// </summary>
    void OnGUI() {
        // Close the window if Option0String is empty.
        // After Unity reload assemblies, the EditorWindow will remain open but all the content
        // in the dialog will be cleared because dialogContext is not serializable. Therefore,
        // close the dialog after assembly reload. Close in the next editor frame or it may
        // generate error message like "OpenGL Context became invalid during rendering".
        // This is for Unity 5.
        if (String.IsNullOrEmpty(dialogContext.Option0String) && !terminating) {
            terminating = true;
            RunOnMainThread.Run(() => {
                Close();
            }, runNow: false);
        }

        InitializeStyles();

        Rect rect = EditorGUILayout.BeginVertical();

        if (!String.IsNullOrEmpty(dialogContext.Title)) {
            GUILayout.Label(dialogContext.Title, EditorStyles.boldLabel);
            EditorGUILayout.Space();
        }

        // Render the dialog message.
        GUILayout.Label(dialogContext.Message, DefaultMessageStyle);
        EditorGUILayout.Space();

        // Render the additional context.
        if (dialogContext.RenderContentAction != null) {
            dialogContext.RenderContentAction(this);
            EditorGUILayout.Space();
        }

        EditorGUILayout.BeginHorizontal();
        // Render additional buttons before the option buttons.
        if (dialogContext.RenderButtonsAction != null) {
            dialogContext.RenderButtonsAction(this);
        }
        // Render option buttons.
        RenderOptionButtons();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.EndVertical();

        // Adjust the dialog window size according to the rendered content.
        // Rect returned by BeginVertical() can be zeroes for a couple of frames, therefore
        // ignoring resizing for those frames.
        if (rect.width != 0.0f && rect.height != 0.0f) {
            // Additional space at the bottom of the window.
            const float FILLER_WINDOWS_HEIGHT = 15.0f;
            float windowHeight = rect.height + FILLER_WINDOWS_HEIGHT;
            minSize = new Vector2(dialogContext.WindowWidth, windowHeight);
            maxSize = new Vector2(dialogContext.WindowWidth, windowHeight);
        }
    }