/// <summary> /// Enforces the mode on the control points /// </summary> /// <param name="index">Index.</param> private void EnforceMode(int index) { int modeIndex = (index + 1) / 3; BezierMoveMode mode = m_Mode[modeIndex]; // If the mode is free or we are on the 1st or last control point then do nothing if (mode == BezierMoveMode.Free || modeIndex == 0 || modeIndex == m_Mode.Length - 1) { return; } int middleIndex = modeIndex * 3; int fixedIndex; int enforcedIndex; if (index <= middleIndex) { fixedIndex = middleIndex - 1; enforcedIndex = middleIndex + 1; } else { fixedIndex = middleIndex + 1; enforcedIndex = middleIndex - 1; } Vector3 middle = m_Points[middleIndex]; Vector3 enforcedTangent = middle - m_Points[fixedIndex]; if (mode == BezierMoveMode.Aligned) { enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, m_Points[enforcedIndex]); } m_Points[enforcedIndex] = middle + enforcedTangent; }
/// <summary> /// Draws the selected point inspector. /// </summary> private void DrawSelectedPointInspector() { GUILayout.Label("Selected Point"); EditorGUI.BeginChangeCheck(); Vector3 point = EditorGUILayout.Vector3Field("Position", m_Spline.GetControlPoint(m_SelectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_Spline, "Move Point"); m_Spline.SetControlPoint(m_SelectedIndex, point); EditorUtility.SetDirty(m_Spline); } EditorGUI.BeginChangeCheck(); BezierMoveMode mode = (BezierMoveMode) EditorGUILayout.EnumPopup("Mode", m_Spline.GetControlPointMode(m_SelectedIndex)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_Spline, "Change Point Mode"); m_Spline.SetControlPointMode(m_SelectedIndex, mode); EditorUtility.SetDirty(m_Spline); } }
/// <summary> /// Sets the mode of control point at specified index /// </summary> /// <param name="index">Index.</param> /// <param name="mode">Mode.</param> public void SetControlPointMode(int index, BezierMoveMode mode) { m_Mode[(index + 1) / 3] = mode; }