ResolveToRenderTextureEditor.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. void OnEnable()
  26. {
  27. _propMediaPlayer = this.CheckFindProperty("_mediaPlayer");
  28. _propExternalTexture = this.CheckFindProperty("_externalTexture");
  29. _propResolveFlags = this.CheckFindProperty("_resolveFlags");
  30. _propOptionsApplyHSBC = this.CheckFindProperty("_options.applyHSBC");
  31. _propOptionsHue = this.CheckFindProperty("_options.hue");
  32. _propOptionsSaturation = this.CheckFindProperty("_options.saturation");
  33. _propOptionsBrightness = this.CheckFindProperty("_options.brightness");
  34. _propOptionsContrast = this.CheckFindProperty("_options.contrast");
  35. _propOptionsGamma = this.CheckFindProperty("_options.gamma");
  36. _propOptionsTint = this.CheckFindProperty("_options.tint");
  37. }
  38. private void ButtonFloatReset(SerializedProperty prop, float value)
  39. {
  40. GUILayout.BeginHorizontal();
  41. EditorGUILayout.PropertyField(prop);
  42. if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
  43. {
  44. prop.floatValue = value;
  45. }
  46. GUILayout.EndHorizontal();
  47. }
  48. private void ButtonColorReset(SerializedProperty prop, Color value)
  49. {
  50. GUILayout.BeginHorizontal();
  51. EditorGUILayout.PropertyField(prop);
  52. if (GUILayout.Button("Reset", GUILayout.ExpandWidth(false)))
  53. {
  54. prop.colorValue = value;
  55. }
  56. GUILayout.EndHorizontal();
  57. }
  58. public override void OnInspectorGUI()
  59. {
  60. serializedObject.Update();
  61. EditorGUILayout.PropertyField(_propMediaPlayer);
  62. EditorGUILayout.PropertyField(_propExternalTexture);
  63. _propResolveFlags.intValue = EditorGUILayout.MaskField("Resolve Flags", _propResolveFlags.intValue, System.Enum.GetNames(typeof( VideoRender.ResolveFlags)));
  64. EditorGUI.BeginChangeCheck();
  65. {
  66. EditorGUILayout.PropertyField(_propOptionsApplyHSBC);
  67. EditorGUI.BeginDisabledGroup(!_propOptionsApplyHSBC.boolValue);
  68. {
  69. EditorGUI.indentLevel++;
  70. ButtonFloatReset(_propOptionsHue, 0f);
  71. ButtonFloatReset(_propOptionsSaturation, 0.5f);
  72. ButtonFloatReset(_propOptionsBrightness, 0.5f);
  73. ButtonFloatReset(_propOptionsContrast, 0.5f);
  74. ButtonFloatReset(_propOptionsGamma, 1f);
  75. EditorGUI.indentLevel--;
  76. }
  77. EditorGUI.EndDisabledGroup();
  78. ButtonColorReset(_propOptionsTint, Color.white);
  79. }
  80. if (EditorGUI.EndChangeCheck())
  81. {
  82. Object[] resolves = this.serializedObject.targetObjects;
  83. if (resolves != null)
  84. {
  85. foreach (ResolveToRenderTexture resolve in resolves)
  86. {
  87. resolve.SetMaterialDirty();
  88. }
  89. }
  90. }
  91. serializedObject.ApplyModifiedProperties();
  92. {
  93. ResolveToRenderTexture resolve = this.target as ResolveToRenderTexture;
  94. if (resolve != null && resolve.TargetTexture != null)
  95. {
  96. Rect r = GUILayoutUtility.GetAspectRect(resolve.TargetTexture.width / (float)resolve.TargetTexture.height);
  97. GUI.DrawTexture(r, resolve.TargetTexture, ScaleMode.StretchToFill, true);
  98. if (GUILayout.Button("Select Texture"))
  99. {
  100. Selection.activeObject = resolve.TargetTexture;
  101. }
  102. Repaint();
  103. }
  104. }
  105. }
  106. }
  107. }