Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Duplicate CurvySpline
#1
Hello, I would like to know if it's possible to duplicate a CurvySpline by code please ?
Thank you
Reply
#2
Hi,
A simple
Code:
Instantiate(yourSpline);
will do it.
In case you are not familiar with this method, it's a Unity method that duplicates a gameobject.

If you want to have more control on the copying process, you can make some custom copying code that will look like this:
Code:
   void Clone(CurvySpline spline)
   {
       var clone = CurvySpline.Create(spline);
       foreach (var controlPoint in spline.ControlPointsList)
       {
           CurvySplineSegment newControlPoint = clone.Add(controlPoint.transform.localPosition)[0];
           CopyDataFrom(controlPoint, newControlPoint);
       }
       clone.Refresh();
   }

   //warning: this does not handle metadata and connections
   static void CopyDataFrom(CurvySplineSegment source, CurvySplineSegment destination)
   {
       destination.transform.position = source.transform.position;
       destination.transform.rotation = source.transform.rotation;
       destination.AutoBakeOrientation = source.AutoBakeOrientation;
       destination.SerializedOrientationAnchor = source.SerializedOrientationAnchor;
       destination.Swirl = source.Swirl;
       destination.SwirlTurns = source.SwirlTurns;
       destination.AutoHandles = source.AutoHandles;
       destination.AutoHandleDistance = source.AutoHandleDistance;
       destination.HandleOut = source.HandleOut;
       destination.HandleIn = source.HandleIn;
       destination.OverrideGlobalTension = source.OverrideGlobalTension;
       destination.OverrideGlobalContinuity = source.OverrideGlobalContinuity;
       destination.OverrideGlobalBias = source.OverrideGlobalBias;
       destination.SynchronizeTCB = source.SynchronizeTCB;
       destination.StartTension = source.StartTension;
       destination.EndTension = source.EndTension;
       destination.StartContinuity = source.StartContinuity;
       destination.EndContinuity = source.EndContinuity;
       destination.StartBias = source.StartBias;
       destination.EndBias = source.EndBias;
   }
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Disable the Update of the CurvySpline UsernameHed 8 716 05-29-2019, 01:13 PM
Last Post: _Aka_
  CurvySpline.Interpolate() returns (0,0,0) on first frame freqout 6 4,213 04-20-2018, 03:27 PM
Last Post: _Aka_
  CurvySpline.Count return 0 after build BastienCil 1 1,475 06-29-2017, 06:24 PM
Last Post: BastienCil
  CurvySpline.Update() sorta expensive invadererik 5 4,843 04-28-2016, 02:11 PM
Last Post: Jake

Forum Jump: