protected override void ShowPointOverride(SplineBase spline, int index, Vector3 point, Quaternion handleRotation, float size) { if (!spline.Loop) { if (index == spline.ControlPointCount - 1) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null) { if ((SceneView.lastActiveSceneView.camera.transform.position - point).magnitude > 4.0f) { if (Handles.Button(point + spline.GetDirection(1.0f) * 1.5f, handleRotation, size * HandleSize, size * PickSize2, (id, p, r, s, e) => CapFunction(size, id, p, m_addButton, e))) { SplineEditor.Append((Spline)spline); Selection.activeGameObject = spline.GetSplineControlPoints().Last().gameObject; } } } } else if (index == 0) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera != null) { if ((SceneView.lastActiveSceneView.camera.transform.position - point).magnitude > 4.0f) { if (Handles.Button(point - spline.GetDirection(0.0f) * 1.5f, handleRotation, size * HandleSize, size * PickSize2, (id, p, r, s, e) => CapFunction(size, id, p, m_addButton, e))) { SplineEditor.Prepend((Spline)spline); Selection.activeGameObject = spline.GetSplineControlPoints().First().gameObject; } } } } } }
private void ShowPoint(SplineBase spline, int index, Vector3 point, Quaternion handleRotation) { if (!CanShowPoint(index)) { return; } bool hasBranches = spline.HasBranches(index); Handles.color = ModeColors[(int)spline.GetControlPointMode(index)]; if (index % 3 == 0) { if (hasBranches) { Handles.color = m_branchColor; } else { Handles.color = Color.green; } } float size = HandleUtility.GetHandleSize(point); Handles.CapFunction dcf = Handles.DotHandleCap; if (index == 0) { if (!hasBranches) { size *= 1.5f; } } if (Handles.Button(point, handleRotation, size * HandleSize, size * PickSize, dcf)) { SplineBase unselectedSpline = m_selectedSpline; m_selectedSpline = spline; int unselectedIndex = m_selectedIndex; m_selectedIndex = index; if (OnControlPointClick(unselectedIndex, m_selectedIndex)) { SplineControlPoint controlPoint = spline.GetSplineControlPoints().Where(cpt => cpt.Index == index).FirstOrDefault(); if (controlPoint != null) { Selection.activeGameObject = controlPoint.gameObject; } } else { m_selectedIndex = unselectedIndex; m_selectedSpline = unselectedSpline; } Repaint(); } if (m_selectedIndex == index && spline == m_splineBase) { ShowLengths(spline, index, true); } ShowPointOverride(spline, index, point, handleRotation, size); }
private void OnRuntimeSelectionChanged(UnityEngine.Object[] unselected) { SplineBase minSpline = null; int minIndex = -1; float minDistance = float.PositiveInfinity; if (unselected != null) { GameObject[] gameObjects = unselected.OfType <GameObject>().ToArray(); for (int i = 0; i < gameObjects.Length; ++i) { GameObject go = gameObjects[i]; if (go == null) { continue; } SplineBase spline = go.GetComponentInParent <SplineBase>(); if (spline == null) { continue; } spline.Select(); float distance = minDistance; SplineBase hitSpline; int selectedIndex = HitTestRecursive(spline.Root, minDistance, out hitSpline, out distance); if (distance < minDistance && selectedIndex != -1) { minDistance = distance; minIndex = selectedIndex; minSpline = hitSpline; } spline.Unselect(); } if (minSpline != null) { SplineControlPoint ctrlPoint = minSpline.GetSplineControlPoints().Where(p => p.Index == minIndex).FirstOrDefault(); if (ctrlPoint != null) { RuntimeSelection.activeObject = ctrlPoint.gameObject; } minSpline.Select(); return; } } if (RuntimeSelection.gameObjects != null) { GameObject[] gameObjects = RuntimeSelection.gameObjects; if (gameObjects != null) { for (int i = 0; i < gameObjects.Length; ++i) { SplineBase spline = gameObjects[i].GetComponentInParent <SplineBase>(); if (spline != null) { spline.Select(); } } } } }