43 lines
1.6 KiB
C#
43 lines
1.6 KiB
C#
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.Video;
|
|
|
|
[CustomPropertyDrawer(typeof(VideoPlayerClip))]
|
|
public class VideoPlayerClipDrawer : PropertyDrawer
|
|
{
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
EditorGUI.BeginProperty(position, label, property);
|
|
|
|
var videoClipProp = property.FindPropertyRelative("videoClip");
|
|
var speedProp = property.FindPropertyRelative("playbackSpeed");
|
|
|
|
float lineHeight = EditorGUIUtility.singleLineHeight;
|
|
float spacing = EditorGUIUtility.standardVerticalSpacing;
|
|
|
|
Rect rect = new Rect(position.x, position.y, position.width, lineHeight);
|
|
|
|
EditorGUI.PropertyField(rect, videoClipProp);
|
|
rect.y += lineHeight + spacing;
|
|
|
|
if (videoClipProp.objectReferenceValue != null)
|
|
{
|
|
VideoClip clip = videoClipProp.objectReferenceValue as VideoClip;
|
|
EditorGUI.LabelField(rect, $"Duration: {clip.length:F2}s | FPS: {clip.frameRate:F1} | Frames: {clip.frameCount}");
|
|
rect.y += lineHeight + spacing;
|
|
}
|
|
|
|
EditorGUI.PropertyField(rect, speedProp);
|
|
|
|
EditorGUI.EndProperty();
|
|
}
|
|
|
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
{
|
|
var videoClipProp = property.FindPropertyRelative("videoClip");
|
|
int lines = videoClipProp.objectReferenceValue != null ? 3 : 2;
|
|
return EditorGUIUtility.singleLineHeight * lines + EditorGUIUtility.standardVerticalSpacing * (lines - 1);
|
|
}
|
|
}
|
|
#endif |