public static void CreateBranch(Spline spline, int connectionPointIndex, bool isInbound) { Spline branch = SplineEditor.CreateSpline( spline.transform.position, spline.GetThickness(connectionPointIndex), spline.GetTwist(connectionPointIndex), spline.GetControlPointMode(connectionPointIndex), "Battlehub.Spline.CreateBranch"); branch.name = "Branch"; RecordHierarchy(spline, "Battlehub.Spline.CreateBranch"); spline.SetBranch(branch, connectionPointIndex, isInbound); if (isInbound) { branch.AlignWithNextSpline(); Selection.activeGameObject = branch.GetSplineControlPoints().First().gameObject; } else { branch.AlignWithPrevSpline(); Selection.activeGameObject = branch.GetSplineControlPoints().Last().gameObject; } EditorUtility.SetDirty(spline); }
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; } } } } } }
public static void Create() { Camera sceneCam = SceneView.lastActiveSceneView.camera; Thickness thickness = new Thickness(Vector3.one, 0, 1); Twist twist = new Twist(0, 0, 1); Selection.activeGameObject = SplineEditor.CreateSpline(sceneCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 5f)), thickness, twist).gameObject; }
public static void Prepend() { GameObject selected = Selection.activeObject as GameObject; Spline spline = selected.GetComponentInParent <Spline>(); SplineEditor.Prepend(spline); Selection.activeGameObject = spline.GetSplineControlPoints().First().gameObject; }
private static void Insert() { GameObject selected = Selection.activeObject as GameObject; Spline spline = selected.GetComponentInParent <Spline>(); SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); SplineEditor.Insert(spline, ctrlPoint.Index); Selection.activeGameObject = spline.GetSplineControlPoints().ElementAt(ctrlPoint.Index + 3).gameObject; }
protected override void OnInspectorGUIOverride() { if (m_spline == null) { return; } if (ConvergingSpline) { if (GUILayout.Button("Cancel")) { ConvergingSpline = null; } return; } GUILayout.BeginHorizontal(); { GUILayout.BeginVertical(); int curveIndex = (SelectedIndex - 1) / 3; if (GUILayout.Button("OUT -> Branch")) { CreateBranch(m_spline, SelectedIndex, false); } if (curveIndex == m_spline.CurveCount - 1 && m_spline.NextSpline == null) { if (m_spline.NextSpline == null) { if (GUILayout.Button("Append")) { SplineEditor.Append(m_spline); Selection.activeGameObject = m_spline.GetSplineControlPoints().Last().gameObject; } } } if (curveIndex == 0 && m_spline.PrevSpline == null) { if (m_spline.PrevSpline == null) { if (GUILayout.Button("Prepend")) { SplineEditor.Prepend(m_spline); Selection.activeGameObject = m_spline.GetSplineControlPoints().First().gameObject; } } } if (GUILayout.Button("Insert")) { SplineEditor.Insert(m_spline, SelectedIndex); Selection.activeGameObject = m_spline.GetSplineControlPoints().ElementAt(SelectedIndex + 3).gameObject; } GUILayout.EndVertical(); GUILayout.BeginVertical(); if (GUILayout.Button("Branch -> IN")) { CreateBranch(m_spline, SelectedIndex, true); } if (curveIndex == m_spline.CurveCount - 1 && m_spline.NextSpline == null) { if (m_spline.NextSpline == null) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera) { if (GUILayout.Button("To Cam")) { SplineEditor.AppendThrough(m_spline, SceneView.lastActiveSceneView.camera.transform); Selection.activeGameObject = m_spline.GetSplineControlPoints().Last().gameObject; } } } } if (curveIndex == 0 && m_spline.PrevSpline == null) { if (m_spline.PrevSpline == null) { if (SceneView.lastActiveSceneView != null && SceneView.lastActiveSceneView.camera) { if (GUILayout.Button("To Cam")) { SplineEditor.PrependThrough(m_spline, SceneView.lastActiveSceneView.camera.transform); Selection.activeGameObject = m_spline.GetSplineControlPoints().First().gameObject; } } } } if (SelectedIndex >= 0 && curveIndex < m_spline.CurveCount) { if (GUILayout.Button("Remove")) { Remove(m_spline, SelectedIndex); } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (SelectedIndex == 0 && m_spline.PrevSpline == null || SelectedIndex == m_spline.ControlPointCount - 1 && m_spline.NextSpline == null) { if (!m_spline.HasBranches(SelectedIndex)) { if (GUILayout.Button("Converge")) { if (m_spline.Loop) { EditorUtility.DisplayDialog("Unable to converge", "Unable to converge. Selected spline has loop.", "OK"); } else { ConvergingSpline = m_spline; } } } } if (SelectedIndex < m_spline.ControlPointCount && SelectedIndex >= 0) { if (m_spline.HasBranches(SelectedIndex)) { if (GUILayout.Button("Separate")) { Separate(m_spline, SelectedIndex); } } } if (GUILayout.Button("Align View To Point")) { if (SceneView.lastActiveSceneView != null) { SplineControlPoint controlPoint = (SplineControlPoint)target; SceneView.lastActiveSceneView.AlignViewToObject(controlPoint.transform); SceneView.lastActiveSceneView.Repaint(); } } base.OnInspectorGUIOverride(); }