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