// add more CP's, rotating path by random angles
        void addTrackCP()
        {
            float   rndX = Random.value * CurvationX * DTUtility.RandomSign();
            float   rndY = Random.value * CurvationY * DTUtility.RandomSign();
            Vector3 p    = TrackSpline.ControlPoints[TrackSpline.ControlPointCount - 1].localPosition;

            mDir = Quaternion.Euler(rndX, rndY, 0) * mDir;
            TrackSpline.InsertAfter(null).localPosition = p + mDir * CPStepSize;
        }
        // Code that runs on entering the state.
        public override void OnEnter()
        {
            GameObject go = Fsm.GetOwnerDefaultTarget(GameObject);

            if (go)
            {
                CurvySpline spl = go.GetComponent <CurvySpline>();
                if (spl)
                {
                    if (!Index.IsNone)
                    {
                        CurvySplineSegment seg = (Index.Value >= 0 && Index.Value < spl.ControlPointCount) ? spl.ControlPoints[Index.Value] : null;
                        for (int i = 0; i < Points.Length; i++)
                        {
                            if (!Points[i].IsNone)
                            {
                                CurvySplineSegment newCP;
                                if (Mode == InsertMode.After)
                                {
                                    newCP = spl.InsertAfter(seg);
                                }
                                else
                                {
                                    newCP = spl.InsertBefore(seg);
                                }
                                if (Space == Space.Self)
                                {
                                    newCP.localPosition = Points[i].Value;
                                }
                                else
                                {
                                    newCP.position = Points[i].Value;
                                }
                            }
                        }
                        spl.Refresh();
                    }
                }
            }

            Finish();
        }
Beispiel #3
0
 CurvySplineSegment insertCP(CurvySpline spline, CurvySplineSegment current, Vector3 worldPos)
 {
     var seg = spline.InsertAfter(current);
     seg.position = worldPos;
     Undo.RegisterCreatedObjectUndo(seg.gameObject, "Add ControlPoint");
     return seg;
 }