private SplinePointHandle.Result DrawDragHandle(SplineRenderer renderer, Vector3 position, float scale, bool hasSelectionMargin) { Handles.DrawCapFunction dcf = Handles.CircleCap; float size = HandleUtility.GetHandleSize(position) * 2.0f * m_pointSizeConst; Vector2 guiPosition = HandleUtility.WorldToGUIPoint(position); if (Vector2.Distance(guiPosition, Event.current.mousePosition) > 15 * renderer.PointSize * scale || IsControlPointDrag || Event.current.alt) { size *= 0; } float selectionSize; if (hasSelectionMargin) { selectionSize = size * (renderer.PointSize + renderer.SelectionMargin) * scale; } else { selectionSize = size * renderer.PointSize * scale; } SplinePointHandle.Result result = SplinePointHandle.DragHandleGUI(position, Quaternion.LookRotation(Camera.current.transform.forward), size * renderer.PointSize * scale, selectionSize, dcf, renderer.SelectionColor); return(result); }
protected override SplineEditorEvent GetEvent(out SplineEditorEventArgs args) { SplineEditorEvent evnt = SplineEditorEvent.None; args = null; SplineBase[] splines = Splines; SplineRenderer[] splineRenderers = SplineRenderers; if (splines == null || splineRenderers == null) { return(SplineEditorEvent.None); } SplineRenderer dragSplineRenderer = null; for (int i = 0; i < splines.Length; ++i) { SplineRenderer splineRenderer = splineRenderers[i]; SplineBase spline = splines[i]; for (int j = 0; j < spline.PointsCount; ++j) { if ((IsJunctionDrag || IsSplinePointCreator) && DragSpline == spline && j == DragPointIndex) { dragSplineRenderer = splineRenderer; continue; } DrawSplinePoint(ref args, ref evnt, splineRenderer, spline, j); } } if (IsSplinePointCreator || IsJunctionDrag) { DrawSplinePoint(ref args, ref evnt, dragSplineRenderer, DragSpline, DragPointIndex); } if (evnt == SplineEditorEvent.SplinePointDrag || evnt == SplineEditorEvent.SplinePointCreatorDrag) { m_pointerOver = false; } if (evnt == SplineEditorEvent.SplinePointDrop || evnt == SplineEditorEvent.SplinePointCreatorDrop) { if (m_pointerOverSpline != null && m_pointerOverSplinePointIndex != -1) { if (!m_pointerOver) { m_pointerOverSpline = null; m_pointerOverSplinePointIndex = -1; } args = new SplineEditorEventArgs(m_pointerOverSpline, m_pointerOverSplinePointIndex); m_pointerOverSpline = null; m_pointerOverSplinePointIndex = -1; } } return(evnt); }
public virtual void Disable() { EndDrag(); if (m_selectedJunctions != null) { for (int i = 0; i < m_selectedJunctions.Length; ++i) { JunctionBase junction = m_selectedJunctions[i]; if (junction != null) { junction.Unselect(); } } } if (m_splineRenderers != null) { for (int i = 0; i < m_splineRenderers.Length; ++i) { SplineRenderer splineRenderer = m_splineRenderers[i]; if (splineRenderer != null) { splineRenderer.IsSelected = false; } } } if (m_selectedSplinePoints != null) { for (int i = 0; i < m_selectedSplinePoints.Length; ++i) { SplinePointBase splinePoint = m_selectedSplinePoints[i]; if (splinePoint != null) { splinePoint.Unselect(); } } } if (m_selectedBezierPoints != null) { for (int i = 0; i < m_selectedBezierPoints.Length; ++i) { ControlPoint bezierPoint = m_selectedBezierPoints[i]; if (bezierPoint != null) { bezierPoint.Unselect(); } } } m_splines = null; m_splineRenderers = null; m_selectedSplines = null; m_selectedJunctions = null; m_selectedSplinePoints = null; m_selectedBezierPoints = null; }
protected virtual void Awake() { m_renderer = gameObject.GetComponent <SplineRenderer>(); if (m_renderer == null) { m_renderer = gameObject.AddComponent <SplineRenderer>(); } m_renderer.enabled = false; }
protected virtual void Awake() { m_renderer = gameObject.AddComponent <SplineRenderer>(); }
private void DrawSplinePoint(ref SplineEditorEventArgs args, ref SplineEditorEvent evnt, SplineRenderer splineRenderer, SplineBase spline, int j) { int mode = spline.GetPointMode(j); if (mode >= 0 && mode < splineRenderer.ControlPointColors.Length) { Handles.color = splineRenderer.ControlPointColors[mode]; } int controlPointsCount = spline.GetCtrlPointsCount(j); for (int k = 0; k < controlPointsCount; ++k) { int scale = 1; if (!splineRenderer.IsControlPointVisible(j, k)) { scale = 0; } Vector3 ctrlPosition = spline.GetCtrlPointPosition(j, k); SplinePointHandle.Result ctrlPointDragResult = DrawPointHandle(splineRenderer, ctrlPosition, scale, true); if (ctrlPointDragResult == SplinePointHandle.Result.Drag) { if (evnt == SplineEditorEvent.None) { args = new SplineEditorEventArgs(spline, j, k); evnt = SplineEditorEvent.SplineCtrlPointDrag; } } if (ctrlPointDragResult == SplinePointHandle.Result.EndDrag) { if (evnt == SplineEditorEvent.None) { args = new SplineEditorEventArgs(spline, j, k); evnt = SplineEditorEvent.SplineCtrlPointDrop; } } } float dragHandleScale = 1; if (m_draggingDragPointHandle && spline == DragSpline && DragPointIndex == j) { dragHandleScale = 0; } JunctionBase junction = spline.GetJunction(j); if (junction != null && junction != NewJunction) { bool drawSplinePoint = junction == null || spline == junction.GetSpline(0) && j == junction.GetSplinePointIndex(0); if (drawSplinePoint) { dragHandleScale = 1.5f; } else { dragHandleScale = 0; } } Handles.color = splineRenderer.SplinePointColor; Vector3 position = spline.GetPointPosition(j); SplinePointHandle.Result dragResult = DrawDragHandle(splineRenderer, position, dragHandleScale, DragSpline == null); if (dragResult == SplinePointHandle.Result.Drag) { if (evnt == SplineEditorEvent.None) { args = new SplineEditorEventArgs(spline, j); evnt = SplineEditorEvent.SplinePointDrag; } } else if (dragResult == SplinePointHandle.Result.EndDrag) { if (evnt == SplineEditorEvent.None) { args = new SplineEditorEventArgs(spline, j); evnt = SplineEditorEvent.SplinePointDrop; } } else if (dragResult == SplinePointHandle.Result.PointerOver) { m_pointerOverSpline = spline; m_pointerOverSplinePointIndex = j; m_pointerOver = true; } if (junction != null && junction != NewJunction) { Handles.color = splineRenderer.JunctionColor; JunctionHandle.Result junctionResult = DrawJunctionHandle(splineRenderer, junction.transform.position, 1); if (junctionResult == JunctionHandle.Result.Click) { evnt = SplineEditorEvent.JunctionClick; args = new SplineEditorEventArgs(junction); } else if (junctionResult == JunctionHandle.Result.Drag) { evnt = SplineEditorEvent.JunctionDrag; args = new SplineEditorEventArgs(junction); } } Handles.color = splineRenderer.SplinePointColor; SplinePointHandle.Result result = DrawPointHandle(splineRenderer, position, 1, false); if (result == SplinePointHandle.Result.EndDrag) { m_draggingDragPointHandle = false; if (evnt == SplineEditorEvent.None) { args = new SplineEditorEventArgs(spline, j); evnt = SplineEditorEvent.SplinePointCreatorDrop; } } else if (result == SplinePointHandle.Result.Drag) { m_draggingDragPointHandle = true; if (evnt == SplineEditorEvent.None) { args = new SplineEditorEventArgs(spline, j); evnt = SplineEditorEvent.SplinePointCreatorDrag; } } }
private bool BeginDragSplinePoint() { Vector3 position; if (GetPositionOnDragPlane(ScreenPointToRay(MousePosition), out position)) { Vector3 offset = position - m_dragSpline.GetPointPosition(m_dragPointIndex); const float s = 0.1f; if (offset.magnitude > HandleSize(m_beginDragPosition) * s) { JunctionBase junction = m_dragSpline.GetJunction(m_dragPointIndex); if (m_dragPointIndex == 0 && junction == null) { m_dragSpline.Prepend(position); GameObject splinePoint = m_dragSpline.GetPoint(0); RegisterCreatedObjectUndo(splinePoint, "BH.S3.Prepend"); SetTransformParentUndo(splinePoint.transform, splinePoint.transform.parent, "BH.S3.Prepend"); } else if (m_dragPointIndex == m_dragSpline.PointsCount - 1 && junction == null) { m_dragSpline.Append(position); m_dragPointIndex = m_dragSpline.PointsCount - 1; RegisterCreatedObjectUndo(m_dragSpline.GetPoint(m_dragPointIndex), "BH.S3.Append"); } else { Vector3 dir; if (m_dragSpline.CurveCount == m_dragPointIndex) { dir = m_dragSpline.GetDirection(1.0f); } else { dir = m_dragSpline.GetDirection(0, m_dragPointIndex); } bool isOut = Mathf.Sign(Vector3.Dot(offset.normalized, dir)) >= 0; int connectionIndex = m_dragSpline.CreateBranch(m_dragPointIndex, isOut); junction = m_dragSpline.GetJunction(m_dragPointIndex); m_dragSpline = junction.GetSpline(connectionIndex); RegisterCreatedObjectUndo(m_dragSpline.gameObject, "BH.S3.Branch"); if (junction.ConnectionsCount == 2) { m_newJunction = junction; RegisterCreatedObjectUndo(junction.gameObject, "BH.S3.Branch"); } m_splines = m_splines.Add(m_dragSpline); SplineRenderer splineRenderer = m_dragSpline.GetComponent <SplineRenderer>(); m_splineRenderers = m_splineRenderers.Add(splineRenderer); if (splineRenderer != null) { splineRenderer.IsSelected = true; } m_dragPointIndex = isOut ? 1 : 0; } return(true); } } return(false); }