13 public class LineBaseEditor : MRTKEditor
16 public static readonly Color DefaultDisplayLineColor = Color.white;
17 protected static readonly Color lineVelocityColor =
new Color(0.9f, 1f, 0f, 0.8f);
18 protected const int linePreviewResolutionUnselected = 16;
21 protected static int linePreviewResolutionSelected = 16;
22 protected static bool drawLinePoints =
false;
23 protected static bool drawDottedLine =
true;
24 protected static bool drawLineRotations =
false;
25 protected static bool drawLineManualUpVectors =
false;
26 protected static float lineRotationLength = 0.5f;
27 protected static float lineManualUpVectorLength = 10f;
31 protected override void DrawCustomSceneGUI()
34 bool selected = Selection.activeGameObject == line.gameObject;
36 int previewResolution = Mathf.Min(linePreviewResolutionSelected, linePreviewResolutionUnselected);
39 previewResolution = linePreviewResolutionSelected;
45 DrawDottedLine(line, previewResolution);
49 if (drawLineRotations && selected)
51 DrawLineRotations(line, previewResolution);
55 if (drawLineManualUpVectors && selected)
57 DrawManualUpVectorHandles(line);
69 protected override void DrawCustomFooter()
73 if (DrawSectionStart(line.name +
" Editor",
"Editor Settings"))
75 linePreviewResolutionSelected = EditorGUILayout.IntSlider(
"Preview resolution", linePreviewResolutionSelected, 3, 100);
77 drawDottedLine = EditorGUILayout.Toggle(
"Draw Dotted Line", drawDottedLine);
78 drawLinePoints = EditorGUILayout.Toggle(
"Draw Line Points", drawLinePoints);
79 drawLineRotations = EditorGUILayout.Toggle(
"Draw Line Rotations", drawLineRotations);
80 drawLineManualUpVectors = EditorGUILayout.Toggle(
"Draw Manual Up Vectors", drawLineManualUpVectors);
82 if (drawLineRotations)
84 lineRotationLength = EditorGUILayout.Slider(
"Rotation Arrow Length", lineRotationLength, 0.01f, 5f);
87 if (drawLineManualUpVectors)
89 lineManualUpVectorLength = EditorGUILayout.Slider(
"Manual Up Vector Length", lineManualUpVectorLength, 1f, 10f);
90 if (GUILayout.Button(
"Normalize Up Vectors"))
95 if (upVector == Vector3.zero)
97 upVector = Vector3.up;
107 SceneView.RepaintAll();
110 protected void DrawDottedLine(
LineBase line,
int numSteps)
112 Vector3 firstPos = Vector3.zero;
113 Vector3 lastPos = Vector3.zero;
115 switch (EditorStepMode)
123 Vector3 currentPos = line.
GetPoint(i);
124 Handles.DrawDottedLine(lastPos, currentPos, MRTKEditor.DottedLineScreenSpace);
125 lastPos = currentPos;
130 Handles.DrawDottedLine(lastPos, firstPos, MRTKEditor.DottedLineScreenSpace);
138 Handles.color = DefaultDisplayLineColor;
140 for (
int i = 1; i < numSteps; i++)
142 float normalizedLength = (1f / (numSteps - 1)) * i;
143 Vector3 currentPos = line.
GetPoint(normalizedLength);
144 Handles.DrawDottedLine(lastPos, currentPos, MRTKEditor.DottedLineScreenSpace);
145 lastPos = currentPos;
150 Handles.DrawDottedLine(lastPos, firstPos, MRTKEditor.DottedLineScreenSpace);
156 protected void DrawLinePoints(
LineBase line)
158 Handles.color = DefaultDisplayLineColor;
159 float dotSize = HandleUtility.GetHandleSize(line.transform.position) * 0.025f;
162 Handles.DotHandleCap(0, line.
GetPoint(i), Quaternion.identity, dotSize, EventType.Repaint);
166 protected void DrawLineRotations(
LineBase line,
int numSteps)
168 Handles.color = lineVelocityColor;
169 float arrowSize = HandleUtility.GetHandleSize(line.transform.position) * lineRotationLength;
171 for (
int i = 1; i < numSteps; i++)
173 float normalizedLength = (1f / (numSteps - 1)) * i;
174 Vector3 currentPos = line.
GetPoint(normalizedLength);
175 Quaternion rotation = line.
GetRotation(normalizedLength);
177 Handles.color = Color.Lerp(lineVelocityColor, Handles.zAxisColor, 0.75f);
178 Handles.ArrowHandleCap(0, currentPos, Quaternion.LookRotation(rotation * Vector3.forward), arrowSize, EventType.Repaint);
179 Handles.color = Color.Lerp(lineVelocityColor, Handles.xAxisColor, 0.75f);
180 Handles.ArrowHandleCap(0, currentPos, Quaternion.LookRotation(rotation * Vector3.right), arrowSize, EventType.Repaint);
181 Handles.color = Color.Lerp(lineVelocityColor, Handles.yAxisColor, 0.75f);
182 Handles.ArrowHandleCap(0, currentPos, Quaternion.LookRotation(rotation * Vector3.up), arrowSize, EventType.Repaint);
186 protected void DrawManualUpVectorHandles(
LineBase line)
194 Vector3 currentPoint = line.
GetPoint(normalizedLength);
196 line.
ManualUpVectors[i] = VectorHandle(currentPoint, currentUpVector,
false, lineManualUpVectorLength);