@@ -13,25 +13,97 @@ public static class CurvePreferences
13
13
/// </summary>
14
14
public static bool IsDebugEnabled
15
15
{
16
- get { return GetBoolPref ( ENABLE_DEBUG_PREF , ENABLE_DEBUG_DEFAULT ) ; }
17
- set { EditorPrefs . SetBool ( ENABLE_DEBUG_PREF , value ) ; }
16
+ get
17
+ {
18
+ if ( ! _isDebugEnabled . HasValue )
19
+ {
20
+ _isDebugEnabled = GetBoolPref ( ENABLE_DEBUG_PREF , ENABLE_DEBUG_DEFAULT ) ;
21
+ }
22
+
23
+ return _isDebugEnabled . Value ;
24
+
25
+ }
26
+ set
27
+ {
28
+ _isDebugEnabled = value ;
29
+
30
+ EditorPrefs . SetBool ( ENABLE_DEBUG_PREF , value ) ;
31
+ }
18
32
}
19
33
20
34
/// <summary>
21
35
/// Returns true if rotation visualization info should be enabled, otherwise false.
22
36
/// </summary>
23
37
public static bool ShouldVisualizeRotation
24
38
{
25
- get { return GetBoolPref ( SHOW_ROTATION_PREF , SHOW_ROTATION_DEFAULT ) ; }
26
- set { EditorPrefs . SetBool ( SHOW_ROTATION_PREF , value ) ; }
39
+ get
40
+ {
41
+ if ( ! _shouldVisualizeRotation . HasValue )
42
+ {
43
+ _shouldVisualizeRotation = GetBoolPref ( SHOW_ROTATION_PREF , SHOW_ROTATION_DEFAULT ) ;
44
+ }
45
+
46
+ return _shouldVisualizeRotation . Value ;
47
+ }
48
+ set
49
+ {
50
+ _shouldVisualizeRotation = value ;
51
+
52
+ EditorPrefs . SetBool ( SHOW_ROTATION_PREF , value ) ;
53
+ }
27
54
}
28
55
56
+ /// <summary>
57
+ /// Returns true if handle movement should be mirrored, otherwise false.
58
+ /// </summary>
29
59
public static bool ShouldMirrorHandleMovement
30
60
{
31
- get { return GetBoolPref ( MIRROR_HANDLE_MOVEMENT_PREF , MIRROR_HANDLE_MOVEMENT_DEFAULT ) ; }
32
- set { EditorPrefs . SetBool ( MIRROR_HANDLE_MOVEMENT_PREF , value ) ; }
61
+ get
62
+ {
63
+ if ( ! _shouldMirrorHandleMovement . HasValue )
64
+ {
65
+ _shouldMirrorHandleMovement = GetBoolPref ( MIRROR_HANDLE_MOVEMENT_PREF , MIRROR_HANDLE_MOVEMENT_DEFAULT ) ;
66
+ }
67
+
68
+ return _shouldMirrorHandleMovement . Value ;
69
+ }
70
+ set
71
+ {
72
+ _shouldMirrorHandleMovement = value ;
73
+
74
+ EditorPrefs . SetBool ( MIRROR_HANDLE_MOVEMENT_PREF , value ) ;
75
+ }
76
+ }
77
+
78
+ /// <summary>
79
+ /// The maximum distance from the SceneView camera at which editor graphics should be drawn for the curve before
80
+ /// being culled.
81
+ /// </summary>
82
+ public static float MaximumViewDistance
83
+ {
84
+ get
85
+ {
86
+ if ( ! _maximumViewDistance . HasValue )
87
+ {
88
+ _maximumViewDistance = GetFloatPref ( MAX_VIEW_DISTANCE_PREF , MAX_VIEW_DISTANCE_DEFAULT ) ;
89
+ }
90
+
91
+ return _maximumViewDistance . Value ;
92
+ }
93
+ set
94
+ {
95
+ _maximumViewDistance = value ;
96
+
97
+ EditorPrefs . SetFloat ( MAX_VIEW_DISTANCE_PREF , value ) ;
98
+ }
33
99
}
34
100
101
+ // Caching layer
102
+ private static bool ? _isDebugEnabled ;
103
+ private static bool ? _shouldVisualizeRotation ;
104
+ private static bool ? _shouldMirrorHandleMovement ;
105
+ private static float ? _maximumViewDistance ;
106
+
35
107
// UI
36
108
private const string PREFERENCES_TITLE_PATH = "Preferences/JCMG Curves" ;
37
109
private const string USER_PREFERENCES_HEADER = "User Preferences" ;
@@ -49,10 +121,12 @@ public static bool ShouldMirrorHandleMovement
49
121
private const string SHOW_ROTATION_PREF = "JCMG.Curves.ShowRotationVisualization" ;
50
122
private const string ENABLE_DEBUG_PREF = "JCMG.Curves.EnableDebug" ;
51
123
private const string MIRROR_HANDLE_MOVEMENT_PREF = "JCMG.Curves.MirrorHandleMovement" ;
124
+ private const string MAX_VIEW_DISTANCE_PREF = "JCMG.Curves.MaximumViewDistance" ;
52
125
53
126
private const bool SHOW_ROTATION_DEFAULT = true ;
54
127
private const bool ENABLE_DEBUG_DEFAULT = true ;
55
128
private const bool MIRROR_HANDLE_MOVEMENT_DEFAULT = true ;
129
+ private const float MAX_VIEW_DISTANCE_DEFAULT = 200f ;
56
130
57
131
static CurvePreferences ( )
58
132
{
@@ -131,6 +205,25 @@ private static void DrawPersonalPrefsGUI(string value = "")
131
205
SceneView . RepaintAll ( ) ;
132
206
}
133
207
}
208
+
209
+ // Max View Distance
210
+ EditorGUILayout . Space ( ) ;
211
+ EditorGUILayout . HelpBox (
212
+ "The maximum distance at which the curve orientation and other secondary graphics will be drawn in the " +
213
+ "SceneView." ,
214
+ MessageType . Info ) ;
215
+
216
+ GUI . changed = false ;
217
+ using ( new EditorGUILayout . HorizontalScope ( ) )
218
+ {
219
+ EditorGUILayout . LabelField ( "Maximum View Distance" , MAX_WIDTH ) ;
220
+ var newViewDistance = Mathf . Max ( 0 , EditorGUILayout . FloatField ( MaximumViewDistance , MAX_WIDTH ) ) ;
221
+ if ( GUI . changed )
222
+ {
223
+ MaximumViewDistance = newViewDistance ;
224
+ SceneView . RepaintAll ( ) ;
225
+ }
226
+ }
134
227
}
135
228
136
229
/// <summary>
@@ -148,5 +241,21 @@ private static bool GetBoolPref(string key, bool defaultValue)
148
241
149
242
return EditorPrefs . GetBool ( key ) ;
150
243
}
244
+
245
+ /// <summary>
246
+ /// Returns the current float preference; if none exists, the default is set and returned.
247
+ /// </summary>
248
+ /// <param name="key"></param>
249
+ /// <param name="defaultValue"></param>
250
+ /// <returns></returns>
251
+ private static float GetFloatPref ( string key , float defaultValue )
252
+ {
253
+ if ( ! EditorPrefs . HasKey ( key ) )
254
+ {
255
+ EditorPrefs . SetFloat ( key , defaultValue ) ;
256
+ }
257
+
258
+ return EditorPrefs . GetFloat ( key ) ;
259
+ }
151
260
}
152
261
}
0 commit comments