12 [Tooltip(
"The source Line this component will render")]
15 [Header(
"Visual Settings")]
16 [Tooltip(
"Color gradient applied to line's normalized length")]
19 public AnimationCurve LineWidth = AnimationCurve.Linear(0f, 0.05f, 1f, 0.05f);
21 public float WidthMultiplier = 0.25f;
25 [Tooltip(
"Normalized offset for color gradient")]
26 public float ColorOffset = 0f;
28 [Tooltip(
"Normalized offset for width curve")]
29 public float WidthOffset = 0f;
31 [Tooltip(
"Normalized offset for rotation offset")]
32 public float RotationOffset = 0f;
34 [Header(
"Point Placement")]
35 [Tooltip(
"Method for gathering points along line. Interpolated uses normalized length. FromSource uses line's base points. (FromSource may not look right for all Line types.)")]
38 [Tooltip(
"Number of steps to interpolate along line in Interpolated step mode")]
40 public int NumLineSteps = 10;
46 public float StepLength = 0.05f;
49 public int MaxLineSteps = 2048;
51 public AnimationCurve StepLengthCurve = AnimationCurve.Linear(0f, 1f, 1f, 0.5f);
59 source = GetComponent<LineBase>();
73 protected virtual Color
GetColor(
float normalizedLength)
75 if (LineColor == null)
77 LineColor =
new Gradient();
80 return LineColor.Evaluate(Mathf.Repeat(normalizedLength + ColorOffset, 1f));
83 protected virtual float GetWidth(
float normalizedLength)
85 if (LineWidth == null)
87 LineWidth = AnimationCurve.Linear(0f, 1f, 1f, 1f);
90 return LineWidth.Evaluate(Mathf.Repeat(normalizedLength + WidthOffset, 1f)) * WidthMultiplier;
93 private float[] normalizedLengths;
96 protected virtual void OnDrawGizmos()
98 if (Application.isPlaying)
102 source = gameObject.GetComponent<
LineBase>();
103 if (source == null || !source.enabled)
106 GizmosDrawLineRenderer(source,
this);
114 GizmosDrawLineFromSource(source, renderer);
118 GizmosDrawLineInterpolated(source, renderer);
125 Vector3 firstPos = source.
GetPoint(0);
126 Vector3 lastPos = firstPos;
127 Color gColor = renderer.
GetColor(0);
130 Gizmos.color = gColor;
131 Gizmos.DrawSphere(firstPos, renderer.
GetWidth(0) / 2);
132 for (
int i = 1; i < source.
NumPoints; i++)
134 float normalizedLength = (1f / (source.
NumPoints)) * i;
135 Vector3 currentPos = source.
GetPoint(i);
136 gColor = renderer.
GetColor(normalizedLength);
137 gColor.a = gColor.a * 0.5f;
138 Gizmos.color = gColor;
139 Gizmos.DrawLine(lastPos, currentPos);
140 Gizmos.DrawSphere(currentPos, renderer.
GetWidth(normalizedLength) / 2);
141 lastPos = currentPos;
146 Gizmos.DrawLine(lastPos, firstPos);
152 Vector3 firstPos = source.
GetPoint(0f);
153 Vector3 lastPos = firstPos;
154 Color gColor = renderer.
GetColor(0);
157 Gizmos.color = gColor;
158 Gizmos.DrawSphere(firstPos, renderer.
GetWidth(0) / 2);
161 float normalizedLength = (1f / (renderer.
NumLineSteps)) * i;
162 Vector3 currentPos = source.
GetPoint(normalizedLength);
163 gColor = renderer.
GetColor(normalizedLength);
164 gColor.a = gColor.a * 0.5f;
165 Gizmos.color = gColor;
166 Gizmos.DrawLine(lastPos, currentPos);
167 Gizmos.DrawSphere(currentPos, renderer.
GetWidth(normalizedLength) / 2);
168 lastPos = currentPos;
173 Gizmos.DrawLine(lastPos, firstPos);