//Copyright(c) Microsoft Corporation.
// Licensed under the MIT License.
using UnityEngine;
using UnityEditor;
namespace Microsoft.MixedReality.GraphicsTools.Editor
{
///
/// Draws a customer decorator drawer that displays a help box with rich text tagging implementation as experimental.
///
[CustomPropertyDrawer(typeof(ExperimentalAttribute))]
public class ExperimentalPropertyDrawer : DecoratorDrawer
{
// Cached height calculated in OnGUI
private float lastHeight = 18;
///
/// Unity calls this function to draw the GUI.
///
/// Rectangle to display the GUI in
public override void OnGUI(Rect position)
{
var experimental = attribute as ExperimentalAttribute;
if (experimental != null)
{
var defaultValue = EditorStyles.helpBox.richText;
EditorStyles.helpBox.richText = true;
EditorGUI.HelpBox(position, experimental.Text, MessageType.Warning);
EditorStyles.helpBox.richText = defaultValue;
lastHeight = EditorStyles.helpBox.CalcHeight(new GUIContent(experimental.Text), EditorGUIUtility.currentViewWidth);
}
}
///
/// Returns the height required to display UI elements drawn by OnGUI.
///
/// The height required by OnGUI.
public override float GetHeight()
{
var experimental = attribute as ExperimentalAttribute;
if (experimental != null)
{
return lastHeight;
}
return base.GetHeight();
}
}
}