private Vector3 ShowControlPoint(int index) { Vector3 point = handleTransform.TransformPoint(curve.handlesPositions[index]); float size = HandleUtility.GetHandleSize(point); if (index == 0) { size *= 2f; } if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotHandleCap)) { selectedIndex = index; Repaint(); } if (selectedIndex == index) { EditorGUI.BeginChangeCheck(); point = Handles.DoPositionHandle(point, handleRotation); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(curve, "Move Point"); EditorUtility.SetDirty(curve); curve.handlesPositions[index] = handleTransform.InverseTransformPoint(point); curve.OnChangeSpline(); } } return(point); }
public override void OnInspectorGUI() { // DrawDefaultInspector(); curve = target as CatmulRommSpline_1; if (!curve) { return; } if (selectedIndex >= 0 && selectedIndex < curve.handlesPositions.Count - 1) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Press to add or remove curve control point."); if (GUILayout.Button("Add Point")) { Undo.RecordObject(curve, "Add Point"); EditorUtility.SetDirty(curve); curve.AddPoint(selectedIndex); curve.OnChangeSpline(); } if (curve.Count > 3) { if (GUILayout.Button("Remove Point")) { Undo.RecordObject(curve, "Remove Point"); EditorUtility.SetDirty(curve); curve.RemovePoint(selectedIndex); curve.OnChangeSpline(); } } EditorGUILayout.EndHorizontal(); } if (selectedIndex >= 0 && selectedIndex < curve.handlesPositions.Count) { DrawSelectedPointInspector(); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Select curve control point for curve edit."); EditorGUILayout.EndHorizontal(); } }