MediaPathDrawer.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. namespace RenderHeads.Media.AVProVideo.Editor
  6. {
  7. [CustomPropertyDrawer(typeof(MediaPath))]
  8. public class MediaPathDrawer : PropertyDrawer
  9. {
  10. public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return 0f; }
  11. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  12. {
  13. EditorGUI.BeginProperty(position, GUIContent.none, property);
  14. SerializedProperty propPath = property.FindPropertyRelative("_path");
  15. SerializedProperty propPathType = property.FindPropertyRelative("_pathType");
  16. EditorGUILayout.PropertyField(propPathType, GUIContent.none);
  17. string newUrl = EditorGUILayout.TextField(propPath.stringValue);
  18. newUrl = newUrl.Trim();
  19. if (EditorHelper.SafeSetPathProperty(newUrl, propPath))
  20. {
  21. // TODO: shouldn't we set all targets?
  22. EditorUtility.SetDirty(property.serializedObject.targetObject);
  23. }
  24. MediaPlayerEditor.ShowFileWarningMessages(propPath.stringValue, (MediaPathType)propPathType.enumValueIndex, null, MediaSource.Path, false, Platform.Unknown);
  25. GUI.color = Color.white;
  26. EditorGUI.EndProperty();
  27. }
  28. public static void ShowBrowseButton(SerializedProperty propMediaPath)
  29. {
  30. GUIContent buttonText = new GUIContent("Browse", EditorGUIUtility.IconContent("d_Project").image);
  31. if (GUILayout.Button(buttonText, GUILayout.ExpandWidth(true)))
  32. {
  33. RecentMenu.Create(propMediaPath, null, MediaPlayerEditor.MediaFileExtensions, false);
  34. }
  35. }
  36. public static void ShowBrowseButtonIcon(SerializedProperty propMediaPath, SerializedProperty propMediaSource)
  37. {
  38. if (GUILayout.Button(EditorGUIUtility.IconContent("d_Project"), GUILayout.ExpandWidth(false)))
  39. {
  40. RecentMenu.Create(propMediaPath, propMediaSource, MediaPlayerEditor.MediaFileExtensions, false, 100);
  41. }
  42. }
  43. public static void ShowBrowseSubtitlesButtonIcon(SerializedProperty propMediaPath)
  44. {
  45. if (GUILayout.Button(EditorGUIUtility.IconContent("d_Project"), GUILayout.ExpandWidth(false)))// GUILayout.Height(EditorGUIUtility.singleLineHeight)))
  46. {
  47. RecentMenu.Create(propMediaPath, null, MediaPlayerEditor.SubtitleFileExtensions, false);
  48. }
  49. }
  50. }
  51. }