multiple xr toolkit package
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VRC_SyncVideoPlayerEditor.cs 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditorInternal;
  6. [CustomPropertyDrawer(typeof(VRCSDK2.VRC_SyncVideoPlayer.VideoEntry))]
  7. public class CustomVideoEntryDrawer : PropertyDrawer
  8. {
  9. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  10. {
  11. SerializedProperty source = property.FindPropertyRelative("Source");
  12. SerializedProperty ratio = property.FindPropertyRelative("AspectRatio");
  13. SerializedProperty speed = property.FindPropertyRelative("PlaybackSpeed");
  14. SerializedProperty clip = property.FindPropertyRelative("VideoClip");
  15. SerializedProperty url = property.FindPropertyRelative("URL");
  16. return EditorGUI.GetPropertyHeight(source, new GUIContent("Source"), true) + EditorGUIUtility.standardVerticalSpacing
  17. + EditorGUI.GetPropertyHeight(ratio, new GUIContent("Aspect Ratio"), true) + EditorGUIUtility.standardVerticalSpacing
  18. + EditorGUI.GetPropertyHeight(speed, new GUIContent("Playback Speed"), true) + EditorGUIUtility.standardVerticalSpacing
  19. + Mathf.Max(EditorGUI.GetPropertyHeight(clip, new GUIContent("VideoClip"), true), EditorGUI.GetPropertyHeight(url, new GUIContent("URL"), true)) + EditorGUIUtility.standardVerticalSpacing;
  20. }
  21. public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
  22. {
  23. SerializedProperty source = property.FindPropertyRelative("Source");
  24. SerializedProperty ratio = property.FindPropertyRelative("AspectRatio");
  25. SerializedProperty speed = property.FindPropertyRelative("PlaybackSpeed");
  26. SerializedProperty clip = property.FindPropertyRelative("VideoClip");
  27. SerializedProperty url = property.FindPropertyRelative("URL");
  28. EditorGUI.BeginProperty(rect, label, property);
  29. float x = rect.x;
  30. float y = rect.y;
  31. float w = rect.width;
  32. float h = EditorGUI.GetPropertyHeight(source, new GUIContent("Source"), true) + EditorGUIUtility.standardVerticalSpacing;
  33. VRCSDK2.VRC_EditorTools.FilteredEnumPopup<UnityEngine.Video.VideoSource>(new Rect(x, y, w, h), source, (e) => e == UnityEngine.Video.VideoSource.Url);
  34. y += h;
  35. if (source.enumValueIndex == (int)UnityEngine.Video.VideoSource.Url)
  36. {
  37. h = EditorGUI.GetPropertyHeight(url, new GUIContent("URL"), true) + EditorGUIUtility.standardVerticalSpacing;
  38. EditorGUI.PropertyField(new Rect(x, y, w, h), url);
  39. y += h;
  40. }
  41. else
  42. {
  43. h = EditorGUI.GetPropertyHeight(clip, new GUIContent("VideoClip"), true) + EditorGUIUtility.standardVerticalSpacing;
  44. EditorGUI.PropertyField(new Rect(x, y, w, h), clip);
  45. y += h;
  46. }
  47. h = EditorGUI.GetPropertyHeight(ratio, new GUIContent("AspectRatio"), true) + EditorGUIUtility.standardVerticalSpacing;
  48. EditorGUI.PropertyField(new Rect(x, y, w, h), ratio);
  49. y += h;
  50. h = EditorGUI.GetPropertyHeight(ratio, new GUIContent("Playback Speed"), true) + EditorGUIUtility.standardVerticalSpacing;
  51. EditorGUI.PropertyField(new Rect(x, y, w, h), speed);
  52. if (speed.floatValue == 0f)
  53. speed.floatValue = 1f;
  54. y += h;
  55. EditorGUI.EndProperty();
  56. }
  57. }
  58. [CustomEditor(typeof(VRCSDK2.VRC_SyncVideoPlayer))]
  59. public class SyncVideoPlayerEditor : Editor
  60. {
  61. ReorderableList sourceList;
  62. public override void OnInspectorGUI()
  63. {
  64. SerializedProperty searchRoot = serializedObject.FindProperty("VideoSearchRoot");
  65. EditorGUILayout.PropertyField(searchRoot);
  66. SerializedProperty maxQual = serializedObject.FindProperty("MaxStreamQuality");
  67. EditorGUILayout.PropertyField(maxQual);
  68. EditorGUILayout.Space();
  69. sourceList.DoLayoutList();
  70. serializedObject.ApplyModifiedProperties();
  71. }
  72. private void OnEnable()
  73. {
  74. SerializedProperty videos = serializedObject.FindProperty("Videos");
  75. sourceList = new ReorderableList(serializedObject, videos);
  76. sourceList.drawElementCallback += (Rect rect, int index, bool active, bool focused) =>
  77. {
  78. EditorGUI.PropertyField(rect, serializedObject.FindProperty("Videos").GetArrayElementAtIndex(index));
  79. };
  80. sourceList.elementHeightCallback += (int index) =>
  81. {
  82. SerializedProperty element = serializedObject.FindProperty("Videos").GetArrayElementAtIndex(index);
  83. return EditorGUI.GetPropertyHeight(element);
  84. };
  85. sourceList.drawHeaderCallback = (Rect rect) => EditorGUI.LabelField(rect, "Videos");
  86. }
  87. }