- Modifié
I used the Skeleton Render Separator to separate the animation into multiple skeleton parts render.I noticed that the anchor point of each renderer child object is based on the center of the animation.
I need to map the click coordinates, map the screen coordinates to the meshrender within the rect local coordinates.Because of the skeleton parts render's pivot offset difference that the maping result is incorrect(when used API: Transform.InverseTransformPoint(clickPos)).
Here is my test code:
private Renderer myRender; //skeleton parts render
private Vector2 mainTexSize, boundSize, halfBoundSize;
void GetBrushPos(Vector2 screenPos)
{
myRender = GetComponent<MeshRenderer>();
boundSize = myRender.bounds.size;
mainTexSize = new Vector2(myRender.sharedMaterial.mainTexture.width, myRender.sharedMaterial.mainTexture.height);
halfBoundSize = boundSize / 2;
var clickPos = Camera.main.ScreenToWorldPoint(screenPos);
var clicklocalPos = Vector2.Scale(transform.InverseTransformPoint(clickPos), transform.lossyScale) + halfBoundSize;
var pixelPerInch = new Vector2(mainTexSize.x / boundSize.x / transform.lossyScale.x, mainTexSize.y / boundSize.y / transform.lossyScale.y);
brushPos = Vector2.Scale(Vector2.Scale(clicklocalPos, transform.lossyScale), pixelPerInch);
}
I tried to offset the vertices of the child mesh and redraw the mesh, but it didn't work because the mesh center point was zero.
So I would like to know whether it is possible to modify the center point of attachments in Spine?Or how to get the offset of renderer child bounds pivot in Unity?