protected override void OnInspectorGUIOverride() { if (m_spline == null) { m_spline = GetTarget() as Spline; } if (m_spline == null) { return; } int curveIndex = (SelectedIndex - 1) / 3; GUILayout.BeginHorizontal(); { if (curveIndex == m_spline.CurveCount - 1) { if (GUILayout.Button("Append")) { Undo.RecordObject(m_spline, "Battlehub.Spline.Append"); m_spline.Extend(); EditorUtility.SetDirty(m_spline); Selection.activeGameObject = m_spline.GetComponentsInChildren <SplineControlPoint>(true).Last().gameObject; } } if (curveIndex == 0) { if (GUILayout.Button("Prepend")) { Undo.RecordObject(m_spline, "Battlehub.Spline.Prepend"); m_spline.Extend(true); EditorUtility.SetDirty(m_spline); Selection.activeGameObject = m_spline.GetComponentsInChildren <SplineControlPoint>(true).First().gameObject; } } } GUILayout.EndHorizontal(); if (SelectedIndex >= 0 && curveIndex < m_spline.CurveCount) { if (GUILayout.Button("Remove")) { Remove(); } } base.OnInspectorGUIOverride(); }
private static void Prepend() { GameObject selected = Selection.activeObject as GameObject; Spline spline = selected.GetComponentInParent <Spline>(); Undo.RecordObject(spline, "Battlehub.Spline.Prepend"); spline.Prepend(); EditorUtility.SetDirty(spline); Selection.activeGameObject = spline.GetComponentsInChildren <SplineControlPoint>(true).First().gameObject; }
private static void Insert() { GameObject selected = Selection.activeObject as GameObject; Spline spline = selected.GetComponentInParent <Spline>(); SplineControlPoint ctrlPoint = selected.GetComponent <SplineControlPoint>(); Undo.RecordObject(spline, "Battlehub.Spline.Insert"); spline.Insert((ctrlPoint.Index + 2) / 3); EditorUtility.SetDirty(spline); Selection.activeGameObject = spline.GetComponentsInChildren <SplineControlPoint>(true).ElementAt(ctrlPoint.Index + 3).gameObject; }