private static void RenamePoints(BezierCurve3D curve) { for (int i = 0; i < curve.KeyPointsCount; i++) { curve.KeyPoints[i].name = "Point " + i; } }
private static void AddDefaultPoints(BezierCurve3D curve) { BezierPoint3D startPoint = curve.AddKeyPoint(); startPoint.LocalPosition = new Vector3(-1f, 0f, 0f); startPoint.LeftHandleLocalPosition = new Vector3(-0.35f, -0.35f, 0f); BezierPoint3D endPoint = curve.AddKeyPoint(); endPoint.LocalPosition = new Vector3(1f, 0f, 0f); endPoint.LeftHandleLocalPosition = new Vector3(-0.35f, 0.35f, 0f); }
public static void DrawPointsSceneGUI(BezierCurve3D curve, BezierPoint3D exclude = null) { for (int i = 0; i < curve.KeyPointsCount; i++) { if (curve.KeyPoints[i] == exclude) { continue; } BezierPoint3DEditor.handleCapSize = BezierPoint3DEditor.CircleCapSize; BezierPoint3DEditor.DrawPointSceneGUI(curve.KeyPoints[i]); } }
private static bool RemoveKeyPointAt(BezierCurve3D curve, int index) { if (curve.KeyPointsCount < 2) { return(false); } var point = curve.KeyPoints[index]; Undo.IncrementCurrentGroup(); Undo.RegisterCompleteObjectUndo(curve, "Save Curve"); curve.KeyPoints.RemoveAt(index); RenamePoints(curve); //Undo.RegisterCompleteObjectUndo(curve, "Save Curve"); Undo.DestroyObjectImmediate(point.gameObject); return(true); }
protected virtual void OnEnable() { this.curve = (BezierCurve3D)this.target; if (curve.KeyPointsCount < 2) { while (curve.KeyPointsCount != 0) { curve.RemoveKeyPointAt(this.curve.KeyPointsCount - 1); } BezierCurve3DEditor.AddDefaultPoints(this.curve); } this.keyPoints = new ReorderableList(this.serializedObject, serializedObject.FindProperty("keyPoints"), true, true, false, false); this.keyPoints.drawElementCallback = this.DrawElementCallback; this.keyPoints.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, string.Format("Points: {0}", this.keyPoints.serializedProperty.arraySize), EditorStyles.boldLabel); }; }
private static BezierPoint3D AddKeyPointAt(BezierCurve3D curve, int index) { BezierPoint3D newPoint = new GameObject("Point " + curve.KeyPointsCount, typeof(BezierPoint3D)).GetComponent <BezierPoint3D>(); newPoint.transform.parent = curve.transform; newPoint.transform.localRotation = Quaternion.identity; newPoint.Curve = curve; if (curve.KeyPointsCount == 0 || curve.KeyPointsCount == 1) { newPoint.LocalPosition = Vector3.zero; } else { if (index == 0) { newPoint.Position = (curve.KeyPoints[0].Position - curve.KeyPoints[1].Position).normalized + curve.KeyPoints[0].Position; } else if (index == curve.KeyPointsCount) { newPoint.Position = (curve.KeyPoints[index - 1].Position - curve.KeyPoints[index - 2].Position).normalized + curve.KeyPoints[index - 1].Position; } else { newPoint.Position = BezierCurve3D.GetPointOnCubicCurve(0.5f, curve.KeyPoints[index - 1], curve.KeyPoints[index]); } } Undo.IncrementCurrentGroup(); Undo.RegisterCreatedObjectUndo(newPoint.gameObject, "Create Point"); Undo.RegisterCompleteObjectUndo(curve, "Save Curve"); curve.KeyPoints.Insert(index, newPoint); RenamePoints(curve); //Undo.RegisterCompleteObjectUndo(curve, "Save Curve"); return(newPoint); }