using RebootKit.Engine.Foundation; using UnityEditor; using UnityEngine; namespace RebootKitEditor.PropertyDrawers { [CustomPropertyDrawer(typeof(ConstsProperty<>))] public class ConstsPropertyDrawer : PropertyDrawer { const string k_InlineValue = "m_InlineValue"; const string k_Asset = "m_Asset"; const string k_UseInlineValue = "m_UseInlineValue"; public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { SerializedProperty useInlineValue = property.FindPropertyRelative(k_UseInlineValue); SerializedProperty inlineValue = property.FindPropertyRelative(k_InlineValue); SerializedProperty asset = property.FindPropertyRelative(k_Asset); EditorGUI.BeginProperty(position, label, property); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(label, EditorStyles.miniBoldLabel); if (useInlineValue.boolValue) { EditorGUILayout.PropertyField(inlineValue, GUIContent.none); } else { EditorGUILayout.PropertyField(asset, GUIContent.none); } if (GUILayout.Button(useInlineValue.boolValue ? "Inline" : "Asset", GUILayout.MaxWidth(100))) { useInlineValue.boolValue = !useInlineValue.boolValue; } GUILayout.EndHorizontal(); EditorGUI.EndProperty(); } } }