Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a smarter way to do this?
#2
Hi,
You can do what you are looking for in a simpler way. I attached a zip with an example of the simpler way. Here are some explanations:
Instead of having a MetaData at the end of each path, referencing the following paths' first CP (Control Point), I prefer having a simpler MetaData at the beginning of each path.

Code:
public class BranchInfo : CurvyMetadataBase, ICurvyMetadata
{
    public string Description;
    public int Direction;
}

And here is the code doing the switch
Code:
    public void OnCPEnd(CurvySplineMoveEventArgs e)
    {
        // we need a SplineController as well as a connection to work with
        if (e.Sender is SplineController && e.ControlPoint.Connection)
        {
            CurvySplineSegment controlPointToFollow = null;
            foreach (CurvySplineSegment controlPoint in e.ControlPoint.Connection.ControlPoints)
            {
                BranchInfo branchInfo = controlPoint.GetMetadata<BranchInfo>();
                if (branchInfo && branchInfo.Direction == direction)
                {
                    controlPointToFollow = controlPoint;
                    break;
                }
            }

            e.Follow(controlPointToFollow); // Follow the new spline
            // Set the controller to use the new spline
            SplineController controller = (SplineController)e.Sender;
            controller.Spline = e.Spline;
            controller.RelativePosition = e.TF;
        }
    }

I see the following advantages in this way of doing:
  * Faster to edit and modify the levels: with this way, you skip the need to reference the first CPof each path in metaTurnInfo. This makes it faster to add paths, or to change the order of existing paths.
  * Can handle more than two directions: without changing the path switching code, you can handle multiple paths just by modifying the code that defines the value of the direction. For example you can add a 3rd path with a value of 2  for the case where the player doesn't choose left or right.
  * More efficient code: calling the OtherControlPoints function creates a new list each time, which will make the garbage collector run more often, which is bad for frame rate.

I hope that you will find your work simpler with these changes.
If my suggestion doesn't tackle some of the complexity you found, please let me know.


Attached Files
.zip   Paths.zip (Size: 6.48 KB / Downloads: 0)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Messages In This Thread
RE: Is there a smarter way to do this? - by _Aka_ - 03-02-2018, 07:48 PM
RE: Is there a smarter way to do this? - by _Aka_ - 03-03-2018, 08:50 PM

Forum Jump: