mob-sakai / UIEffect

UIEffect is an effect component for uGUI element in Unity. Let's decorate your UI with effects!
https://github.com/mob-sakai/UIEffect
MIT License
5.62k stars 773 forks source link

i add spine's skeletongraphic like this #208

Open woshihuo12 opened 4 years ago

woshihuo12 commented 4 years ago

private void Awake() { mSkeletonGraphic = GetComponent(); mSkeletonGraphic.OnPostProcessVertices += OnPostProcessSkeletonGraphic; }

    private void OnPostProcessSkeletonGraphic(MeshGeneratorBuffers buffers)
    {
        if (!isActiveAndEnabled)
            return;

        float normalizedIndex = ptex.GetNormalizedIndex(this);

        // rect.
        Rect rect = m_EffectArea.GetSpineEffectArea(buffers, rectTransform.rect);

        // rotation.
        float rad = m_Rotation * Mathf.Deg2Rad;
        Vector2 dir = new Vector2(Mathf.Cos(rad), Mathf.Sin(rad));
        dir.x *= rect.height / rect.width;
        dir = dir.normalized;

        // Calculate vertex position.
        Vector2 nomalizedPos;
        Matrix2x3 localMatrix = new Matrix2x3(rect, dir.x, dir.y);  // Get local matrix.
        for (int i = 0; i < buffers.vertexCount; i++)
        {
            var vertex = buffers.vertexBuffer[i];
            m_EffectArea.GetNormalizedFactor(i, localMatrix, vertex, true, out nomalizedPos);

            var curUv = buffers.uvBuffer[i];

            buffers.uvBuffer[i] = new Vector2(
                Packer.ToFloat(curUv.x, curUv.y),
                Packer.ToFloat(nomalizedPos.y, normalizedIndex)
            );
        }
    }

so , no need modify mesh method.