private int HitTest(SplineBase spline, out float minDistance) { minDistance = float.PositiveInfinity; if (Camera == null) { Debug.LogError("Camera is null"); return(-1); } if (RuntimeSelection.gameObjects == null) { return(-1); } Vector3[] controlPoints = new Vector3[spline.ControlPointCount]; for (int j = 0; j < controlPoints.Length; j++) { controlPoints[j] = spline.GetControlPoint(j); } minDistance = SelectionMargin * SelectionMargin; int selectedIndex = -1; Vector2 mousePositon = Input.mousePosition; for (int i = 0; i < controlPoints.Length; ++i) { Vector3 ctrlPoint = controlPoints[i]; if (spline.IsControlPointLocked(i)) { continue; } Vector2 pt = Camera.WorldToScreenPoint(ctrlPoint); float mag = (pt - mousePositon).sqrMagnitude; if (mag < minDistance) { minDistance = mag; selectedIndex = i; } } return(selectedIndex); }
private void ShowPoints(SplineBase spline) { if (!spline.IsSelected) { return; } Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ? spline.transform.rotation : Quaternion.identity; int firstPointIndex = 0; if (spline.IsControlPointLocked(firstPointIndex)) { firstPointIndex++; if (spline.IsControlPointLocked(firstPointIndex)) { firstPointIndex++; } } int lastPointIndex = spline.ControlPointCount - 1; if (spline.IsControlPointLocked(lastPointIndex)) { lastPointIndex--; if (spline.IsControlPointLocked(lastPointIndex)) { lastPointIndex--; } } if (ConvergingSpline) { if (spline.Loop) { if (firstPointIndex == 0) { firstPointIndex++; } if (lastPointIndex == spline.ControlPointCount - 1) { lastPointIndex--; } } for (int i = firstPointIndex; i <= lastPointIndex; i++) { if (i % 3 == 0 && spline != m_splineBase) { Vector3 p = spline.GetControlPoint(i); ShowPoint(spline, i, p, handleRotation); } } } else { for (int i = firstPointIndex; i <= lastPointIndex; i++) { Vector3 p = spline.GetControlPoint(i); ShowPoint(spline, i, p, handleRotation); } } if (m_selectedIndex == -1 && spline == m_splineBase) { ShowSplineLength(m_splineBase, m_greenLabelStyle); } }
private void UpdateRenderersState() { if (m_index == 0 || m_index == 1) { if (m_spline.PrevSpline != null) { if (m_renderer != null) { m_renderer.enabled = !m_spline.IsControlPointLocked(m_index); } } else { if (m_renderer != null && !m_renderer.enabled) { m_renderer.enabled = true; } } } else if (m_index == m_spline.ControlPointCount - 1 || m_index == m_spline.ControlPointCount - 2) { if (m_spline.NextSpline != null) { if (m_renderer != null) { m_renderer.enabled = !m_spline.IsControlPointLocked(m_index); } } else { if (m_renderer != null && !m_renderer.enabled) { m_renderer.enabled = true; } } } else { if (m_renderer != null && !m_renderer.enabled) { m_renderer.enabled = true; } } if (SplineBase.ConvergingSpline) { if (m_spline.Loop) { if (m_index == 0 || m_index == m_spline.ControlPointCount - 1) { if (m_renderer != null) { m_renderer.enabled = false; } } } if (m_index % 3 != 0 || m_spline == SplineBase.ConvergingSpline) { if (m_renderer != null) { m_renderer.enabled = false; } } } UpdateMaterial(); }