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_SyncVideoStreamEditor.cs 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditorInternal;
  6. [CustomPropertyDrawer(typeof(VRCSDK2.VRC_SyncVideoStream.VideoEntry))]
  7. public class CustomVideoStreamEntryDrawer : PropertyDrawer
  8. {
  9. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  10. {
  11. SerializedProperty source = property.FindPropertyRelative("Source");
  12. SerializedProperty speed = property.FindPropertyRelative("PlaybackSpeed");
  13. SerializedProperty clip = property.FindPropertyRelative("VideoClip");
  14. SerializedProperty url = property.FindPropertyRelative("URL");
  15. SerializedProperty live = property.FindPropertyRelative("SyncType");
  16. SerializedProperty sync = property.FindPropertyRelative("SyncMinutes");
  17. return EditorGUI.GetPropertyHeight(source, new GUIContent("Source"), 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. + EditorGUI.GetPropertyHeight(speed, new GUIContent("SyncType"), true) + EditorGUIUtility.standardVerticalSpacing
  21. + EditorGUI.GetPropertyHeight(speed, new GUIContent("SyncMinutes"), true) + EditorGUIUtility.standardVerticalSpacing;
  22. }
  23. public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
  24. {
  25. SerializedProperty source = property.FindPropertyRelative("Source");
  26. SerializedProperty speed = property.FindPropertyRelative("PlaybackSpeed");
  27. SerializedProperty clip = property.FindPropertyRelative("VideoClip");
  28. SerializedProperty url = property.FindPropertyRelative("URL");
  29. SerializedProperty live = property.FindPropertyRelative("SyncType");
  30. SerializedProperty sync = property.FindPropertyRelative("SyncMinutes");
  31. EditorGUI.BeginProperty(rect, label, property);
  32. float x = rect.x;
  33. float y = rect.y;
  34. float w = rect.width;
  35. float h = EditorGUI.GetPropertyHeight(source, new GUIContent("Source"), true) + EditorGUIUtility.standardVerticalSpacing;
  36. VRCSDK2.VRC_EditorTools.FilteredEnumPopup<UnityEngine.Video.VideoSource>(new Rect(x, y, w, h), source, (e) => e == UnityEngine.Video.VideoSource.Url);
  37. y += h;
  38. if (source.enumValueIndex == (int)UnityEngine.Video.VideoSource.Url)
  39. {
  40. h = EditorGUI.GetPropertyHeight(url, new GUIContent("URL"), true) + EditorGUIUtility.standardVerticalSpacing;
  41. EditorGUI.PropertyField(new Rect(x, y, w, h), url);
  42. y += h;
  43. }
  44. else
  45. {
  46. h = EditorGUI.GetPropertyHeight(clip, new GUIContent("VideoClip"), true) + EditorGUIUtility.standardVerticalSpacing;
  47. EditorGUI.PropertyField(new Rect(x, y, w, h), clip);
  48. y += h;
  49. }
  50. h = EditorGUI.GetPropertyHeight(speed, 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. h = EditorGUI.GetPropertyHeight(live, new GUIContent("SyncType"), true) + EditorGUIUtility.standardVerticalSpacing;
  56. EditorGUI.PropertyField(new Rect(x, y, w, h), live);
  57. y += h;
  58. h = EditorGUI.GetPropertyHeight(sync, new GUIContent("SyncMinutes"), true) + EditorGUIUtility.standardVerticalSpacing;
  59. EditorGUI.PropertyField(new Rect(x, y, w, h), sync);
  60. if (sync.floatValue < 1f)
  61. sync.floatValue = 0;
  62. y += h;
  63. EditorGUI.EndProperty();
  64. }
  65. }
  66. [CustomEditor(typeof(VRCSDK2.VRC_SyncVideoStream))]
  67. public class SyncVideoStreamEditor : Editor
  68. {
  69. ReorderableList sourceList;
  70. public override void OnInspectorGUI()
  71. {
  72. SerializedProperty searchRoot = serializedObject.FindProperty("VideoSearchRoot");
  73. EditorGUILayout.PropertyField(searchRoot);
  74. SerializedProperty maxQual = serializedObject.FindProperty("MaxStreamQuality");
  75. EditorGUILayout.PropertyField(maxQual);
  76. SerializedProperty texFmt = serializedObject.FindProperty("videoTextureFormat");
  77. EditorGUILayout.PropertyField(texFmt);
  78. SerializedProperty autoStart = serializedObject.FindProperty("AutoStart");
  79. EditorGUILayout.PropertyField(autoStart);
  80. EditorGUILayout.Space();
  81. sourceList.DoLayoutList();
  82. serializedObject.ApplyModifiedProperties();
  83. }
  84. private void OnEnable()
  85. {
  86. SerializedProperty videos = serializedObject.FindProperty("Videos");
  87. sourceList = new ReorderableList(serializedObject, videos);
  88. sourceList.drawElementCallback += (Rect rect, int index, bool active, bool focused) =>
  89. {
  90. EditorGUI.PropertyField(rect, serializedObject.FindProperty("Videos").GetArrayElementAtIndex(index));
  91. };
  92. sourceList.elementHeightCallback += (int index) =>
  93. {
  94. SerializedProperty element = serializedObject.FindProperty("Videos").GetArrayElementAtIndex(index);
  95. return EditorGUI.GetPropertyHeight(element);
  96. };
  97. sourceList.drawHeaderCallback = (Rect rect) => EditorGUI.LabelField(rect, "Videos");
  98. }
  99. }