Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jzapdot committed Feb 22, 2020
1 parent bdf2d19 commit 21ce13b
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 13 deletions.
121 changes: 115 additions & 6 deletions Curves/Scripts/Editor/CurvePreferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,97 @@ public static class CurvePreferences
/// </summary>
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);
}
}

/// <summary>
/// Returns true if rotation visualization info should be enabled, otherwise false.
/// </summary>
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);
}
}

/// <summary>
/// Returns true if handle movement should be mirrored, otherwise false.
/// </summary>
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);
}
}

/// <summary>
/// The maximum distance from the SceneView camera at which editor graphics should be drawn for the curve before
/// being culled.
/// </summary>
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";
Expand All @@ -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()
{
Expand Down Expand Up @@ -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();
}
}
}

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

return EditorPrefs.GetBool(key);
}

/// <summary>
/// Returns the current float preference; if none exists, the default is set and returned.
/// </summary>
/// <param name="key"></param>
/// <param name="defaultValue"></param>
/// <returns></returns>
private static float GetFloatPref(string key, float defaultValue)
{
if (!EditorPrefs.HasKey(key))
{
EditorPrefs.SetFloat(key, defaultValue);
}

return EditorPrefs.GetFloat(key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace JCMG.Curves.Editor
{
[CustomEditor(typeof(Bezier3DSplineData))]
internal sealed class Bezier3DSplineDataInspector : UnityEditor.Editor
public sealed class Bezier3DSplineDataInspector : UnityEditor.Editor
{
/// <summary>
/// Get or sets whether or not this inspector should be drawing the scene GUI. Default is true.
Expand All @@ -32,7 +32,7 @@ public bool ShouldDrawSceneGUI
}

#pragma warning disable 0649
public static event Action<IReadOnly3DSplineData> SplineUpdated;
public event Action<IReadOnly3DSplineData> SplineUpdated;
#pragma warning restore 0649

private bool _shouldDrawSceneGUI;
Expand Down
4 changes: 2 additions & 2 deletions Curves/Scripts/Editor/Inspectors/Bezier3DSplineInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IReadOnly3DSplineData> SplineUpdated;
public event Action<IReadOnly3DSplineData> SplineUpdated;
#pragma warning restore 0649

private Bezier3DSpline _spline;
Expand Down
10 changes: 9 additions & 1 deletion Curves/Scripts/Editor/Tools/SceneGUITools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace JCMG.Curves.Editor
/// <summary>
/// Helper methods for drawing in the scene
/// </summary>
internal static class SceneGUITools
public static class SceneGUITools
{
public static void DrawCurveLinesHandles(IBezier3DSplineData splineData, Transform transform = null)
{
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Curves/Scripts/Tools/SceneGUITools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace JCMG.Curves
/// <summary>
/// Helper methods for drawing in the scene
/// </summary>
internal static class SceneGUITools
public static class SceneGUITools
{
public static void DrawCurveLinesGizmos(IBezier3DSplineData splineData, Transform transform = null)
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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":""}
{"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 comments on commit 21ce13b

Please sign in to comment.