public override void DrawInspector() { base.DrawInspector(); if (Event.current.type == EventType.MouseUp) { GetSplineLength(); } spline.editorPathColor = EditorGUILayout.ColorField("Color in Scene", spline.editorPathColor); bool lastAlwaysDraw = spline.alwaysDraw; spline.alwaysDraw = EditorGUILayout.Toggle("Always Draw Spline", spline.alwaysDraw); if (lastAlwaysDraw != spline.alwaysDraw) { if (spline.alwaysDraw) { DSSplineDrawer.RegisterComputer(spline); } else { DSSplineDrawer.UnregisterComputer(spline); } } spline.drawThinckness = EditorGUILayout.Toggle("Draw thickness", spline.drawThinckness); if (spline.drawThinckness) { EditorGUI.indentLevel++; spline.billboardThickness = EditorGUILayout.Toggle("Always face camera", spline.billboardThickness); EditorGUI.indentLevel--; } EditorGUILayout.Space(); EditorGUILayout.HelpBox("Samples: " + spline.samples.Length + "\n\r" + "Length: " + length, MessageType.Info); }
void ApplyPoints() { if (originalPoints.Count != imported.Count) { return; } if (imported.Count == 0) { return; } Quaternion lookRot = Quaternion.identity; switch (importAxis) { case Axis.X: lookRot = Quaternion.LookRotation(Vector3.right); break; case Axis.Y: lookRot = Quaternion.LookRotation(Vector3.down); break; case Axis.Z: lookRot = Quaternion.LookRotation(Vector3.forward); break; } for (int i = 0; i < imported.Count; i++) { SplinePoint[] transformed = new SplinePoint[originalPoints[i].Length]; originalPoints[i].CopyTo(transformed, 0); for (int j = 0; j < transformed.Length; j++) { transformed[j].position *= scaleFactor; transformed[j].tangent *= scaleFactor; transformed[j].tangent2 *= scaleFactor; transformed[j].position = lookRot * transformed[j].position; transformed[j].tangent = lookRot * transformed[j].tangent; transformed[j].tangent2 = lookRot * transformed[j].tangent2; transformed[j].normal = lookRot * transformed[j].normal; } imported[i].SetPoints(transformed); if (alwaysDraw) { DSSplineDrawer.RegisterComputer(imported[i]); } else { DSSplineDrawer.UnregisterComputer(imported[i]); } } SceneView.RepaintAll(); }
public override void Draw(Rect rect) { switch (Event.current.type) { case EventType.MouseDown: if (Event.current.button == 0) { mouseLeft = true; } break; case EventType.MouseUp: if (Event.current.button == 0) { mouseLeft = false; } break; } Rect lastRect; scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(rect.width), GUILayout.Height(rect.height)); EditorGUILayout.BeginHorizontal(normalRow); EditorGUILayout.LabelField("Name", EditorStyles.boldLabel, GUILayout.Width(rect.width - 200)); EditorGUILayout.LabelField("Color", EditorStyles.boldLabel, GUILayout.Width(65)); EditorGUILayout.LabelField("Draw", EditorStyles.boldLabel, GUILayout.Width(40)); EditorGUILayout.LabelField("Thickness", EditorStyles.boldLabel, GUILayout.Width(60)); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); for (int i = 0; i < sceneSplines.Count; i++) { bool isSelected = selected.Contains(i); if (isSelected) { GUI.backgroundColor = SplinePrefs.highlightColor; } EditorGUILayout.BeginHorizontal(isSelected ? selectedRow : normalRow); EditorGUILayout.LabelField(sceneSplines[i].name, isSelected ? selectedRow : normalRow, GUILayout.Width(rect.width - 200)); GUI.backgroundColor = Color.white; Color pathColor = sceneSplines[i].editorPathColor; pathColor = EditorGUILayout.ColorField(pathColor, GUILayout.Width(65)); if (pathColor != sceneSplines[i].editorPathColor) { foreach (int index in selected) { sceneSplines[index].editorPathColor = pathColor; } } bool alwaysDraw = sceneSplines[i].alwaysDraw; alwaysDraw = EditorGUILayout.Toggle(alwaysDraw, GUILayout.Width(40)); if (alwaysDraw != sceneSplines[i].alwaysDraw) { foreach (int index in selected) { if (alwaysDraw) { DSSplineDrawer.RegisterComputer(sceneSplines[index]); } else { DSSplineDrawer.UnregisterComputer(sceneSplines[index]); } } } bool thickness = sceneSplines[i].drawThinckness; thickness = EditorGUILayout.Toggle(thickness, GUILayout.Width(40)); if (thickness != sceneSplines[i].drawThinckness) { foreach (int index in selected) { sceneSplines[index].drawThinckness = thickness; } } EditorGUILayout.EndHorizontal(); lastRect = GUILayoutUtility.GetLastRect(); if (mouseLeft) { if (lastRect.Contains(Event.current.mousePosition)) { if (Event.current.control) { if (!selected.Contains(i)) { selected.Add(i); } } else if (selected.Count > 0 && Event.current.shift) { int closest = selected[0]; int delta = sceneSplines.Count; for (int j = 0; j < selected.Count; j++) { int d = Mathf.Abs(i - selected[j]); if (d < delta) { delta = d; closest = selected[j]; } } if (closest < i) { for (int j = closest + 1; j <= i; j++) { if (selected.Contains(j)) { continue; } selected.Add(j); } } else { for (int j = closest - 1; j >= i; j--) { if (selected.Contains(j)) { continue; } selected.Add(j); } } } else { selected = new List <int>(new int[] { i }); } List <GameObject> selectGo = new List <GameObject>(); foreach (int index in selected) { selectGo.Add(sceneSplines[index].gameObject); } Selection.objects = selectGo.ToArray(); Repaint(); } } } if (EditorGUI.EndChangeCheck()) { SceneView.RepaintAll(); } EditorGUILayout.EndScrollView(); if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.DownArrow) { if (selected.Count > 0) { selected = new List <int>(new int[] { selected[0] }); } else { selected[0]++; } } else if (Event.current.keyCode == KeyCode.UpArrow) { if (selected.Count > 0) { selected = new List <int>(new int[] { selected[selected.Count - 1] }); } else { selected[0]++; } } if (selected.Count == 0) { return; } if (selected[0] < 0) { selected[0] = sceneSplines.Count - 1; } if (selected[0] >= sceneSplines.Count) { selected[0] = 0; } if (sceneSplines.Count > 0) { Selection.activeGameObject = sceneSplines[selected[0]].gameObject; } } }