MediaPlayerEditor_Subtitles.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. using UnityEditor;
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2015-2021 RenderHeads Ltd. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. namespace RenderHeads.Media.AVProVideo.Editor
  7. {
  8. /// <summary>
  9. /// Editor for the MediaPlayer component
  10. /// </summary>
  11. public partial class MediaPlayerEditor : UnityEditor.Editor
  12. {
  13. #if UNITY_EDITOR_OSX
  14. internal const string SubtitleFileExtensions = "srt";
  15. #else
  16. internal const string SubtitleFileExtensions = "Subtitle Files;*.srt";
  17. #endif
  18. private SerializedProperty _propSubtitles;
  19. private SerializedProperty _propSubtitlePath;
  20. private void OnInspectorGUI_Subtitles()
  21. {
  22. // TODO: add support for multiple targets?
  23. MediaPlayer media = (this.target) as MediaPlayer;
  24. //EditorGUILayout.BeginVertical();
  25. EditorGUILayout.PropertyField(_propSubtitles, new GUIContent("Sideload Subtitles"));
  26. EditorGUI.BeginDisabledGroup(!_propSubtitles.boolValue);
  27. EditorGUILayout.BeginVertical(GUI.skin.box);
  28. EditorGUILayout.PropertyField(_propSubtitlePath);
  29. //if (!Application.isPlaying)
  30. {
  31. GUI.color = Color.white;
  32. GUILayout.BeginHorizontal();
  33. if (Application.isPlaying)
  34. {
  35. if (GUILayout.Button("Load"))
  36. {
  37. MediaPath mediaPath = new MediaPath(_propSubtitlePath.FindPropertyRelative("_path").stringValue, (MediaPathType)_propSubtitlePath.FindPropertyRelative("_pathType").enumValueIndex);
  38. media.EnableSubtitles(mediaPath);
  39. }
  40. if (GUILayout.Button("Clear"))
  41. {
  42. media.DisableSubtitles();
  43. }
  44. }
  45. else
  46. {
  47. GUILayout.FlexibleSpace();
  48. }
  49. MediaPathDrawer.ShowBrowseSubtitlesButtonIcon(_propSubtitlePath);
  50. GUILayout.EndHorizontal();
  51. if (_propSubtitles.boolValue)
  52. {
  53. ///MediaPath mediaPath = new MediaPath(_propSubtitlePath.FindPropertyRelative("_path").stringValue, (MediaPathType)_propSubtitlePath.FindPropertyRelative("_pathType").enumValueIndex);
  54. //ShowFileWarningMessages(mediaPath, media.AutoOpen, Platform.Unknown);
  55. //GUI.color = Color.white;
  56. }
  57. }
  58. //EditorGUILayout.EndVertical();
  59. EditorGUILayout.EndVertical();
  60. EditorGUI.EndDisabledGroup();
  61. }
  62. }
  63. }