// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEditor;
using UnityEngine;
namespace Microsoft.MixedReality.Toolkit.Editor
{
///
/// A collection of shared functionality for MRTK shader GUIs.
///
public static class MixedRealityToolkitShaderGUIUtilities
{
///
/// GUI content styles which are common among shader GUIs.
///
public static class Styles
{
public static readonly GUIContent DepthWriteWarning = new GUIContent("Warning: Depth buffer sharing is enabled for this project, but this material does not write depth. Enabling depth will improve reprojection, but may cause rendering artifacts in translucent materials.");
public static readonly GUIContent DepthWriteFixNowButton = new GUIContent("Fix Now", "Enables Depth Write For This Material");
}
///
/// Displays a depth write warning and fix button if depth buffer sharing is enabled.
///
/// The material editor to display the warning in.
/// The title of the dialog window to display when the user selects the fix button.
/// The message in the dialog window when the user selects the fix button.
/// True if the user opted to fix the warning, false otherwise.
public static bool DisplayDepthWriteWarning(MaterialEditor materialEditor, string dialogTitle = "Depth Write", string dialogMessage = "Change this material to write to the depth buffer?")
{
bool dialogConfirmed = false;
if (MixedRealityOptimizeUtils.IsDepthBufferSharingEnabled())
{
var defaultValue = EditorStyles.helpBox.richText;
EditorStyles.helpBox.richText = true;
if (materialEditor.HelpBoxWithButton(Styles.DepthWriteWarning, Styles.DepthWriteFixNowButton))
{
if (EditorUtility.DisplayDialog(dialogTitle, dialogMessage, "Yes", "No"))
{
dialogConfirmed = true;
}
}
EditorStyles.helpBox.richText = defaultValue;
}
return dialogConfirmed;
}
}
}