void OnScene(SceneView current) { for (int i = 0; i < imported.Count; i++) { SplineDrawer.DrawSplineComputer(imported[i]); } }
public override void DrawScene() { base.DrawScene(); if (drawComputer) { for (int i = 0; i < splines.Length; i++) { SplineDrawer.DrawSplineComputer(splines[i]); } } if (drawConnectedComputers) { for (int i = 0; i < splines.Length; i++) { List <SplineComputer> computers = splines[i].GetConnectedComputers(); for (int j = 1; j < computers.Count; j++) { SplineDrawer.DrawSplineComputer(computers[j], 0.0, 1.0, 0.5f); } } } if (module >= 0 && module < modules.Length) { modules[module].DrawScene(); } }
public override void DrawScene() { base.DrawScene(); if (spline.isClosed) { return; } Camera editorCamera = SceneView.currentDrawingSceneView.camera; for (int i = 0; i < availableMergeComputers.Length; i++) { SplineDrawer.DrawSplineComputer(availableMergeComputers[i]); SplinePoint startPoint = availableMergeComputers[i].GetPoint(0); SplinePoint endPoint = availableMergeComputers[i].GetPoint(availableMergeComputers[i].pointCount - 1); Handles.color = availableMergeComputers[i].editorPathColor; if (SplineEditorHandles.CircleButton(startPoint.position, Quaternion.LookRotation(editorCamera.transform.position - startPoint.position), HandleUtility.GetHandleSize(startPoint.position) * 0.15f, 1f, availableMergeComputers[i].editorPathColor)) { Merge(i, MergeSide.Start); break; } if (SplineEditorHandles.CircleButton(endPoint.position, Quaternion.LookRotation(editorCamera.transform.position - endPoint.position), HandleUtility.GetHandleSize(endPoint.position) * 0.15f, 1f, availableMergeComputers[i].editorPathColor)) { Merge(i, MergeSide.End); break; } } Handles.color = Color.white; }
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) { SplineDrawer.RegisterComputer(spline); } else { SplineDrawer.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); }
protected override void OnSceneGUI() { base.OnSceneGUI(); SurfaceGenerator user = (SurfaceGenerator)target; if (user.extrudeSpline != null) { SplineDrawer.DrawSplineComputer(user.extrudeSpline, 0.0, 1.0, 0.5f); } }
void OnScene(SceneView current) { for (int i = 0; i < collections.Count; i++) { if (collections[i].spline != null) { SplineDrawer.DrawSplineComputer(collections[i].spline); } } }
void OnScene(SceneView current) { if (selected.Count > 1) { for (int i = 0; i < selected.Count; i++) { if (!sceneSplines[selected[i]].alwaysDraw) { SplineDrawer.DrawSplineComputer(sceneSplines[selected[i]]); } } } }
protected virtual void OnSceneGUI() { if (doRebuild) { DoRebuild(); } SplineUser user = (SplineUser)target; if (user == null) { return; } if (user.spline != null) { SplineComputer rootComputer = user.GetComponent <SplineComputer>(); List <SplineComputer> allComputers = user.spline.GetConnectedComputers(); for (int i = 0; i < allComputers.Count; i++) { if (allComputers[i] == rootComputer && _editIndex == -1) { continue; } if (allComputers[i].alwaysDraw) { continue; } SplineDrawer.DrawSplineComputer(allComputers[i], 0.0, 1.0, 0.4f); } SplineDrawer.DrawSplineComputer(user.spline); } if (_editIndex == 0) { SceneClipEdit(); } if (offsetModifierEditor != null) { offsetModifierEditor.DrawScene(); } if (rotationModifierEditor != null) { rotationModifierEditor.DrawScene(); } if (colorModifierEditor != null) { colorModifierEditor.DrawScene(); } if (sizeModifierEditor != null) { sizeModifierEditor.DrawScene(); } }
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) { SplineDrawer.RegisterComputer(imported[i]); } else { SplineDrawer.UnregisterComputer(imported[i]); } } SceneView.RepaintAll(); }
public override void DrawScene() { bool change = false; Camera editorCamera = SceneView.currentDrawingSceneView.camera; for (int i = 0; i < spline.pointCount; i++) { Vector3 pos = spline.GetPointPosition(i); if (SplineEditorHandles.CircleButton(pos, Quaternion.LookRotation(editorCamera.transform.position - pos), HandleUtility.GetHandleSize(pos) * 0.12f, 1f, spline.editorPathColor)) { SplitAtPoint(i); change = true; break; } } SplineSample projected = spline.Evaluate(ProjectMouse()); if (!change) { float pointValue = (float)projected.percent * (spline.pointCount - 1); int pointIndex = Mathf.FloorToInt(pointValue); float size = HandleUtility.GetHandleSize(projected.position) * 0.3f; Vector3 up = Vector3.Cross(editorCamera.transform.forward, projected.forward).normalized *size + projected.position; Vector3 down = Vector3.Cross(projected.forward, editorCamera.transform.forward).normalized *size + projected.position; Handles.color = spline.editorPathColor; Handles.DrawLine(up, down); Handles.color = Color.white; if (pointValue - pointIndex > spline.moveStep) { if (SplineEditorHandles.CircleButton(projected.position, Quaternion.LookRotation(editorCamera.transform.position - projected.position), HandleUtility.GetHandleSize(projected.position) * 0.12f, 1f, spline.editorPathColor)) { SplitAtPercent(projected.percent); change = true; } } SceneView.RepaintAll(); } Handles.color = Color.white; SplineDrawer.DrawSplineComputer(spline, 0.0, projected.percent, 1f); SplineDrawer.DrawSplineComputer(spline, projected.percent, 1.0, 0.4f); }
public override void DrawScene() { editorCamera = SceneView.currentDrawingSceneView.camera; bool canCreate = false; if (placementMode == PlacementMode.CameraPlane) { GetCreatePointOnPlane(-editorCamera.transform.forward, editorCamera.transform.position + editorCamera.transform.forward * offset, out createPoint); Handles.color = new Color(1f, 0.78f, 0.12f); DrawGrid(createPoint, editorCamera.transform.forward, Vector2.one * 10, 2.5f); Handles.color = Color.white; canCreate = true; createNormal = -editorCamera.transform.forward; } if (placementMode == PlacementMode.Surface) { Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity, surfaceLayerMask)) { canCreate = true; createPoint = hit.point + hit.normal * offset; Handles.color = Color.blue; Handles.DrawLine(hit.point, createPoint); SplineEditorHandles.DrawRectangle(createPoint, Quaternion.LookRotation(-editorCamera.transform.forward, editorCamera.transform.up), HandleUtility.GetHandleSize(createPoint) * 0.1f); Handles.color = Color.white; createNormal = hit.normal; } } if (placementMode == PlacementMode.XPlane) { canCreate = AxisGrid(Vector3.right, new Color(0.85f, 0.24f, 0.11f, 0.92f), out createPoint); createNormal = Vector3.right; } if (placementMode == PlacementMode.YPlane) { canCreate = AxisGrid(Vector3.up, new Color(0.6f, 0.95f, 0.28f, 0.92f), out createPoint); createNormal = Vector3.up; } if (placementMode == PlacementMode.ZPlane) { canCreate = AxisGrid(Vector3.forward, new Color(0.22f, 0.47f, 0.97f, 0.92f), out createPoint); createNormal = Vector3.back; } if (placementMode == PlacementMode.Insert) { canCreate = true; if (points.Length < 2) { placementMode = PlacementMode.YPlane; } else { InsertMode(Event.current.mousePosition); } } else if (eventModule.mouseLeftDown && canCreate && !eventModule.mouseRight && !eventModule.alt) { CreateSplinePoint(createPoint, createNormal); } if (lastCreated >= 0 && lastCreated < points.Length && editor.eventModule.mouseLeft) { Vector3 tangent = points[lastCreated].position - createPoint; if (appendMode == AppendMode.End) { tangent = createPoint - points[lastCreated].position; } points[lastCreated].SetTangent2Position(points[lastCreated].position + tangent); } else if (!editor.eventModule.mouseLeft) { lastCreated = -1; } if (!canCreate) { DrawMouseCross(); } UpdateVisualizer(); SplineDrawer.DrawSpline(visualizer, color); Repaint(); }
protected override void OnSceneGUI() { base.OnSceneGUI(); ObjectBender bender = (ObjectBender)target; if (selected.Count > 0) { Handles.BeginGUI(); for (int i = 0; i < selected.Count; i++) { Vector2 screenPosition = HandleUtility.WorldToGUIPoint(bender.bendProperties[selected[i]].transform.transform.position); DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + bender.bendProperties[selected[i]].transform.transform.name.Length * 4, screenPosition.y, 120, 25), bender.bendProperties[selected[i]].transform.transform.name); } Handles.EndGUI(); } for (int i = 0; i < bender.bendProperties.Length; i++) { if (bender.bendProperties[i].bendSpline && bender.bendProperties[i].splineComputer != null) { SplineDrawer.DrawSplineComputer(bender.bendProperties[i].splineComputer, 0.0, 1.0, 0.2f); } } //Draw bounds if (bender.bend) { return; } TS_Bounds bound = bender.GetBounds(); Vector3 a = bender.transform.TransformPoint(bound.min); Vector3 b = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.min.y, bound.min.z)); Vector3 c = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.min.y, bound.max.z)); Vector3 d = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.min.y, bound.max.z)); Vector3 e = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.max.y, bound.min.z)); Vector3 f = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.max.y, bound.min.z)); Vector3 g = bender.transform.TransformPoint(new Vector3(bound.max.x, bound.max.y, bound.max.z)); Vector3 h = bender.transform.TransformPoint(new Vector3(bound.min.x, bound.max.y, bound.max.z)); Handles.color = Color.gray; Handles.DrawLine(a, b); Handles.DrawLine(b, c); Handles.DrawLine(c, d); Handles.DrawLine(d, a); Handles.DrawLine(e, f); Handles.DrawLine(f, g); Handles.DrawLine(g, h); Handles.DrawLine(h, e); Handles.DrawLine(a, e); Handles.DrawLine(b, f); Handles.DrawLine(c, g); Handles.DrawLine(d, h); Vector3 r = bender.transform.right; Vector3 fr = bender.transform.forward; switch (bender.axis) { case ObjectBender.Axis.Z: Handles.color = Color.blue; Handles.DrawLine(r + b, r + c); break; case ObjectBender.Axis.X: Handles.color = Color.red; Handles.DrawLine(b - fr, a - fr); break; case ObjectBender.Axis.Y: Handles.color = Color.green; Handles.DrawLine(b - fr + r, f - fr + r); break; } }
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) { SplineDrawer.RegisterComputer(sceneSplines[index]); } else { SplineDrawer.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; } } }
public override void DrawScene() { base.DrawScene(); if (drawComputer) { for (int i = 0; i < splines.Length; i++) { SplineDrawer.DrawSplineComputer(splines[i]); } } if (drawConnectedComputers) { for (int i = 0; i < splines.Length; i++) { List <SplineComputer> computers = splines[i].GetConnectedComputers(); for (int j = 1; j < computers.Count; j++) { SplineDrawer.DrawSplineComputer(computers[j], 0.0, 1.0, 0.5f); } } } if (pathEditor.currentModule == null) { switch (transformTool) { case 1: for (int i = 0; i < splines.Length; i++) { Vector3 position = splines[i].transform.position; position = Handles.PositionHandle(position, splines[i].transform.rotation); if (position != splines[i].transform.position) { RecordUndo("Move spline computer"); Undo.RecordObject(splines[i].transform, "Move spline computer"); splines[i].transform.position = position; splines[i].SetPoints(pathEditor.points); pathEditor.Refresh(); } } break; case 2: for (int i = 0; i < splines.Length; i++) { Quaternion rotation = splines[i].transform.rotation; rotation = Handles.RotationHandle(rotation, splines[i].transform.position); if (rotation != splines[i].transform.rotation) { RecordUndo("Rotate spline computer"); Undo.RecordObject(splines[i].transform, "Rotate spline computer"); splines[i].transform.rotation = rotation; splines[i].SetPoints(pathEditor.points); pathEditor.Refresh(); } } break; case 3: for (int i = 0; i < splines.Length; i++) { Vector3 scale = splines[i].transform.localScale; scale = Handles.ScaleHandle(scale, splines[i].transform.position, splines[i].transform.rotation, HandleUtility.GetHandleSize(splines[i].transform.position)); if (scale != splines[i].transform.localScale) { RecordUndo("Scale spline computer"); Undo.RecordObject(splines[i].transform, "Scale spline computer"); splines[i].transform.localScale = scale; splines[i].SetPoints(pathEditor.points); pathEditor.Refresh(); } } break; } if (transformTool > 0) { for (int i = 0; i < splines.Length; i++) { Vector2 screenPosition = HandleUtility.WorldToGUIPoint(splines[i].transform.position); screenPosition.y += 20f; Handles.BeginGUI(); DreamteckEditorGUI.Label(new Rect(screenPosition.x - 120 + splines[i].name.Length * 4, screenPosition.y, 120, 25), splines[i].name); Handles.EndGUI(); } } } if (module >= 0 && module < modules.Length) { modules[module].DrawScene(); } }
protected virtual void OnSceneGUI() { Node node = (Node)target; Node.Connection[] connections = node.GetConnections(); #if DREAMTECK_SPLINES for (int i = 0; i < connections.Length; i++) { SplineDrawer.DrawSplineComputer(connections[i].spline, 0.0, 1.0, 0.5f); } #endif bool update = false; if (position != node.transform.position) { position = node.transform.position; update = true; } if (scale != node.transform.localScale) { scale = node.transform.localScale; update = true; } if (rotation != node.transform.rotation) { rotation = node.transform.rotation; update = true; } if (update) { node.UpdateConnectedComputers(); } if (addComp == null) { if (connections.Length > 0) { bool bezier = false; for (int i = 0; i < connections.Length; i++) { if (connections[i].spline == null) { continue; } if (connections[i].spline.type == Spline.Type.Bezier) { bezier = true; continue; } } if (bezier && node.type == Node.Type.Smooth) { if (connections[0].spline != null) { SplinePoint point = node.GetPoint(0, true); Handles.DrawDottedLine(node.transform.position, point.tangent, 6f); Handles.DrawDottedLine(node.transform.position, point.tangent2, 6f); Vector3 lastPos = point.tangent; bool setPoint = false; point.SetTangentPosition(Handles.PositionHandle(point.tangent, node.transform.rotation)); if (lastPos != point.tangent) { setPoint = true; } lastPos = point.tangent2; point.SetTangent2Position(Handles.PositionHandle(point.tangent2, node.transform.rotation)); if (lastPos != point.tangent2) { setPoint = true; } if (setPoint) { node.SetPoint(0, point, true); node.UpdateConnectedComputers(); } } } } return; } SplinePoint[] points = addComp.GetPoints(); Transform camTransform = SceneView.currentDrawingSceneView.camera.transform; #if DREAMTECK_SPLINES SplineDrawer.DrawSplineComputer(addComp, 0.0, 1.0, 0.5f); #endif TextAnchor originalAlignment = GUI.skin.label.alignment; Color originalColor = GUI.skin.label.normal.textColor; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.skin.label.normal.textColor = addComp.editorPathColor; for (int i = 0; i < availablePoints.Length; i++) { if (addComp.isClosed && i == points.Length - 1) { break; } Handles.Label(points[i].position + Camera.current.transform.up * HandleUtility.GetHandleSize(points[i].position) * 0.3f, (i + 1).ToString()); if (SplineEditorHandles.CircleButton(points[availablePoints[i]].position, Quaternion.LookRotation(-camTransform.forward, camTransform.up), HandleUtility.GetHandleSize(points[availablePoints[i]].position) * 0.1f, 2f, addComp.editorPathColor)) { AddConnection(addComp, availablePoints[i]); break; } } GUI.skin.label.alignment = originalAlignment; GUI.skin.label.normal.textColor = originalColor; }