Skip to content

Commit 21ce13b

Browse files
committed
v1.1.1
* Verified support for 2019.3.6 * Changed several access modifiers from internal to public for inspectors, SceneGUITools helper class. * Created new preference for view distance; this controls how far from the SceneView camera the orientation handles are drawn and can be a performance enhancement for large splines
1 parent bdf2d19 commit 21ce13b

File tree

6 files changed

+130
-13
lines changed

6 files changed

+130
-13
lines changed

Curves/Scripts/Editor/CurvePreferences.cs

Lines changed: 115 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,97 @@ public static class CurvePreferences
1313
/// </summary>
1414
public static bool IsDebugEnabled
1515
{
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+
}
1832
}
1933

2034
/// <summary>
2135
/// Returns true if rotation visualization info should be enabled, otherwise false.
2236
/// </summary>
2337
public static bool ShouldVisualizeRotation
2438
{
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+
}
2754
}
2855

56+
/// <summary>
57+
/// Returns true if handle movement should be mirrored, otherwise false.
58+
/// </summary>
2959
public static bool ShouldMirrorHandleMovement
3060
{
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+
}
3399
}
34100

101+
// Caching layer
102+
private static bool? _isDebugEnabled;
103+
private static bool? _shouldVisualizeRotation;
104+
private static bool? _shouldMirrorHandleMovement;
105+
private static float? _maximumViewDistance;
106+
35107
// UI
36108
private const string PREFERENCES_TITLE_PATH = "Preferences/JCMG Curves";
37109
private const string USER_PREFERENCES_HEADER = "User Preferences";
@@ -49,10 +121,12 @@ public static bool ShouldMirrorHandleMovement
49121
private const string SHOW_ROTATION_PREF = "JCMG.Curves.ShowRotationVisualization";
50122
private const string ENABLE_DEBUG_PREF = "JCMG.Curves.EnableDebug";
51123
private const string MIRROR_HANDLE_MOVEMENT_PREF = "JCMG.Curves.MirrorHandleMovement";
124+
private const string MAX_VIEW_DISTANCE_PREF = "JCMG.Curves.MaximumViewDistance";
52125

53126
private const bool SHOW_ROTATION_DEFAULT = true;
54127
private const bool ENABLE_DEBUG_DEFAULT = true;
55128
private const bool MIRROR_HANDLE_MOVEMENT_DEFAULT = true;
129+
private const float MAX_VIEW_DISTANCE_DEFAULT = 200f;
56130

57131
static CurvePreferences()
58132
{
@@ -131,6 +205,25 @@ private static void DrawPersonalPrefsGUI(string value = "")
131205
SceneView.RepaintAll();
132206
}
133207
}
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+
}
134227
}
135228

136229
/// <summary>
@@ -148,5 +241,21 @@ private static bool GetBoolPref(string key, bool defaultValue)
148241

149242
return EditorPrefs.GetBool(key);
150243
}
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+
}
151260
}
152261
}

Curves/Scripts/Editor/Inspectors/Bezier3DSplineDataInspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace JCMG.Curves.Editor
66
{
77
[CustomEditor(typeof(Bezier3DSplineData))]
8-
internal sealed class Bezier3DSplineDataInspector : UnityEditor.Editor
8+
public sealed class Bezier3DSplineDataInspector : UnityEditor.Editor
99
{
1010
/// <summary>
1111
/// Get or sets whether or not this inspector should be drawing the scene GUI. Default is true.
@@ -32,7 +32,7 @@ public bool ShouldDrawSceneGUI
3232
}
3333

3434
#pragma warning disable 0649
35-
public static event Action<IReadOnly3DSplineData> SplineUpdated;
35+
public event Action<IReadOnly3DSplineData> SplineUpdated;
3636
#pragma warning restore 0649
3737

3838
private bool _shouldDrawSceneGUI;

Curves/Scripts/Editor/Inspectors/Bezier3DSplineInspector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
namespace JCMG.Curves.Editor
55
{
66
[CustomEditor(typeof(Bezier3DSpline))]
7-
internal sealed class Bezier3DSplineInspector : UnityEditor.Editor
7+
public sealed class Bezier3DSplineInspector : UnityEditor.Editor
88
{
99
#pragma warning disable 0649
10-
public static event Action<IReadOnly3DSplineData> SplineUpdated;
10+
public event Action<IReadOnly3DSplineData> SplineUpdated;
1111
#pragma warning restore 0649
1212

1313
private Bezier3DSpline _spline;

Curves/Scripts/Editor/Tools/SceneGUITools.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace JCMG.Curves.Editor
77
/// <summary>
88
/// Helper methods for drawing in the scene
99
/// </summary>
10-
internal static class SceneGUITools
10+
public static class SceneGUITools
1111
{
1212
public static void DrawCurveLinesHandles(IBezier3DSplineData splineData, Transform transform = null)
1313
{
@@ -61,10 +61,18 @@ public static void DrawCurveLinesHandles(IBezier3DSplineData splineData, Transfo
6161

6262
public static void DrawCurveOrientations(IBezier3DSplineData splineData)
6363
{
64+
var sceneViewCameraPosition = SceneView.lastActiveSceneView.camera.transform.position;
65+
var maxViewDistance = CurvePreferences.MaximumViewDistance;
66+
6467
for (var dist = 0f; dist < splineData.TotalLength; dist += 1)
6568
{
6669
var point = splineData.GetPosition(dist);
6770

71+
if (Vector3.Distance(sceneViewCameraPosition, point) > maxViewDistance)
72+
{
73+
continue;
74+
}
75+
6876
// Draw Up Vector
6977
var up = splineData.GetUp(dist);
7078
Handles.color = Handles.yAxisColor;

Curves/Scripts/Tools/SceneGUITools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace JCMG.Curves
55
/// <summary>
66
/// Helper methods for drawing in the scene
77
/// </summary>
8-
internal static class SceneGUITools
8+
public static class SceneGUITools
99
{
1010
public static void DrawCurveLinesGizmos(IBezier3DSplineData splineData, Transform transform = null)
1111
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"com.jeffcampbellmakesgames.curves","displayName":"JCMG Curves","version":"1.0.0","unity":"2019.3","description":"JCMG Curves is a 3D Bezier curve library focused on ease of use in both its API and Unity Editor integration.","keywords":["Curve","Curves"],"category":""}
1+
{"name":"com.jeffcampbellmakesgames.curves","displayName":"JCMG Curves","version":"1.1.0","unity":"2019.3","description":"JCMG Curves is a 3D Bezier curve library focused on ease of use in both its API and Unity Editor integration.","keywords":["Curve","Curves"],"category":""}

0 commit comments

Comments
 (0)