Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
5.9 KiB

  1. #if (UNITY_5_4_OR_NEWER)
  2. namespace VRTK
  3. {
  4. using System;
  5. using UnityEditor;
  6. using UnityEngine;
  7. [CustomEditor(typeof(VRTK_AdaptiveQuality))]
  8. public class VRTK_AdaptiveQualityEditor : Editor
  9. {
  10. private const string DontDisableHelpBoxText =
  11. "This script supports command line arguments to configure the adaptive quality scaling."
  12. + " If this script is disabled it won't respond to the arguments.\n\n"
  13. + "Leave this script enabled and use the `scaleRenderViewport` property if you want to disable"
  14. + " the adaptive quality scaling for now, but want to leave it possible for your built"
  15. + " binary to respond to the arguments.";
  16. private const string MaximumRenderScaleTooBigHelpBoxText =
  17. "The maximum render scale is too big. It's constrained by the maximum render target dimension below.";
  18. private const string ScaleRenderTargetResolutionCostlyHelpBoxText =
  19. "Changing the render target resolution is very costly and should be reduced to a minimum, therefore"
  20. + " this setting is turned off by default. Make sure you understand the performance implication this"
  21. + " setting has when leaving it enabled.";
  22. private const string NoRenderScaleLevelsYetHelpBoxText =
  23. "Overriding render viewport scale levels is disabled because there are no render viewport scale levels calculated yet."
  24. + " They will be calculated at runtime.";
  25. public override void OnInspectorGUI()
  26. {
  27. serializedObject.Update();
  28. VRTK_AdaptiveQuality adaptiveQuality = (VRTK_AdaptiveQuality)target;
  29. EditorGUILayout.HelpBox(DontDisableHelpBoxText, adaptiveQuality.enabled ? MessageType.Warning : MessageType.Error);
  30. EditorGUILayout.Space();
  31. EditorGUILayout.PropertyField(serializedObject.FindProperty("drawDebugVisualization"));
  32. EditorGUILayout.PropertyField(serializedObject.FindProperty("allowKeyboardShortcuts"));
  33. EditorGUILayout.PropertyField(serializedObject.FindProperty("allowCommandLineArguments"));
  34. EditorGUILayout.PropertyField(serializedObject.FindProperty("msaaLevel"));
  35. EditorGUILayout.Space();
  36. serializedObject.FindProperty("scaleRenderViewport").boolValue =
  37. EditorGUILayout.BeginToggleGroup(VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("scaleRenderViewport"),
  38. adaptiveQuality.scaleRenderViewport);
  39. {
  40. Limits2D renderScaleLimits = adaptiveQuality.renderScaleLimits;
  41. EditorGUILayout.PropertyField(serializedObject.FindProperty("renderScaleLimits"));
  42. if (renderScaleLimits.maximum > adaptiveQuality.BiggestAllowedMaximumRenderScale())
  43. {
  44. EditorGUILayout.HelpBox(MaximumRenderScaleTooBigHelpBoxText, MessageType.Error);
  45. }
  46. EditorGUILayout.PropertyField(serializedObject.FindProperty("maximumRenderTargetDimension"));
  47. EditorGUILayout.PropertyField(serializedObject.FindProperty("renderScaleFillRateStepSizeInPercent"));
  48. serializedObject.FindProperty("scaleRenderTargetResolution").boolValue =
  49. EditorGUILayout.Toggle(VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("scaleRenderTargetResolution"),
  50. adaptiveQuality.scaleRenderTargetResolution);
  51. if (adaptiveQuality.scaleRenderTargetResolution)
  52. {
  53. EditorGUILayout.HelpBox(ScaleRenderTargetResolutionCostlyHelpBoxText, MessageType.Warning);
  54. }
  55. int maxRenderScaleLevel = Mathf.Max(adaptiveQuality.renderScales.Count - 1, 0);
  56. bool disabled = maxRenderScaleLevel == 0 || !Application.isPlaying;
  57. EditorGUI.BeginDisabledGroup(disabled);
  58. {
  59. VRTK_EditorUtilities.AddHeader<VRTK_AdaptiveQuality>("overrideRenderViewportScale");
  60. if (disabled)
  61. {
  62. EditorGUI.EndDisabledGroup();
  63. {
  64. EditorGUILayout.HelpBox(NoRenderScaleLevelsYetHelpBoxText, MessageType.Info);
  65. }
  66. EditorGUI.BeginDisabledGroup(true);
  67. }
  68. adaptiveQuality.overrideRenderViewportScale = EditorGUILayout.Toggle(
  69. VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderViewportScale"),
  70. adaptiveQuality.overrideRenderViewportScale);
  71. EditorGUI.BeginDisabledGroup(!adaptiveQuality.overrideRenderViewportScale);
  72. {
  73. adaptiveQuality.overrideRenderViewportScaleLevel =
  74. EditorGUILayout.IntSlider(
  75. VRTK_EditorUtilities.BuildGUIContent<VRTK_AdaptiveQuality>("overrideRenderViewportScaleLevel"),
  76. adaptiveQuality.overrideRenderViewportScaleLevel,
  77. 0,
  78. maxRenderScaleLevel);
  79. }
  80. EditorGUI.EndDisabledGroup();
  81. }
  82. EditorGUI.EndDisabledGroup();
  83. }
  84. EditorGUILayout.EndToggleGroup();
  85. if (Application.isPlaying)
  86. {
  87. string summary = adaptiveQuality.ToString();
  88. summary = summary.Substring(summary.IndexOf("\n", StringComparison.Ordinal) + 1);
  89. VRTK_EditorUtilities.AddHeader("Current State");
  90. EditorGUILayout.HelpBox(summary, MessageType.None);
  91. if (GUILayout.RepeatButton("Refresh"))
  92. {
  93. Repaint();
  94. }
  95. }
  96. serializedObject.ApplyModifiedProperties();
  97. }
  98. }
  99. }
  100. #endif