Exemple #1
0
    public static Vector3 CalcTileArrowOffset(Spine.Slot boundingSlot, Transform transform, float rotation,
                                              float innerRate = 0.7f)
    {
        float   radius = AngleHelper.AngleToRadius(rotation - 90);
        Vector3 v      = new Vector3(Mathf.Cos(radius), Mathf.Sin(radius)) * 10000;

        Spine.BoundingBoxAttachment bounding = boundingSlot.Attachment as Spine.BoundingBoxAttachment;
        float[] vertices = (float[])bounding.Vertices.Clone();

        Vector2 p1 = new Vector2();
        Vector2 p2 = new Vector2();

        int n = vertices.Length / 2;

        for (int i = 0; i <= n; ++i)
        {
            int   m      = i % n;
            float localX = vertices[m * 2 + 0];
            float localY = vertices[m * 2 + 1];
            p2.Set(localX, localY);

            if (i >= 1)
            {
                float   intersectDist;
                Vector2 intersectPoint;
                if (GeometryHelper.CalcIntersectPoint(Vector2.zero, v, p1, p2, out intersectPoint, out intersectDist))
                {
                    intersectPoint *= innerRate;

                    float worldX;
                    float worldY;
                    boundingSlot.Bone.localToWorld(intersectPoint.x, intersectPoint.y, out worldX, out worldY);

                    Vector3 offset = new Vector3(worldX, worldY, 0);
                    offset = transform.TransformPoint(offset);
                    return(offset);
                }
            }

            p1 = p2;
        }

        Vector3 boneCenter = new Vector3(boundingSlot.Bone.WorldX, boundingSlot.Bone.WorldY, 0);

        boneCenter = transform.TransformPoint(boneCenter);
        return(boneCenter);
    }