Since 4.1 (or like so) Unity Team introduced Stretched Corners mode for individual points in SpriteShapeController. The problem is - it’s been almost 2 years since this feature release, but even in 8.0 documentation it still says under Stretched Corners explanation “Please note that scripting support for this new Corner mode will be available in a later release.”.
When, guys? At least give us an option to copy and paste previous points with already enabled in the Edtior Stretched mode.
Hello, how can I access this function? I am using version 8.0.1 and this function is internal only in com.unity.2d.spriteshape@8.0.1\Runtime\Spline.cs.
There is shapeController.spline.SetCorner(int index, bool value) (where shapeController is a Sprite Shape Controller script attached to your Sprite Shape object), but the boolean is responsible for automatic mode. Ages have passed since this original question, but it looks like some kind of scripting support was added somewhere in 9.0 release, you should search it here https://docs.unity3d.com/Packages/com.unity.2d.spriteshape@9.0/api/UnityEngine.U2D.html
Hate to resurrect an old post, but I’m still not seeing support for setting the corner mode to Stretched via script. Has anyone found a solution to this?
I’m on v9.0.2 of the 2D SpriteShape package (Unity 2022.3.21f1) and I see there is a Corner enum with Disabled, Automatic, and Stretched values, but I can’t seem to find the “SetCornerMode” method mentioned by @Venkify .
I see there’s v10.0.0 version of the 2D SpriteShape package, but it requires I upgrade my Unity version so I haven’t tried that yet. The documentation for that version doesn’t show seem to have the method that I’m looking for either, so I’m not sure I’ll find it there anyway.
If someone could point me to exactly where I can find that method I would greatly appreciate it! Thanks
I’m also using SpriteShape v9.0.2 and had the same problem. I wanted to set the corner mode of each of my SpriteShape vertices to Stretched. Here’s how I managed to do that:
When decompiling the Spline class I found the method @Venkify mentioned: internal void SetCornerMode(int index, Corner value). Unfortunately since it is internal we can’t use it easily. The solution I ended up with is reflection. It’s not pretty, not ideal, but it works.
SpriteShapeController spriteShapeController = GetComponent<SpriteShapeController>();
Spline spline = spriteShapeController.spline;
Type splineType = spline.GetType();
int numberOfVertices = spline.GetPointCount();
for (int i = 0; i < numberOfVertices; i++)
{
//Use reflection to call the internal SetCornerMode method
MethodInfo setCornerModeMethodInfo = splineType.GetMethod("SetCornerMode", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
setCornerModeMethodInfo.Invoke(spline, new object[] { i, Corner.Stretched });
}
Keep in mind that since this method is internal, it is more prone to change in future version. But at the moment there doesn’t seem to be any other alternative. It would be really neat if we had a public method for doing something that we can do manually in the editor.