DisplayIMGUIEditor.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 DisplayIMGUI component
  10. /// </summary>
  11. [CanEditMultipleObjects]
  12. [CustomEditor(typeof(DisplayIMGUI))]
  13. public class DisplayIMGUIEditor : UnityEditor.Editor
  14. {
  15. private SerializedProperty _propMediaPlayer;
  16. private SerializedProperty _propScaleMode;
  17. private SerializedProperty _propColor;
  18. private SerializedProperty _propAllowTransparency;
  19. private SerializedProperty _propUseDepth;
  20. private SerializedProperty _propDepth;
  21. private SerializedProperty _propAreaFullscreen;
  22. private SerializedProperty _propAreaX;
  23. private SerializedProperty _propAreaY;
  24. private SerializedProperty _propAreaWidth;
  25. private SerializedProperty _propAreaHeight;
  26. private SerializedProperty _propShowAreaInEditor;
  27. void OnEnable()
  28. {
  29. _propMediaPlayer = this.CheckFindProperty("_mediaPlayer");
  30. _propScaleMode = this.CheckFindProperty("_scaleMode");
  31. _propColor = this.CheckFindProperty("_color");
  32. _propAllowTransparency = this.CheckFindProperty("_allowTransparency");
  33. _propUseDepth = this.CheckFindProperty("_useDepth");
  34. _propDepth = this.CheckFindProperty("_depth");
  35. _propAreaFullscreen = this.CheckFindProperty("_isAreaFullScreen");
  36. _propAreaX = this.CheckFindProperty("_areaX");
  37. _propAreaY = this.CheckFindProperty("_areaY");
  38. _propAreaWidth = this.CheckFindProperty("_areaWidth");
  39. _propAreaHeight = this.CheckFindProperty("_areaHeight");
  40. _propShowAreaInEditor = this.CheckFindProperty("_showAreaInEditor");
  41. }
  42. public override void OnInspectorGUI()
  43. {
  44. serializedObject.Update();
  45. EditorGUI.BeginChangeCheck();
  46. EditorGUILayout.PropertyField(_propMediaPlayer);
  47. EditorGUILayout.PropertyField(_propScaleMode);
  48. EditorGUILayout.PropertyField(_propColor);
  49. EditorGUILayout.PropertyField(_propAllowTransparency);
  50. EditorGUILayout.PropertyField(_propUseDepth);
  51. if (_propUseDepth.boolValue)
  52. {
  53. EditorGUILayout.PropertyField(_propDepth);
  54. }
  55. // Area
  56. EditorGUILayout.PropertyField(_propAreaFullscreen, new GUIContent("Full Screen"));
  57. if (!_propAreaFullscreen.boolValue)
  58. {
  59. EditorGUILayout.PropertyField(_propAreaX, new GUIContent("X"));
  60. EditorGUILayout.PropertyField(_propAreaY, new GUIContent("Y"));
  61. EditorGUILayout.PropertyField(_propAreaWidth, new GUIContent("Width"));
  62. EditorGUILayout.PropertyField(_propAreaHeight, new GUIContent("Height"));
  63. }
  64. EditorGUILayout.PropertyField(_propShowAreaInEditor, new GUIContent("Show in Editor"));
  65. serializedObject.ApplyModifiedProperties();
  66. // Force update
  67. bool unhandledChanges = (EditorGUI.EndChangeCheck() && Application.isPlaying);
  68. if (unhandledChanges)
  69. {
  70. foreach (Object obj in this.targets)
  71. {
  72. ((DisplayIMGUI)obj).Update();
  73. }
  74. }
  75. }
  76. }
  77. }