Skip to content

Commit f0d65c1

Browse files
authored
Merge pull request #7010 from Troy-Ferrell/users/trferrel/line-renderer-fix
Fix Line Renderer editor error
2 parents 5151c00 + 5cbb01a commit f0d65c1

File tree

5 files changed

+52
-24
lines changed

5 files changed

+52
-24
lines changed

Assets/MixedRealityToolkit/Utilities/Lines/DataProviders/EllipseLineDataProvider.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,29 @@ namespace Microsoft.MixedReality.Toolkit.Utilities
1313
public class EllipseLineDataProvider : BaseMixedRealityLineDataProvider
1414
{
1515
[SerializeField]
16-
[Range(0, 2048)]
16+
[Tooltip("Resolution is the number of points used to define positions for points on the line. Equivalent to PointCount. Clamped at 2048 max")]
17+
[Range(0, MaxResolution)]
1718
private int resolution = 36;
1819

20+
/// <summary>
21+
/// Resolution is the number of points used to define positions for points on the line. Equivalent to PointCount. Clamped at 2048 max
22+
/// </summary>
1923
public int Resolution
2024
{
21-
get { return resolution; }
22-
set { resolution = Mathf.Clamp(value, 0, 2048); }
25+
get => resolution;
26+
set => resolution = Mathf.Clamp(value, 0, MaxResolution);
2327
}
2428

29+
[Tooltip("Radius of ellipsis defined by Vector2 where x is half-width and y is half-height")]
2530
[SerializeField]
2631
private Vector2 radius = Vector2.one;
2732

33+
/// <summary>
34+
/// Radius of ellipsis defined by Vector2 where x is half-width and y is half-height
35+
/// </summary>
2836
public Vector2 Radius
2937
{
30-
get { return radius; }
38+
get => radius;
3139
set
3240
{
3341
if (value.x < 0)
@@ -44,22 +52,25 @@ public Vector2 Radius
4452
}
4553
}
4654

55+
private const int MaxResolution = 2048;
56+
57+
4758
#region BaseMixedRealityLineDataProvider Implementation
4859

4960
/// <inheritdoc />
50-
public override int PointCount => resolution;
61+
public override int PointCount => Resolution;
5162

5263
/// <inheritdoc />
5364
protected override Vector3 GetPointInternal(float normalizedDistance)
5465
{
55-
return LineUtility.GetEllipsePoint(radius, normalizedDistance * 2f * Mathf.PI);
66+
return LineUtility.GetEllipsePoint(Radius, normalizedDistance * 2f * Mathf.PI);
5667
}
5768

5869
/// <inheritdoc />
5970
protected override Vector3 GetPointInternal(int pointIndex)
6071
{
61-
float angle = ((float)pointIndex / resolution) * 2f * Mathf.PI;
62-
return LineUtility.GetEllipsePoint(radius, angle);
72+
float angle = ((float)pointIndex / Resolution) * 2f * Mathf.PI;
73+
return LineUtility.GetEllipsePoint(Radius, angle);
6374
}
6475

6576
/// <inheritdoc />

Assets/MixedRealityToolkit/Utilities/Lines/DataProviders/SimpleLineDataProvider.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ namespace Microsoft.MixedReality.Toolkit.Utilities
1111
[AddComponentMenu("Scripts/MRTK/Core/SimpleLineDataProvider")]
1212
public class SimpleLineDataProvider : BaseMixedRealityLineDataProvider
1313
{
14+
[Tooltip("The starting point of this line.")]
1415
[SerializeField]
1516
private MixedRealityPose startPoint = MixedRealityPose.ZeroIdentity;
1617

1718
/// <summary>
18-
/// The Starting point of this line.
19+
/// The starting point of this line which is always located at the GameObject's transform position
1920
/// </summary>
2021
/// <remarks>Always located at this <see href="https://docs.unity3d.com/ScriptReference/GameObject.html">GameObject</see>'s <see href="https://docs.unity3d.com/ScriptReference/Transform-position.html">Transform.position</see></remarks>
2122
public MixedRealityPose StartPoint => startPoint;
@@ -29,8 +30,8 @@ public class SimpleLineDataProvider : BaseMixedRealityLineDataProvider
2930
/// </summary>
3031
public MixedRealityPose EndPoint
3132
{
32-
get { return endPoint; }
33-
set { endPoint = value; }
33+
get => endPoint;
34+
set => endPoint = value;
3435
}
3536

3637
#region Line Data Provider Implementation
@@ -44,9 +45,9 @@ protected override Vector3 GetPointInternal(int pointIndex)
4445
switch (pointIndex)
4546
{
4647
case 0:
47-
return startPoint.Position;
48+
return StartPoint.Position;
4849
case 1:
49-
return endPoint.Position;
50+
return EndPoint.Position;
5051
default:
5152
Debug.LogError("Invalid point index");
5253
return Vector3.zero;
@@ -73,13 +74,13 @@ protected override void SetPointInternal(int pointIndex, Vector3 point)
7374
/// <inheritdoc />
7475
protected override Vector3 GetPointInternal(float normalizedDistance)
7576
{
76-
return Vector3.Lerp(startPoint.Position, endPoint.Position, normalizedDistance);
77+
return Vector3.Lerp(StartPoint.Position, EndPoint.Position, normalizedDistance);
7778
}
7879

7980
/// <inheritdoc />
8081
protected override float GetUnClampedWorldLengthInternal()
8182
{
82-
return Vector3.Distance(startPoint.Position, endPoint.Position);
83+
return Vector3.Distance(StartPoint.Position, EndPoint.Position);
8384
}
8485

8586
/// <inheritdoc />

Assets/MixedRealityToolkit/Utilities/Lines/DataProviders/SplineDataProvider.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Microsoft.MixedReality.Toolkit.Utilities
1111
[AddComponentMenu("Scripts/MRTK/Core/SplineDataProvider")]
1212
public class SplineDataProvider : BaseMixedRealityLineDataProvider
1313
{
14+
[Tooltip("List of positions and orientations that define control points to generate the spline")]
1415
[SerializeField]
1516
private MixedRealityPose[] controlPoints =
1617
{
@@ -20,14 +21,17 @@ public class SplineDataProvider : BaseMixedRealityLineDataProvider
2021
new MixedRealityPose(Vector3.right, Quaternion.identity),
2122
};
2223

24+
/// <summary>
25+
/// List of positions and orientations that define control points to generate the spline
26+
/// </summary>
2327
public MixedRealityPose[] ControlPoints => controlPoints;
2428

2529
[SerializeField]
2630
private bool alignAllControlPoints = true;
2731

2832
public bool AlignAllControlPoints
2933
{
30-
get { return alignAllControlPoints; }
34+
get => alignAllControlPoints;
3135
set
3236
{
3337
if (alignAllControlPoints != value)
@@ -43,7 +47,7 @@ public bool AlignAllControlPoints
4347
/// </summary>
4448
public void ForceUpdateAlignment()
4549
{
46-
if (alignAllControlPoints)
50+
if (AlignAllControlPoints)
4751
{
4852
for (int i = 0; i < PointCount; i++)
4953
{
@@ -54,7 +58,7 @@ public void ForceUpdateAlignment()
5458

5559
private void UpdatePointAlignment(int pointIndex)
5660
{
57-
if (alignAllControlPoints)
61+
if (AlignAllControlPoints)
5862
{
5963
int prevControlPoint;
6064
int changedControlPoint;
@@ -187,7 +191,7 @@ protected override void SetPointInternal(int pointIndex, Vector3 point)
187191
pointIndex = 0;
188192
}
189193

190-
if (alignAllControlPoints)
194+
if (AlignAllControlPoints)
191195
{
192196
if (pointIndex % 3 == 0)
193197
{
@@ -271,4 +275,4 @@ protected override float GetUnClampedWorldLengthInternal()
271275

272276
#endregion BaseMixedRealityLineDataProvider Implementation
273277
}
274-
}
278+
}

Assets/MixedRealityToolkit/Utilities/Lines/Renderers/BaseMixedRealityLineRenderer.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class BaseMixedRealityLineRenderer : MonoBehaviour
1616
protected BaseMixedRealityLineDataProvider lineDataSource;
1717

1818
/// <summary>
19-
/// The line data this component will render
19+
/// The data provider component that provides the positioning source information for the LineRenderer.
2020
/// </summary>
2121
public BaseMixedRealityLineDataProvider LineDataSource
2222
{
@@ -192,6 +192,10 @@ protected virtual float GetWidth(float normalizedLength)
192192
return LineWidth.Evaluate(Mathf.Repeat(normalizedLength + widthOffset, 1f)) * widthMultiplier;
193193
}
194194

195+
/// <summary>
196+
/// Gets the normalized distance along the line path (range 0 to 1) going the given number of steps provided
197+
/// </summary>
198+
/// <param name="stepNum">Number of steps to take "walking" along the curve </param>
195199
protected virtual float GetNormalizedPointAlongLine(int stepNum)
196200
{
197201
float normalizedDistance = 0;
@@ -225,9 +229,15 @@ private void LateUpdate()
225229
UpdateLine();
226230
}
227231

232+
/// <summary>
233+
/// Executes every Unity LateUpdate(). Any property updates or frame updates should occur here to update the line data source.
234+
/// </summary>
228235
protected abstract void UpdateLine();
229236

230-
#if UNITY_EDITOR
237+
#region Gizmos
238+
239+
#if UNITY_EDITOR
240+
231241
protected virtual void OnDrawGizmos()
232242
{
233243
if (UnityEditor.Selection.activeGameObject == gameObject || Application.isPlaying) { return; }
@@ -321,6 +331,8 @@ private void GizmosDrawLineInterpolated()
321331
Gizmos.DrawLine(lastPos, firstPos);
322332
}
323333
}
324-
#endif
334+
335+
#endif
336+
#endregion
325337
}
326338
}

Assets/MixedRealityToolkit/Utilities/Lines/Renderers/MixedRealityLineRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private void OnEnable()
125125
enabled = false;
126126
}
127127

128-
if (FadeLineBrightnessOnEnable)
128+
if (FadeLineBrightnessOnEnable && Application.isPlaying)
129129
{
130130
fadeLine = StartCoroutine(FadeLine(FadeLinePercentage, FadeLineAnimationTime));
131131
}

0 commit comments

Comments
 (0)