MediaPathDrawer.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. //GUI.color = HttpHeader.IsValid(valueProp.stringValue)?Color.white:Color.red;
  18. string newUrl = EditorGUILayout.TextArea(propPath.stringValue, EditorHelper.IMGUI.GetWordWrappedTextAreaStyle());
  19. //GUI.color = Color.white;
  20. newUrl = newUrl.Trim();
  21. if (EditorHelper.SafeSetPathProperty(newUrl, propPath))
  22. {
  23. // TODO: shouldn't we set all targets?
  24. EditorUtility.SetDirty(property.serializedObject.targetObject);
  25. }
  26. MediaPlayerEditor.ShowFileWarningMessages(propPath.stringValue, (MediaPathType)propPathType.enumValueIndex, null, MediaSource.Path, false, Platform.Unknown);
  27. GUI.color = Color.white;
  28. EditorGUI.EndProperty();
  29. }
  30. public static void ShowBrowseButton(SerializedProperty propMediaPath)
  31. {
  32. GUIContent buttonText = new GUIContent("Browse", EditorGUIUtility.IconContent("d_Project").image);
  33. if (GUILayout.Button(buttonText, GUILayout.ExpandWidth(true)))
  34. {
  35. RecentMenu.Create(propMediaPath, null, MediaPlayerEditor.MediaFileExtensions, false);
  36. }
  37. }
  38. public static void ShowBrowseButtonIcon(SerializedProperty propMediaPath, SerializedProperty propMediaSource)
  39. {
  40. if (GUILayout.Button(EditorGUIUtility.IconContent("d_Project"), GUILayout.ExpandWidth(false)))
  41. {
  42. RecentMenu.Create(propMediaPath, propMediaSource, MediaPlayerEditor.MediaFileExtensions, false, 100);
  43. }
  44. }
  45. public static void ShowBrowseSubtitlesButtonIcon(SerializedProperty propMediaPath)
  46. {
  47. if (GUILayout.Button(EditorGUIUtility.IconContent("d_Project"), GUILayout.ExpandWidth(false)))// GUILayout.Height(EditorGUIUtility.singleLineHeight)))
  48. {
  49. RecentMenu.Create(propMediaPath, null, MediaPlayerEditor.SubtitleFileExtensions, false);
  50. }
  51. }
  52. }
  53. }