예제 #1
0
        public void UpdateDisplayColor(Color col)
        {
            if (armature == null)
            {
                return;
            }

            Color rc = col;

            rc.r *= armature.color.r;
            rc.g *= armature.color.g;
            rc.b *= armature.color.b;
            rc.a *= armature.color.a;

            if (armature.isUGUI)
            {
                if (m_UIFrame)
                {
                    if (m_UIFrame.gameObject.activeSelf)
                    {
                        m_UIFrame.m_PreMultiplyAlpha = armature.m_PreMultiplyAlpha;
                        if (!m_UIFrame.color.Equals(rc))
                        {
                            m_UIFrame.m_ColorIsDirty = true;
                            m_UIFrame.color          = rc;
                        }
                        m_UIFrame.UpdateFrame();
                    }
                }
                else if (m_UIMesh)
                {
                    if (m_UIMesh.gameObject.activeSelf)
                    {
                        m_UIMesh.m_PreMultiplyAlpha = armature.m_PreMultiplyAlpha;
                        if (!m_UIMesh.color.Equals(rc))
                        {
                            m_UIMesh.m_ColorIsDirty = true;
                            m_UIMesh.color          = rc;
                        }
                        m_UIMesh.UpdateMesh();
                        if (m_UIMesh.mesh)
                        {
                            m_UIMesh.rectTransform.sizeDelta = (Vector2)m_UIMesh.mesh.bounds.size;
                        }
                    }
                }
                else if (m_Image)
                {
                    if (m_Image.gameObject.activeSelf)
                    {
                        Color c = rc;
                        if (armature.m_PreMultiplyAlpha)
                        {
                            c.r *= c.a;
                            c.g *= c.a;
                            c.b *= c.a;
                        }
                        m_Image.color = c;
                    }
                }
                else if (m_Armature)
                {
                    Color    c = color;
                    Armature parentArmature = m_Armature.parentArmature;
                    while (parentArmature)
                    {
                        c.r           *= parentArmature.color.r;
                        c.g           *= parentArmature.color.g;
                        c.b           *= parentArmature.color.b;
                        c.a           *= parentArmature.color.a;
                        parentArmature = parentArmature.parentArmature;
                    }
                    m_Armature.color = c;
                }
            }
            else
            {
                if (m_SpriteFrame)
                {
                    if (m_SpriteFrame.gameObject.activeSelf)
                    {
                        m_SpriteFrame.m_PreMultiplyAlpha = armature.m_PreMultiplyAlpha;
                        m_SpriteFrame.color = rc;
                        m_SpriteFrame.UpdateFrame();
                    }
                }
                else if (m_SpriteMesh)
                {
                    if (m_SpriteMesh.gameObject.activeSelf)
                    {
                        m_SpriteMesh.m_PreMultiplyAlpha = armature.m_PreMultiplyAlpha;
                        m_SpriteMesh.color = rc;
                        m_SpriteMesh.UpdateMesh();
                    }
                }
                else if (m_SpriteRenderer)
                {
                    if (m_SpriteRenderer.gameObject.activeSelf)
                    {
                        Color c = rc;
                        if (armature.m_PreMultiplyAlpha)
                        {
                            c.r *= c.a;
                            c.g *= c.a;
                            c.b *= c.a;
                        }
                        m_SpriteRenderer.color = c;
                    }
                }
                else if (m_Armature)
                {
                    Color    c = color;
                    Armature parentArmature = m_Armature.parentArmature;
                    while (parentArmature)
                    {
                        c.r           *= parentArmature.color.r;
                        c.g           *= parentArmature.color.g;
                        c.b           *= parentArmature.color.b;
                        c.a           *= parentArmature.color.a;
                        parentArmature = parentArmature.parentArmature;
                    }
                    m_Armature.color = c;
                }
            }
        }
예제 #2
0
        static void ShowUIMesh(TextureFrame frame, SpineData.SkinAttachment attachmentData, Transform slot, Transform skinParent, SpineArmatureEditor armatureEditor)
        {
            GameObject go = new GameObject(attachmentData.name);
            UIMesh     sm = go.AddComponent <UIMesh>();

            sm.raycastTarget = false;
            sm.transform.SetParent(skinParent);

            Vector3 localPos = Vector3.zero;

            localPos.x = attachmentData.x;
            localPos.y = attachmentData.y;
            go.transform.localPosition = localPos;

            Vector3 localSc = Vector3.one;

            localSc.x = attachmentData.scaleX;
            localSc.y = attachmentData.scaleY;
            go.transform.localScale = localSc;

            go.transform.localRotation = Quaternion.Euler(0, 0, attachmentData.rotation);

            Transform[] bones = SetMeshVertex <UIMesh>(sm, attachmentData, armatureEditor);
            sm.uvs       = attachmentData.uvs;
            sm.triangles = attachmentData.triangles;
            sm.colors    = new Color32[sm.vertices.Length];
            for (int i = 0; i < sm.colors.Length; ++i)
            {
                sm.colors[i] = Color.white;
            }
            if (armatureEditor.genMeshCollider && attachmentData.edges != null)
            {
                sm.edges = attachmentData.edges;
            }
            if (attachmentData.weights != null && attachmentData.weights.Count > 0)
            {
                sm.CreateMesh();
                if (armatureEditor.ffdKV.ContainsKey(attachmentData.textureName))
                {
                    //Vertex controller
                    sm.vertControlTrans = new Transform[sm.vertices.Length];
                    for (int i = 0; i < sm.vertices.Length; ++i)
                    {
                        GameObject gov = new GameObject(go.name + "_v" + i);
                        gov.transform.parent        = go.transform;
                        gov.transform.localPosition = sm.vertices[i];
                        gov.transform.localScale    = Vector3.zero;
                        sm.vertControlTrans[i]      = gov.transform;
                        gov.SetActive(false);
                    }
                }
            }
            else
            {
                sm.CreateMesh();
                //Vertex controller
                sm.vertControlTrans = new Transform[sm.vertices.Length];
                for (int i = 0; i < sm.vertices.Length; ++i)
                {
                    GameObject gov = new GameObject(go.name + "_v" + i);
                    gov.transform.parent        = go.transform;
                    gov.transform.localPosition = sm.vertices[i];
                    gov.transform.localScale    = Vector3.zero;
                    sm.vertControlTrans[i]      = gov.transform;
                    gov.SetActive(false);
                }
            }

            if (attachmentData.weights != null && attachmentData.weights.Count > 0)
            {
                List <Armature.BoneWeightClass> boneWeights = new List <Armature.BoneWeightClass>();
                for (int i = 0; i < attachmentData.weights.Count; ++i)
                {
                    int boneCount = (int)attachmentData.weights[i];                    //骨骼数量
                    List <KeyValuePair <int, float> > boneWeightList = new List <KeyValuePair <int, float> >();
                    for (int j = 0; j < boneCount * 2; j += 2)
                    {
                        int   boneIdx = (int)attachmentData.weights[i + j + 1];
                        float weight  = attachmentData.weights[i + j + 2];
                        boneWeightList.Add(new KeyValuePair <int, float>(boneIdx, weight));
                    }
                    //sort boneWeightList,desc
                    boneWeightList.Sort(delegate(KeyValuePair <int, float> x, KeyValuePair <int, float> y) {
                        if (x.Value == y.Value)
                        {
                            return(0);
                        }
                        return(x.Value < y.Value? 1: -1);
                    });
                    Armature.BoneWeightClass bw = new Armature.BoneWeightClass();
                    for (int j = 0; j < boneWeightList.Count; ++j)
                    {
                        if (j == 0)
                        {
                            bw.boneIndex0 = GlobalBoneIndexToLocalBoneIndex(armatureEditor, boneWeightList[j].Key, bones);
                            bw.weight0    = boneWeightList[j].Value;
                        }
                        else if (j == 1)
                        {
                            bw.boneIndex1 = GlobalBoneIndexToLocalBoneIndex(armatureEditor, boneWeightList[j].Key, bones);
                            bw.weight1    = boneWeightList[j].Value;
                        }
                        else if (j == 2)
                        {
                            bw.boneIndex2 = GlobalBoneIndexToLocalBoneIndex(armatureEditor, boneWeightList[j].Key, bones);
                            bw.weight2    = boneWeightList[j].Value;
                        }
                        else if (j == 3)
                        {
                            bw.boneIndex3 = GlobalBoneIndexToLocalBoneIndex(armatureEditor, boneWeightList[j].Key, bones);
                            bw.weight3    = boneWeightList[j].Value;
                        }
                        else if (j == 4)
                        {
                            bw.boneIndex4 = GlobalBoneIndexToLocalBoneIndex(armatureEditor, boneWeightList[j].Key, bones);
                            bw.weight4    = boneWeightList[j].Value;
                        }
                    }
                    boneWeights.Add(bw);
                    i += boneCount * 2;
                }
                Matrix4x4[] matrixArray = new Matrix4x4[bones.Length];
                for (int i = 0; i < matrixArray.Length; ++i)
                {
                    Transform bone = bones[i];
                    matrixArray[i]  = bone.worldToLocalMatrix * armatureEditor.armature.localToWorldMatrix;
                    matrixArray[i] *= Matrix4x4.TRS(slot.localPosition, slot.localRotation, slot.localScale);
                }
                sm.bones     = bones;
                sm.bindposes = matrixArray;
                sm.weights   = boneWeights.ToArray();
            }
            sm.color = attachmentData.color;
            sm.UpdateMesh();
            sm.UpdateVertexColor();
            sm.frame = frame;
        }