Пример #1
0
        /// <summary>
        /// Changes the sprite mesh.
        /// </summary>
        /// <param name="spriteMeshName">Will replace SpriteMesh'name.</param>
        /// <param name="texture">new Texture.</param>
        /// <param name="mat">Mat.</param>
        public void ChangeSpriteMesh(string spriteMeshName, Texture texture, Material mat = null, bool useMaterialBlock = true)
        {
            Renderer attachment = GetAttachmentByName(spriteMeshName);

            if (!attachment)
            {
                return;
            }
            SpriteMesh sm = attachment.GetComponent <SpriteMesh>();

            ChangeSpriteMesh(sm, texture, mat, useMaterialBlock);
        }
Пример #2
0
        /// <summary>
        /// Changes the sprite mesh.
        /// </summary>
        /// <param name="spriteMeshName">Sprite mesh name.</param>
        /// <param name="newTextureFrameName">New texture frame name.</param>
        public void ChangeSpriteMesh(string spriteMeshName, string newTextureFrameName)
        {
            Renderer attachment = GetAttachmentByName(spriteMeshName);

            if (!attachment)
            {
                return;
            }

            SpriteMesh   sm    = attachment.GetComponent <SpriteMesh>();
            TextureFrame frame = textureFrames.GetTextureFrame(newTextureFrameName);

            if (sm != null && frame != null)
            {
                sm.frame = frame;
            }
        }
Пример #3
0
        /// <summary>
        /// Changes the sprite mesh.
        /// </summary>
        /// <param name="sm">Will replace SpriteMesh</param>
        /// <param name="texture">new Texture.</param>
        /// <param name="mat">Mat.</param>
        public void ChangeSpriteMesh(SpriteMesh sm, Texture texture, Material mat = null, bool useMaterialBlock = true)
        {
            if (!sm || !texture)
            {
                return;
            }

            TextureFrame frame = new TextureFrame();

            frame.material  = mat == null ? sm.material : mat;
            frame.texture   = texture;
            frame.isRotated = false;

            frame.rect.x             = 0;
            frame.rect.y             = 0;
            frame.rect.width         = texture.width;
            frame.rect.height        = texture.height;
            frame.frameSize          = new Rect(0, 0, texture.width, texture.height);
            frame.atlasTextureSize.x = texture.width;
            frame.atlasTextureSize.y = texture.height;
            if (!sm.isCreatedMesh)
            {
                sm.CreateMesh();
            }
            sm.frame = frame;
            if (mat)
            {
                sm.material = mat;
            }

            if (useMaterialBlock)
            {
                sm.render.GetPropertyBlock(materialPropertyBlock);
                m_MatBlock.SetTexture("_MainTex", texture);
                sm.render.SetPropertyBlock(materialPropertyBlock);
            }
            else
            {
                sm.material.mainTexture = texture;
            }
        }
Пример #4
0
        protected internal void UpdateCurrentDisplay()
        {
            m_SpriteFrame    = null;
            m_SpriteMesh     = null;
            m_SpriteRenderer = null;
            m_Armature       = null;
            m_Image          = null;
            m_UIFrame        = null;
            m_UIMesh         = null;
            m_CurrentDisplay = null;
            if (armature == null)
            {
                return;
            }

            if (__displayIndex > -1 && transform.childCount > 0)
            {
                Transform skin = (armature.skins == null || armature.skins.Length <= 1) ?transform :transform.Find(armature.skinName);
                if (skin && skin.childCount > 0)
                {
                    Transform child = skin.GetChild(__displayIndex);
                    m_CurrentDisplay = child.gameObject;
                    if (armature.isUGUI)
                    {
                        m_UIFrame = child.GetComponent <UIFrame>();
                        if (!m_UIFrame)
                        {
                            m_UIMesh = child.GetComponent <UIMesh>();
                            if (!m_UIMesh)
                            {
                                m_Image = child.GetComponent <Image>();
                                if (!m_Image)
                                {
                                    m_Armature = child.GetComponent <Armature>();
                                }
                            }
                        }
                    }
                    else
                    {
                        m_SpriteFrame = child.GetComponent <SpriteFrame>();
                        if (!m_SpriteFrame)
                        {
                            m_SpriteMesh = child.GetComponent <SpriteMesh>();
                            if (!m_SpriteMesh)
                            {
                                m_SpriteRenderer = child.GetComponent <SpriteRenderer>();
                                if (!m_SpriteRenderer)
                                {
                                    m_Armature = child.GetComponent <Armature>();
                                }
                            }
                        }
                        UpdateZOrder();
                    }
                }
            }
            else if (armature.skins != null && armature.skins.Length > 1)
            {
                for (int i = 0; i < transform.childCount; ++i)
                {
                    transform.GetChild(i).gameObject.SetActive(false);
                }
            }
        }
Пример #5
0
        static void ShowSpriteMesh(TextureFrame frame, SpineData.SkinAttachment attachmentData, Transform slot, Transform skinParent, SpineArmatureEditor armatureEditor)
        {
            GameObject go = new GameObject(attachmentData.name);
            SpriteMesh sm = go.AddComponent <SpriteMesh>();

            sm.transform.parent = 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 <SpriteMesh>(sm, attachmentData, armatureEditor);
            sm.uvs       = attachmentData.uvs;
            sm.triangles = attachmentData.triangles;
            sm.colors    = new Color[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;
                            break;
                        }
                    }
                    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;
        }
Пример #6
0
        //init
        public void InitShow()
        {
            DragonBoneShowArmature.AddBones(this);
            DragonBoneShowArmature.AddSlot(this);
            DragonBoneShowArmature.ShowBones(this);
            DragonBoneShowArmature.ShowSlots(this);
            DragonBoneShowArmature.ShowSkins(this);
            DragonBoneShowArmature.SetIKs(this);
            DragonBoneAnimFile.CreateAnimFile(this);

            Armature armature = _armature.GetComponent <Armature>();

            m_prefabs.Add(_armature.gameObject);
            armature.textureFrames = m_TextureFrames;

            //update slot display
            for (int s = 0; s < m_slots.Count; ++s)
            {
                m_slots[s].displayIndex = m_slots[s].displayIndex;
            }

            if (armature.isUGUI)
            {
                UnityEngine.UI.MaskableGraphic[] renders = _armature.GetComponentsInChildren <UnityEngine.UI.MaskableGraphic>(true);
                armature.uiAttachments = renders;
                armature.attachments   = new Renderer[0];
            }
            else
            {
                Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(true);
                armature.attachments   = renders;
                armature.uiAttachments = new UnityEngine.UI.MaskableGraphic[0];
            }
            armature.slots        = m_slots.ToArray();
            armature.bones        = m_bones.ToArray();
            armature.zSpace       = zoffset;
            armature.sonArmatures = m_sonArmature.ToArray();
            if (armatureAnimList.ContainsKey(armature.name))
            {
                armature.anims = armatureAnimList[armature.name].ToArray();
            }
            armature.ResetSlotZOrder();

            string path = AssetDatabase.GetAssetPath(animTextAsset);

            path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name;


            //create pose data
            PoseData poseData = AssetDatabase.LoadAssetAtPath <PoseData>(path + "_Pose.asset");

            if (poseData == null)
            {
                poseData = ScriptableObject.CreateInstance <PoseData>();
                AssetDatabase.CreateAsset(poseData, path + "_Pose.asset");
            }
            poseData.slotDatas = new PoseData.SlotData[armature.slots.Length];
            for (int i = 0; i < armature.slots.Length; ++i)
            {
                poseData.slotDatas[i]              = new PoseData.SlotData();
                poseData.slotDatas[i].color        = armature.slots[i].color;
                poseData.slotDatas[i].displayIndex = armature.slots[i].displayIndex;
                poseData.slotDatas[i].zorder       = armature.slots[i].z;
                armature.slots[i].SendMessage("UpdateSlotByInheritSlot", SendMessageOptions.DontRequireReceiver);
            }
            poseData.boneDatas = new PoseData.TransformData[armature.bones.Length];
            for (int i = 0; i < armature.bones.Length; ++i)
            {
                poseData.boneDatas[i]          = new PoseData.TransformData();
                poseData.boneDatas[i].x        = armature.bones[i].localPosition.x;
                poseData.boneDatas[i].y        = armature.bones[i].localPosition.y;
                poseData.boneDatas[i].sx       = armature.bones[i].localScale.x;
                poseData.boneDatas[i].sy       = armature.bones[i].localScale.y;
                poseData.boneDatas[i].rotation = armature.bones[i].localEulerAngles.z;
            }
            if (isUGUI)
            {
                poseData.displayDatas = new PoseData.DisplayData[armature.uiAttachments.Length];
                for (int i = 0; i < armature.uiAttachments.Length; ++i)
                {
                    poseData.displayDatas[i] = new PoseData.DisplayData();
                    UnityEngine.UI.MaskableGraphic render = armature.uiAttachments[i];

                    UIFrame sf = render.GetComponent <UIFrame>();
                    if (sf)
                    {
                        poseData.displayDatas[i].type  = PoseData.AttachmentType.IMG;
                        poseData.displayDatas[i].color = sf.color;
                    }
                    else
                    {
                        UIMesh sm = render.GetComponent <UIMesh>();
                        if (sm)
                        {
                            poseData.displayDatas[i].type   = PoseData.AttachmentType.MESH;
                            poseData.displayDatas[i].color  = sm.color;
                            poseData.displayDatas[i].vertex = (Vector3[])sm.vertices.Clone();
                            if (sm.weights == null || sm.weights.Length == 0)
                            {
                                for (int k = 0; k < poseData.displayDatas[i].vertex.Length; ++k)
                                {
                                    poseData.displayDatas[i].vertex[k] /= 100f;
                                }
                            }
                        }
                        else
                        {
                            UnityEngine.UI.Image sr = render.GetComponent <UnityEngine.UI.Image>();
                            if (sr)
                            {
                                poseData.displayDatas[i].type  = PoseData.AttachmentType.IMG;
                                poseData.displayDatas[i].color = sr.color;
                            }
                            else
                            {
                                poseData.displayDatas[i].type = PoseData.AttachmentType.BOX;
                            }
                        }
                    }
                    poseData.displayDatas[i].transform          = new PoseData.TransformData();
                    poseData.displayDatas[i].transform.x        = render.transform.localPosition.x;
                    poseData.displayDatas[i].transform.y        = render.transform.localPosition.y;
                    poseData.displayDatas[i].transform.sx       = render.transform.localScale.x;
                    poseData.displayDatas[i].transform.sy       = render.transform.localScale.y;
                    poseData.displayDatas[i].transform.rotation = render.transform.localEulerAngles.z;
                    render.transform.localScale *= unit;
                }
            }
            else
            {
                poseData.displayDatas = new PoseData.DisplayData[armature.attachments.Length];
                for (int i = 0; i < armature.attachments.Length; ++i)
                {
                    poseData.displayDatas[i] = new PoseData.DisplayData();
                    Renderer render = armature.attachments[i];

                    SpriteFrame sf = render.GetComponent <SpriteFrame>();
                    if (sf)
                    {
                        poseData.displayDatas[i].type  = PoseData.AttachmentType.IMG;
                        poseData.displayDatas[i].color = sf.color;
                    }
                    else
                    {
                        SpriteMesh sm = render.GetComponent <SpriteMesh>();
                        if (sm)
                        {
                            poseData.displayDatas[i].type   = PoseData.AttachmentType.MESH;
                            poseData.displayDatas[i].color  = sm.color;
                            poseData.displayDatas[i].vertex = (Vector3[])sm.vertices.Clone();
                        }
                        else
                        {
                            SpriteRenderer sr = render.GetComponent <SpriteRenderer>();
                            if (sr)
                            {
                                poseData.displayDatas[i].type  = PoseData.AttachmentType.IMG;
                                poseData.displayDatas[i].color = sr.color;
                            }
                            else
                            {
                                poseData.displayDatas[i].type = PoseData.AttachmentType.BOX;
                            }
                        }
                    }
                    poseData.displayDatas[i].transform          = new PoseData.TransformData();
                    poseData.displayDatas[i].transform.x        = render.transform.localPosition.x;
                    poseData.displayDatas[i].transform.y        = render.transform.localPosition.y;
                    poseData.displayDatas[i].transform.sx       = render.transform.localScale.x;
                    poseData.displayDatas[i].transform.sy       = render.transform.localScale.y;
                    poseData.displayDatas[i].transform.rotation = render.transform.localEulerAngles.z;
                }
            }
            armature.poseData = poseData;
            AssetDatabase.Refresh();
            EditorUtility.SetDirty(poseData);
            AssetDatabase.SaveAssets();
            if (armature.textureFrames && armature.textureFrames.materials != null && armature.textureFrames.materials.Length > 0)
            {
                armature.preMultiplyAlpha = armature.textureFrames.materials[0].GetFloat("_BlendSrc") == (int)UnityEngine.Rendering.BlendMode.One;
            }
            else
            {
                armature.preMultiplyAlpha = true;
            }

            if (armature.isUGUI)
            {
                GameObject canvas = GameObject.Find("/Canvas");
                if (canvas)
                {
                    _armature.SetParent(canvas.transform);
                    _armature.localScale    = Vector3.one / unit;
                    _armature.localPosition = Vector3.zero;
                }
            }

            if (genPrefab)
            {
                string     prefabPath = path + ".prefab";
                GameObject prefab     = AssetDatabase.LoadAssetAtPath <GameObject>(prefabPath);
                if (!prefab)
                {
                    PrefabUtility.CreatePrefab(prefabPath, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab);
                }
                else
                {
                    PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
                }
            }
        }
Пример #7
0
        public override void OnInspectorGUI()
        {
            Armature armature = target as Armature;

            if (armature == null)
            {
                return;
            }

            bool haveGroup = false;

                        #if UNITY_5_6_OR_NEWER
            haveGroup = armature.sortingGroup != null;
                        #endif

            if (!armature.isUGUI && !haveGroup)
            {
                selectedOption = EditorGUILayout.Popup("Sorting Layer", selectedOption, sortingLayerNames);
                if (sortingLayerNames[selectedOption] != armature.sortingLayerName)
                {
                    Undo.RecordObject(armature, "Sorting Layer");
                    armature.sortingLayerName = sortingLayerNames[selectedOption];
                    EditorUtility.SetDirty(armature);
                }

                int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", armature.sortingOrder);
                if (newSortingLayerOrder != armature.sortingOrder)
                {
                    Undo.RecordObject(armature, "Edit Sorting Order");
                    armature.sortingOrder = newSortingLayerOrder;
                    EditorUtility.SetDirty(armature);
                }

                if (GUILayout.Button("Update All Sorting", GUILayout.Height(20)))
                {
                    armature.sortingLayerName = armature.sortingLayerName;
                    armature.sortingOrder     = armature.sortingOrder;
                    EditorUtility.SetDirty(armature);

                    foreach (Renderer render in armature.GetComponentsInChildren <Renderer>(true))
                    {
                        render.sortingLayerName = armature.sortingLayerName;
                        render.sortingOrder     = armature.sortingOrder;
                        EditorUtility.SetDirty(render);

                        SpriteFrame sf = render.GetComponent <SpriteFrame>();
                        if (sf)
                        {
                            sf.sortingLayerName = armature.sortingLayerName;
                            sf.sortingOrder     = armature.sortingOrder;
                            UnityEditor.EditorUtility.SetDirty(sf);
                        }
                        else
                        {
                            SpriteMesh sm = render.GetComponent <SpriteMesh>();
                            if (sm)
                            {
                                sm.sortingLayerName = armature.sortingLayerName;
                                sm.sortingOrder     = armature.sortingOrder;
                                UnityEditor.EditorUtility.SetDirty(sm);
                            }
                        }
                    }

                    foreach (Armature sonArmature in armature.GetComponentsInChildren <Armature>(true))
                    {
                        sonArmature.sortingLayerName = sonArmature.sortingLayerName;
                        sonArmature.sortingOrder     = sonArmature.sortingOrder;
                        EditorUtility.SetDirty(sonArmature);
                    }

                    if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    }
                }
                EditorGUILayout.Space();
            }

            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("color"), true);
            if (!Application.isPlaying)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_FlipX"), true);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_FlipY"), true);
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_PreMultiplyAlpha"), true);

            if (!Application.isPlaying)
            {
                if (!armature.isUGUI)
                {
                                        #if UNITY_5_6_OR_NEWER
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("sortType"), true);
                                        #else
                    armature.sortType = Armature.SortType.ZSpace;
                                        #endif
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("zSpace"), true);

                    if (sortType != armature.sortType)
                    {
                        sortType = armature.sortType;
                        armature.sortingOrder = armature.sortingOrder;
                    }
                }
            }
            if (armature.anims != null && armature.anims.Length > 0)
            {
                int temp = (int)armature.animIndex;
                System.Collections.Generic.List <string> animsList = new System.Collections.Generic.List <string>(armature.anims);
                animsList.Insert(0, "<None>");
                armature.animIndex = EditorGUILayout.Popup("Current Animation", temp + 1, animsList.ToArray()) - 1;
                if (armature.animIndex != temp && !Application.isPlaying)
                {
                    UnityEditor.EditorUtility.SetDirty(armature);
                    if (!Application.isPlaying && !string.IsNullOrEmpty(armature.gameObject.scene.name))
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    }
                }
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("anims"), true);
            if (armature.skins != null && armature.skins.Length > 1)
            {
                int temp = armature.skinIndex;
                armature.skinIndex = EditorGUILayout.Popup("Skins", armature.skinIndex, armature.skins);
                if (temp != armature.skinIndex && !Application.isPlaying)
                {
                    UnityEditor.EditorUtility.SetDirty(armature);
                    if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    }
                }
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("slots"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("bones"), true);
            if (armature.isUGUI)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("uiAttachments"), true);
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("attachments"), true);
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sonArmatures"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("parentArmature"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("textureFrames"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("poseData"), true);
            serializedObject.ApplyModifiedProperties();

            if (!Application.isPlaying && armature.flipX != flipX)
            {
                armature.flipX = armature.flipX;
                flipX          = armature.flipX;
                if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
            if (!Application.isPlaying && armature.flipY != flipY)
            {
                armature.flipY = armature.flipY;
                flipY          = armature.flipY;
                if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
            if (!Application.isPlaying && armature.zSpace != zspace)
            {
                zspace = armature.zSpace;
                armature.ResetSlotZOrder();
                if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }

            if (armature.preMultiplyAlpha != preMultiplyAlpha)
            {
                preMultiplyAlpha          = armature.preMultiplyAlpha;
                armature.preMultiplyAlpha = preMultiplyAlpha;
                if (!Application.isPlaying && !string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
            if (!Application.isPlaying && !armature.isUGUI && armature.parentArmature == null)
            {
                ArmatureMesh am = armature.gameObject.GetComponent <ArmatureMesh>();
                if (!am)
                {
                    if (GUILayout.Button("Add Armature Mesh", GUILayout.Height(20)))
                    {
                        am = armature.gameObject.AddComponent <ArmatureMesh>();
                    }
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Set To Pose", GUILayout.Height(20)))
            {
                armature.SetToPose();
            }
        }
Пример #8
0
        /// <summary>
        /// Sets to pose.
        /// </summary>
        public void SetToPose()
        {
            if (poseData)
            {
                for (int i = 0; i < poseData.boneDatas.Length && i < bones.Length; ++i)
                {
                    Transform bone = bones[i];
                    if (bone)
                    {
                        PoseData.TransformData transData = poseData.boneDatas[i];
                        bone.localPosition    = new Vector3(transData.x, transData.y, bone.localPosition.z);
                        bone.localScale       = new Vector3(transData.sx, transData.sy, bone.localScale.z);
                        bone.localEulerAngles = new Vector3(bone.localEulerAngles.x, bone.localEulerAngles.y, transData.rotation);
                    }
                }
                for (int i = 0; i < poseData.slotDatas.Length && i < slots.Length; ++i)
                {
                    Slot slot = slots[i];
                    if (slot)
                    {
                        slot.color        = poseData.slotDatas[i].color;
                        slot.displayIndex = poseData.slotDatas[i].displayIndex;
                        slot.z            = poseData.slotDatas[i].zorder;
                    }
                    m_SortedSlots = null;
                }
                if (isUGUI)
                {
                    for (int i = 0; i < poseData.displayDatas.Length && i < uiAttachments.Length; ++i)
                    {
                        MaskableGraphic mg = uiAttachments[i];
                        if (mg)
                        {
                            PoseData.DisplayData displayData = poseData.displayDatas[i];
                            switch (displayData.type)
                            {
                            case PoseData.AttachmentType.IMG:
                                UIFrame uf = mg.GetComponent <UIFrame>();
                                if (uf)
                                {
                                    uf.color = displayData.color;
                                }
                                else
                                {
                                    Image img = mg.GetComponent <Image>();
                                    if (img)
                                    {
                                        img.color = displayData.color;
                                    }
                                }
                                break;

                            case PoseData.AttachmentType.MESH:
                                UIMesh um = mg.GetComponent <UIMesh> ();
                                um.vertices = (Vector3[])displayData.vertex.Clone();
                                if (um.vertControlTrans != null && um.vertControlTrans.Length > 0)
                                {
                                    for (int j = 0; j < um.vertControlTrans.Length && j < um.vertices.Length; ++j)
                                    {
                                        Transform vctr = um.vertControlTrans [j];
                                        if (vctr)
                                        {
                                            vctr.localPosition = um.vertices [j];
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < poseData.displayDatas.Length && i < attachments.Length; ++i)
                    {
                        Renderer r = attachments[i];
                        if (r)
                        {
                            PoseData.DisplayData displayData = poseData.displayDatas[i];
                            switch (displayData.type)
                            {
                            case PoseData.AttachmentType.IMG:
                                SpriteFrame sf = r.GetComponent <SpriteFrame>();
                                if (sf)
                                {
                                    sf.color = displayData.color;
                                }
                                else
                                {
                                    SpriteRenderer sr = r.GetComponent <SpriteRenderer>();
                                    if (sr)
                                    {
                                        sr.color = displayData.color;
                                    }
                                }
                                break;

                            case PoseData.AttachmentType.MESH:
                                SpriteMesh sm = r.GetComponent <SpriteMesh>();
                                sm.vertices = (Vector3[])displayData.vertex.Clone();
                                if (sm.vertControlTrans != null)
                                {
                                    for (int j = 0; j < sm.vertControlTrans.Length && j < sm.vertices.Length; ++j)
                                    {
                                        Transform vctr = sm.vertControlTrans[j];
                                        if (vctr)
                                        {
                                            vctr.localPosition = sm.vertices[j];
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            ResetSlotZOrder();
        }
Пример #9
0
 void OnEnable()
 {
     sm = target as SpriteMesh;
 }