ResolveToRenderTextureEditor.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using UnityEditor;
  2. using UnityEngine;
  3. //-----------------------------------------------------------------------------
  4. // Copyright 2015-2022 RenderHeads Ltd. All rights reserved.
  5. //-----------------------------------------------------------------------------
  6. namespace RenderHeads.Media.AVProVideo.Editor
  7. {
  8. /// <summary>
  9. /// Editor for the ResolveToRenderTexture component
  10. /// </summary>
  11. [CanEditMultipleObjects]
  12. [CustomEditor(typeof(ResolveToRenderTexture))]
  13. public class ResolveToRenderTextureEditor : UnityEditor.Editor
  14. {
  15. private SerializedProperty _propMediaPlayer;
  16. private SerializedProperty _propExternalTexture;
  17. private SerializedProperty _propResolveFlags;
  18. private SerializedProperty _propOptionsApplyHSBC;
  19. private SerializedProperty _propOptionsHue;
  20. private SerializedProperty _propOptionsSaturation;
  21. private SerializedProperty _propOptionsBrightness;
  22. private SerializedProperty _propOptionsContrast;
  23. private SerializedProperty _propOptionsGamma;
  24. private SerializedProperty _propOptionsTint;
  25. private SerializedProperty _propOptionsAspectRatio;
  26. void OnEnable()
  27. {
  28. _propMediaPlayer = this.CheckFindProperty("_mediaPlayer");
  29. _propExternalTexture = this.CheckFindProperty("_externalTexture");
  30. _propResolveFlags = this.CheckFindProperty("_resolveFlags");
  31. _propOptionsApplyHSBC = this.CheckFindProperty("_options.applyHSBC");
  32. _propOptionsHue = this.CheckFindProperty("_options.hue");
  33. _propOptionsSaturation = this.CheckFindProperty("_options.saturation");
  34. _propOptionsBrightness = this.CheckFindProperty("_options.brightness");
  35. _propOptionsContrast = this.CheckFindProperty("_options.contrast");
  36. _propOptionsGamma = this.CheckFindProperty("_options.gamma");
  37. _propOptionsTint = this.CheckFindProperty("_options.tint");
  38. _propOptionsAspectRatio = this.CheckFindProperty("_options.aspectRatio");
  39. }
  40. private void ButtonFloatReset(SerializedProperty prop, float value)
  41. {
  42. GUILayout.BeginHorizontal();
  43. EditorGUILayout.PropertyField(prop);
  44. if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
  45. {
  46. prop.floatValue = value;
  47. }
  48. GUILayout.EndHorizontal();
  49. }
  50. private void ButtonColorReset(SerializedProperty prop, Color value)
  51. {
  52. GUILayout.BeginHorizontal();
  53. EditorGUILayout.PropertyField(prop);
  54. if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
  55. {
  56. prop.colorValue = value;
  57. }
  58. GUILayout.EndHorizontal();
  59. }
  60. public override void OnInspectorGUI()
  61. {
  62. serializedObject.Update();
  63. EditorGUILayout.PropertyField(_propMediaPlayer);
  64. EditorGUILayout.PropertyField(_propExternalTexture);
  65. _propResolveFlags.intValue = EditorGUILayout.MaskField("Resolve Flags", _propResolveFlags.intValue, System.Enum.GetNames(typeof( VideoRender.ResolveFlags)));
  66. EditorGUI.BeginChangeCheck();
  67. {
  68. EditorGUILayout.PropertyField(_propOptionsApplyHSBC);
  69. EditorGUI.BeginDisabledGroup(!_propOptionsApplyHSBC.boolValue);
  70. {
  71. EditorGUI.indentLevel++;
  72. ButtonFloatReset(_propOptionsHue, 0f);
  73. ButtonFloatReset(_propOptionsSaturation, 0.5f);
  74. ButtonFloatReset(_propOptionsBrightness, 0.5f);
  75. ButtonFloatReset(_propOptionsContrast, 0.5f);
  76. ButtonFloatReset(_propOptionsGamma, 1f);
  77. EditorGUI.indentLevel--;
  78. }
  79. EditorGUI.EndDisabledGroup();
  80. ButtonColorReset(_propOptionsTint, Color.white);
  81. }
  82. if (EditorGUI.EndChangeCheck())
  83. {
  84. Object[] resolves = this.serializedObject.targetObjects;
  85. if (resolves != null)
  86. {
  87. foreach (ResolveToRenderTexture resolve in resolves)
  88. {
  89. resolve.SetMaterialDirty();
  90. }
  91. }
  92. }
  93. EditorGUILayout.PropertyField(_propOptionsAspectRatio);
  94. serializedObject.ApplyModifiedProperties();
  95. {
  96. ResolveToRenderTexture resolve = this.target as ResolveToRenderTexture;
  97. if (resolve != null && resolve.TargetTexture != null)
  98. {
  99. Rect r = GUILayoutUtility.GetAspectRect(resolve.TargetTexture.width / (float)resolve.TargetTexture.height);
  100. GUI.DrawTexture(r, resolve.TargetTexture, ScaleMode.StretchToFill, true);
  101. if (GUILayout.Button("Select Texture"))
  102. {
  103. Selection.activeObject = resolve.TargetTexture;
  104. }
  105. Repaint();
  106. }
  107. }
  108. }
  109. }
  110. }