Posts: 44
Threads: 16
Joined: Nov 2018
Hi, so I'm trying to make my gameobject have a Connection custom selector so it can decide what spline to take at a junction. I've had a look in the documentation & read this :
Use Custom behavior: define your own connected splines selecting logic. You can do that by setting an instance of a class inheriting from ConnectedControlPointsSelector.
Basically I have not got a clue how to do this.
How would I go about doing this, Id really appreciate it if someone could give me some step by step instructions, it seems like my level of coding is fairly basic.
Thanks in advance.
Posts: 1,951
Threads: 80
Joined: Jun 2017
Hi,
There is a class called ConnectedControlPointsSelector. You inherit from this class, and override its unique abstract method. Here is an example:
Code:
using System.Linq;
using UnityEngine;
class Example : ConnectedControlPointsSelector
{
public override CurvySplineSegment SelectConnectedControlPoint(SplineController caller, CurvyConnection connection, CurvySplineSegment currentControlPoint)
{
return connection.ControlPointsList.Last();
}
}
This example selector always chooses the last control point in the list of connected control points.
Then, you create an object in your scene having the Example script attached to it.
Finally, in your controller's inspector, you set "At connection, use" to "Custom", and then select the object created earlier in the field "Custom Selector"
Please let me know if you still have any question.
Have a nice day
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 44
Threads: 16
Joined: Nov 2018
Hi, thanks for the quick reply, I'll try that tomorrow.
Regards
Posts: 44
Threads: 16
Joined: Nov 2018
Ok so I get that
Code:
return connection.ControlPointsList.Last();
makes the controller go to the last spline ( & last can be exchanged for first ) but can I get it to select a spline by name or tag or something.
Regards.
Posts: 1,951
Threads: 80
Joined: Jun 2017
That was just an example. It's up to you to make your own logic depending on your needs, using Unity's API. Here you can find the documentation about the properties to get the Name and Tag of a game object: https://docs.unity3d.com/ScriptReference/GameObject.html
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Posts: 44
Threads: 16
Joined: Nov 2018
I know how to get the Name & tag of a Gameobject in Unity but connection.ControlPointsList. doesnt have a extenstion method for name.
ie What I'd like to do is
Code:
return connection.ControlPointsList.name
or
Code:
connection.ControlPointsList.tag
Sorry for all the questions but I'm finding it quite difficult to get to grips with the api.
Posts: 1,951
Threads: 80
Joined: Jun 2017
No worries for the questions:
Splines (class name CurvySpline) and control points (class name CurvySplineSegment) are all inheriting from MonoBehaviour, so as any MonoBehavioue, you can call the gameobject property on them to get the GameObject the MonoBehaviour is attached to.
ControlPointsList is a list of control points. So if you retrieve a control point from the list, let's say ControlPointsList[0], you can then call gameObject.name to get it's name.
And keep in mind that CurvySplineSegment has a Spline property to get the spline it is part of.
Please consider leaving a
review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.