1
+ using UnityEngine ;
2
+ using UnityEditor ;
3
+
4
+ namespace UniRate . Editor {
5
+
6
+ [ CustomEditor ( typeof ( RateRequestComponent ) , true ) ]
7
+ [ CanEditMultipleObjects ]
8
+ public class RateRequestComponentInspector : UnityEditor . Editor {
9
+
10
+ #region <<---------- Properties and Fields ---------->>
11
+
12
+ private SerializedProperty _propUpdateRatePresetOption ;
13
+ private SerializedProperty _propUpdateRateCustomValue ;
14
+
15
+ private SerializedProperty _propFixedUpdateRatePresetOption ;
16
+ private SerializedProperty _propFixedUpdateRateCustomValue ;
17
+
18
+ private SerializedProperty _propRenderIntervalPresetOption ;
19
+ private SerializedProperty _propRenderIntervalCustomValue ;
20
+
21
+ private SerializedProperty _propDelaySecondsToStopRequests ;
22
+
23
+ private readonly string [ ] _displayUpdateRate = new [ ] {
24
+ $ "{ RateRequestComponent . PresetOptions . Ultra . ToString ( ) } ({ RatePreset . Ultra . UpdateRate . ToString ( ) } )",
25
+ $ "{ RateRequestComponent . PresetOptions . VeryHigh . ToString ( ) } ({ RatePreset . VeryHigh . UpdateRate . ToString ( ) } )",
26
+ $ "{ RateRequestComponent . PresetOptions . High . ToString ( ) } ({ RatePreset . High . UpdateRate . ToString ( ) } )",
27
+ $ "{ RateRequestComponent . PresetOptions . Medium . ToString ( ) } ({ RatePreset . Medium . UpdateRate . ToString ( ) } )",
28
+ $ "{ RateRequestComponent . PresetOptions . Low . ToString ( ) } ({ RatePreset . Low . UpdateRate . ToString ( ) } )",
29
+ $ "{ RateRequestComponent . PresetOptions . VeryLow . ToString ( ) } ({ RatePreset . VeryLow . UpdateRate . ToString ( ) } )",
30
+ RateRequestComponent . PresetOptions . Custom . ToString ( ) ,
31
+ } ;
32
+
33
+ private readonly string [ ] _displayFixedUpdateRate = new [ ] {
34
+ $ "{ RateRequestComponent . PresetOptions . Ultra . ToString ( ) } ({ RatePreset . Ultra . FixedUpdateRate . ToString ( ) } )",
35
+ $ "{ RateRequestComponent . PresetOptions . VeryHigh . ToString ( ) } ({ RatePreset . VeryHigh . FixedUpdateRate . ToString ( ) } )",
36
+ $ "{ RateRequestComponent . PresetOptions . High . ToString ( ) } ({ RatePreset . High . FixedUpdateRate . ToString ( ) } )",
37
+ $ "{ RateRequestComponent . PresetOptions . Medium . ToString ( ) } ({ RatePreset . Medium . FixedUpdateRate . ToString ( ) } )",
38
+ $ "{ RateRequestComponent . PresetOptions . Low . ToString ( ) } ({ RatePreset . Low . FixedUpdateRate . ToString ( ) } )",
39
+ $ "{ RateRequestComponent . PresetOptions . VeryLow . ToString ( ) } ({ RatePreset . VeryLow . FixedUpdateRate . ToString ( ) } )",
40
+ RateRequestComponent . PresetOptions . Custom . ToString ( ) ,
41
+ } ;
42
+
43
+ private readonly string [ ] _displayRenderInterval = new [ ] {
44
+ $ "{ RateRequestComponent . PresetOptions . Ultra . ToString ( ) } ({ RatePreset . Ultra . RenderInterval . ToString ( ) } )",
45
+ $ "{ RateRequestComponent . PresetOptions . VeryHigh . ToString ( ) } ({ RatePreset . VeryHigh . RenderInterval . ToString ( ) } )",
46
+ $ "{ RateRequestComponent . PresetOptions . High . ToString ( ) } ({ RatePreset . High . RenderInterval . ToString ( ) } )",
47
+ $ "{ RateRequestComponent . PresetOptions . Medium . ToString ( ) } ({ RatePreset . Medium . RenderInterval . ToString ( ) } )",
48
+ $ "{ RateRequestComponent . PresetOptions . Low . ToString ( ) } ({ RatePreset . Low . RenderInterval . ToString ( ) } )",
49
+ $ "{ RateRequestComponent . PresetOptions . VeryLow . ToString ( ) } ({ RatePreset . VeryLow . RenderInterval . ToString ( ) } )",
50
+ RateRequestComponent . PresetOptions . Custom . ToString ( ) ,
51
+ } ;
52
+
53
+ private const string STR_SPACE = " " ;
54
+
55
+ #endregion <<---------- Properties and Fields ---------->>
56
+
57
+
58
+
59
+
60
+ #region <<---------- Editor ---------->>
61
+
62
+ private void OnEnable ( ) {
63
+ this . _propUpdateRatePresetOption = this . serializedObject . FindProperty ( "_updateRatePresetOption" ) ;
64
+ this . _propUpdateRateCustomValue = this . serializedObject . FindProperty ( "_updateRateCustomValue" ) ;
65
+
66
+ this . _propFixedUpdateRatePresetOption = this . serializedObject . FindProperty ( "_fixedUpdateRatePresetOption" ) ;
67
+ this . _propFixedUpdateRateCustomValue = this . serializedObject . FindProperty ( "_fixedUpdateRateCustomValue" ) ;
68
+
69
+ this . _propRenderIntervalPresetOption = this . serializedObject . FindProperty ( "_renderIntervalPresetOption" ) ;
70
+ this . _propRenderIntervalCustomValue = this . serializedObject . FindProperty ( "_renderIntervalCustomValue" ) ;
71
+
72
+ this . _propDelaySecondsToStopRequests = this . serializedObject . FindProperty ( "_delaySecondsToStopRequests" ) ;
73
+ }
74
+
75
+ public override void OnInspectorGUI ( ) {
76
+ this . serializedObject . Update ( ) ;
77
+ this . DrawDefaultInspector ( ) ;
78
+
79
+ EditorGUI . BeginChangeCheck ( ) ;
80
+ EditorGUILayout . PropertyField ( this . _propDelaySecondsToStopRequests , new GUIContent ( "Delay Seconds to Stop Requests" ) ) ;
81
+ if ( EditorGUI . EndChangeCheck ( ) ) {
82
+ this . serializedObject . ApplyModifiedProperties ( ) ;
83
+ }
84
+ EditorGUILayout . Space ( ) ;
85
+
86
+ bool isCustom ;
87
+
88
+ EditorGUI . BeginChangeCheck ( ) ;
89
+ isCustom = this . DrawPresetOptionAndReturnIfCustom ( "Render Interval" , this . _displayRenderInterval , this . _propRenderIntervalPresetOption ) ;
90
+ if ( EditorGUI . EndChangeCheck ( ) ) {
91
+ this . serializedObject . ApplyModifiedProperties ( ) ;
92
+ }
93
+ if ( isCustom ) {
94
+ EditorGUI . BeginChangeCheck ( ) ;
95
+ this . _propRenderIntervalCustomValue . intValue = EditorGUILayout . IntField ( STR_SPACE , this . _propRenderIntervalCustomValue . intValue ) ;
96
+ if ( EditorGUI . EndChangeCheck ( ) ) {
97
+ this . serializedObject . ApplyModifiedProperties ( ) ;
98
+ }
99
+ }
100
+
101
+ EditorGUI . BeginChangeCheck ( ) ;
102
+ isCustom = this . DrawPresetOptionAndReturnIfCustom ( "Update Rate" , this . _displayUpdateRate , this . _propUpdateRatePresetOption ) ;
103
+ if ( EditorGUI . EndChangeCheck ( ) ) {
104
+ this . serializedObject . ApplyModifiedProperties ( ) ;
105
+ }
106
+ if ( isCustom ) {
107
+ EditorGUI . BeginChangeCheck ( ) ;
108
+ this . _propUpdateRateCustomValue . intValue = EditorGUILayout . IntField ( STR_SPACE , this . _propUpdateRateCustomValue . intValue ) ;
109
+ if ( EditorGUI . EndChangeCheck ( ) ) {
110
+ this . serializedObject . ApplyModifiedProperties ( ) ;
111
+ }
112
+ }
113
+
114
+ EditorGUI . BeginChangeCheck ( ) ;
115
+ isCustom = this . DrawPresetOptionAndReturnIfCustom ( "Fixed Update Rate" , this . _displayFixedUpdateRate , this . _propFixedUpdateRatePresetOption ) ;
116
+ if ( EditorGUI . EndChangeCheck ( ) ) {
117
+ this . serializedObject . ApplyModifiedProperties ( ) ;
118
+ }
119
+ if ( isCustom ) {
120
+ EditorGUI . BeginChangeCheck ( ) ;
121
+ this . _propFixedUpdateRateCustomValue . intValue = EditorGUILayout . IntField ( STR_SPACE , this . _propFixedUpdateRateCustomValue . intValue ) ;
122
+ if ( EditorGUI . EndChangeCheck ( ) ) {
123
+ this . serializedObject . ApplyModifiedProperties ( ) ;
124
+ }
125
+ }
126
+
127
+ #if ! UNITY_2019_3_OR_NEWER
128
+ EditorGUILayout . Space ( ) ;
129
+ EditorGUILayout . HelpBox ( "render interval is only supported on Unity 2019.3 or newer" , MessageType . Warning ) ;
130
+ #endif
131
+ }
132
+
133
+ #endregion <<---------- Editor ---------->>
134
+
135
+
136
+
137
+
138
+ #region <<---------- General ---------->>
139
+
140
+ private bool DrawPresetOptionAndReturnIfCustom ( string label , string [ ] display , SerializedProperty property ) {
141
+ int enumIndex = ( property . hasMultipleDifferentValues ? - 1 : property . enumValueIndex ) ;
142
+ enumIndex = EditorGUILayout . Popup ( label , enumIndex , display ) ;
143
+ var enumValue = ( RateRequestComponent . PresetOptions ) enumIndex ;
144
+ if ( enumIndex != - 1 ) {
145
+ property . enumValueIndex = enumIndex ;
146
+ }
147
+ return ( enumValue == RateRequestComponent . PresetOptions . Custom ) ;
148
+ }
149
+
150
+ #endregion <<---------- General ---------->>
151
+ }
152
+ }
0 commit comments