diff --git a/Curves/Scripts/Editor/CurvePreferences.cs b/Curves/Scripts/Editor/CurvePreferences.cs index c38f155..bce5189 100644 --- a/Curves/Scripts/Editor/CurvePreferences.cs +++ b/Curves/Scripts/Editor/CurvePreferences.cs @@ -13,8 +13,22 @@ public static class CurvePreferences /// public static bool IsDebugEnabled { - get { return GetBoolPref(ENABLE_DEBUG_PREF, ENABLE_DEBUG_DEFAULT); } - set { EditorPrefs.SetBool(ENABLE_DEBUG_PREF, value); } + get + { + if (!_isDebugEnabled.HasValue) + { + _isDebugEnabled = GetBoolPref(ENABLE_DEBUG_PREF, ENABLE_DEBUG_DEFAULT); + } + + return _isDebugEnabled.Value; + + } + set + { + _isDebugEnabled = value; + + EditorPrefs.SetBool(ENABLE_DEBUG_PREF, value); + } } /// @@ -22,16 +36,74 @@ public static bool IsDebugEnabled /// public static bool ShouldVisualizeRotation { - get { return GetBoolPref(SHOW_ROTATION_PREF, SHOW_ROTATION_DEFAULT); } - set { EditorPrefs.SetBool(SHOW_ROTATION_PREF, value); } + get + { + if(!_shouldVisualizeRotation.HasValue) + { + _shouldVisualizeRotation = GetBoolPref(SHOW_ROTATION_PREF, SHOW_ROTATION_DEFAULT); + } + + return _shouldVisualizeRotation.Value; + } + set + { + _shouldVisualizeRotation = value; + + EditorPrefs.SetBool(SHOW_ROTATION_PREF, value); + } } + /// + /// Returns true if handle movement should be mirrored, otherwise false. + /// public static bool ShouldMirrorHandleMovement { - get { return GetBoolPref(MIRROR_HANDLE_MOVEMENT_PREF, MIRROR_HANDLE_MOVEMENT_DEFAULT); } - set { EditorPrefs.SetBool(MIRROR_HANDLE_MOVEMENT_PREF, value); } + get + { + if (!_shouldMirrorHandleMovement.HasValue) + { + _shouldMirrorHandleMovement = GetBoolPref(MIRROR_HANDLE_MOVEMENT_PREF, MIRROR_HANDLE_MOVEMENT_DEFAULT); + } + + return _shouldMirrorHandleMovement.Value; + } + set + { + _shouldMirrorHandleMovement = value; + + EditorPrefs.SetBool(MIRROR_HANDLE_MOVEMENT_PREF, value); + } + } + + /// + /// The maximum distance from the SceneView camera at which editor graphics should be drawn for the curve before + /// being culled. + /// + public static float MaximumViewDistance + { + get + { + if (!_maximumViewDistance.HasValue) + { + _maximumViewDistance = GetFloatPref(MAX_VIEW_DISTANCE_PREF, MAX_VIEW_DISTANCE_DEFAULT); + } + + return _maximumViewDistance.Value; + } + set + { + _maximumViewDistance = value; + + EditorPrefs.SetFloat(MAX_VIEW_DISTANCE_PREF, value); + } } + // Caching layer + private static bool? _isDebugEnabled; + private static bool? _shouldVisualizeRotation; + private static bool? _shouldMirrorHandleMovement; + private static float? _maximumViewDistance; + // UI private const string PREFERENCES_TITLE_PATH = "Preferences/JCMG Curves"; private const string USER_PREFERENCES_HEADER = "User Preferences"; @@ -49,10 +121,12 @@ public static bool ShouldMirrorHandleMovement private const string SHOW_ROTATION_PREF = "JCMG.Curves.ShowRotationVisualization"; private const string ENABLE_DEBUG_PREF = "JCMG.Curves.EnableDebug"; private const string MIRROR_HANDLE_MOVEMENT_PREF = "JCMG.Curves.MirrorHandleMovement"; + private const string MAX_VIEW_DISTANCE_PREF = "JCMG.Curves.MaximumViewDistance"; private const bool SHOW_ROTATION_DEFAULT = true; private const bool ENABLE_DEBUG_DEFAULT = true; private const bool MIRROR_HANDLE_MOVEMENT_DEFAULT = true; + private const float MAX_VIEW_DISTANCE_DEFAULT = 200f; static CurvePreferences() { @@ -131,6 +205,25 @@ private static void DrawPersonalPrefsGUI(string value = "") SceneView.RepaintAll(); } } + + // Max View Distance + EditorGUILayout.Space(); + EditorGUILayout.HelpBox( + "The maximum distance at which the curve orientation and other secondary graphics will be drawn in the " + + "SceneView.", + MessageType.Info); + + GUI.changed = false; + using (new EditorGUILayout.HorizontalScope()) + { + EditorGUILayout.LabelField("Maximum View Distance", MAX_WIDTH); + var newViewDistance = Mathf.Max(0, EditorGUILayout.FloatField(MaximumViewDistance, MAX_WIDTH)); + if (GUI.changed) + { + MaximumViewDistance = newViewDistance; + SceneView.RepaintAll(); + } + } } /// @@ -148,5 +241,21 @@ private static bool GetBoolPref(string key, bool defaultValue) return EditorPrefs.GetBool(key); } + + /// + /// Returns the current float preference; if none exists, the default is set and returned. + /// + /// + /// + /// + private static float GetFloatPref(string key, float defaultValue) + { + if (!EditorPrefs.HasKey(key)) + { + EditorPrefs.SetFloat(key, defaultValue); + } + + return EditorPrefs.GetFloat(key); + } } } diff --git a/Curves/Scripts/Editor/Inspectors/Bezier3DSplineDataInspector.cs b/Curves/Scripts/Editor/Inspectors/Bezier3DSplineDataInspector.cs index d5941bc..4fe29d4 100644 --- a/Curves/Scripts/Editor/Inspectors/Bezier3DSplineDataInspector.cs +++ b/Curves/Scripts/Editor/Inspectors/Bezier3DSplineDataInspector.cs @@ -5,7 +5,7 @@ namespace JCMG.Curves.Editor { [CustomEditor(typeof(Bezier3DSplineData))] - internal sealed class Bezier3DSplineDataInspector : UnityEditor.Editor + public sealed class Bezier3DSplineDataInspector : UnityEditor.Editor { /// /// Get or sets whether or not this inspector should be drawing the scene GUI. Default is true. @@ -32,7 +32,7 @@ public bool ShouldDrawSceneGUI } #pragma warning disable 0649 - public static event Action SplineUpdated; + public event Action SplineUpdated; #pragma warning restore 0649 private bool _shouldDrawSceneGUI; diff --git a/Curves/Scripts/Editor/Inspectors/Bezier3DSplineInspector.cs b/Curves/Scripts/Editor/Inspectors/Bezier3DSplineInspector.cs index 91f6ce0..3170cdb 100644 --- a/Curves/Scripts/Editor/Inspectors/Bezier3DSplineInspector.cs +++ b/Curves/Scripts/Editor/Inspectors/Bezier3DSplineInspector.cs @@ -4,10 +4,10 @@ namespace JCMG.Curves.Editor { [CustomEditor(typeof(Bezier3DSpline))] - internal sealed class Bezier3DSplineInspector : UnityEditor.Editor + public sealed class Bezier3DSplineInspector : UnityEditor.Editor { #pragma warning disable 0649 - public static event Action SplineUpdated; + public event Action SplineUpdated; #pragma warning restore 0649 private Bezier3DSpline _spline; diff --git a/Curves/Scripts/Editor/Tools/SceneGUITools.cs b/Curves/Scripts/Editor/Tools/SceneGUITools.cs index 710fb08..a3adcc3 100644 --- a/Curves/Scripts/Editor/Tools/SceneGUITools.cs +++ b/Curves/Scripts/Editor/Tools/SceneGUITools.cs @@ -7,7 +7,7 @@ namespace JCMG.Curves.Editor /// /// Helper methods for drawing in the scene /// - internal static class SceneGUITools + public static class SceneGUITools { public static void DrawCurveLinesHandles(IBezier3DSplineData splineData, Transform transform = null) { @@ -61,10 +61,18 @@ public static void DrawCurveLinesHandles(IBezier3DSplineData splineData, Transfo public static void DrawCurveOrientations(IBezier3DSplineData splineData) { + var sceneViewCameraPosition = SceneView.lastActiveSceneView.camera.transform.position; + var maxViewDistance = CurvePreferences.MaximumViewDistance; + for (var dist = 0f; dist < splineData.TotalLength; dist += 1) { var point = splineData.GetPosition(dist); + if (Vector3.Distance(sceneViewCameraPosition, point) > maxViewDistance) + { + continue; + } + // Draw Up Vector var up = splineData.GetUp(dist); Handles.color = Handles.yAxisColor; diff --git a/Curves/Scripts/Tools/SceneGUITools.cs b/Curves/Scripts/Tools/SceneGUITools.cs index f12afe0..ae1dc28 100644 --- a/Curves/Scripts/Tools/SceneGUITools.cs +++ b/Curves/Scripts/Tools/SceneGUITools.cs @@ -5,7 +5,7 @@ namespace JCMG.Curves /// /// Helper methods for drawing in the scene /// - internal static class SceneGUITools + public static class SceneGUITools { public static void DrawCurveLinesGizmos(IBezier3DSplineData splineData, Transform transform = null) { diff --git a/package.json b/package.json index ed172fe..8df58d1 100644 --- a/package.json +++ b/package.json @@ -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":""} \ No newline at end of file +{"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":""} \ No newline at end of file