51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
[CustomPropertyDrawer(typeof(CircularBuffer<>))]
|
|
public class CircularBufferDrawer : PropertyDrawer
|
|
{
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
|
|
EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
|
|
|
EditorGUI.indentLevel++;
|
|
|
|
SerializedProperty bufferSizeProp = property.FindPropertyRelative("bufferSize");
|
|
int bufferSize = bufferSizeProp.intValue;
|
|
|
|
EditorGUI.PropertyField(
|
|
new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight),
|
|
bufferSizeProp);
|
|
|
|
SerializedProperty bufferProp = property.FindPropertyRelative("buffer");
|
|
|
|
EditorGUI.LabelField(
|
|
new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 2, position.width, EditorGUIUtility.singleLineHeight),
|
|
"Buffer Elements");
|
|
|
|
float lineHeight = EditorGUIUtility.singleLineHeight;
|
|
float bufferHeight = lineHeight * bufferSize;
|
|
|
|
Rect bufferRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 3, position.width, bufferHeight);
|
|
|
|
EditorGUI.PropertyField(bufferRect, bufferProp, GUIContent.none, true);
|
|
|
|
EditorGUI.indentLevel--;
|
|
|
|
EditorGUI.EndProperty();
|
|
}
|
|
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
{
|
|
SerializedProperty bufferSizeProp = property.FindPropertyRelative("bufferSize");
|
|
int bufferSize = bufferSizeProp.intValue;
|
|
|
|
return EditorGUIUtility.singleLineHeight * (bufferSize + 3); // 1 for buffer size, 1 for label, and bufferSize for buffer elements
|
|
}
|
|
}
|
|
|
|
#endif
|