コード例 #1
0
        //init
        public void InitShow()
        {
            ShowArmature.AddBones(this);
            ShowArmature.AddSlot(this);
            ShowArmature.ShowBones(this);
            ShowArmature.ShowSlots(this);
            ShowArmature.ShowSkins(this);
            ShowArmature.SetIKs(this);
            AnimFile.CreateAnimFile(this);

            DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>();

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

            Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(true);
            foreach (Renderer r in renders)
            {
                if (r.GetComponent <SpriteFrame>())
                {
                    //optimize memory
                    SpriteFrame  sf = r.GetComponent <SpriteFrame>();
                    TextureFrame tf = sf.frame;
                    sf.frames = new TextureFrame[] { tf };
                }
            }
            dba.attachments = renders;
            dba.slots       = slots.ToArray();
            dba.zSpace      = zoffset;
            dba.ResetSlotZOrder();

            string path = AssetDatabase.GetAssetPath(animTextAsset);

            path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name + ".prefab";
            GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path);

            if (!prefab)
            {
                PrefabUtility.CreatePrefab(path, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab);
            }
            else
            {
                PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
            }
        }
コード例 #2
0
 /// <summary>
 /// Get TextureFrame By Name
 /// </summary>
 /// <returns>The frame by name.</returns>
 /// <param name="name">Name.</param>
 public TextureFrame GetFrameByName(string name)
 {
     if (frames != null)
     {
         int len = frames.Length;
         for (int i = 0; i < len; ++i)
         {
             TextureFrame frame = frames[i];
             if (frame.name.Equals(name))
             {
                 return(frame);
             }
         }
     }
     return(null);
 }
コード例 #3
0
 public void ParseAtlasText()
 {
     if (atlasText != null && atlasMat != null && atlasMat.mainTexture != null)
     {
         SimpleJSON.JSONClass obj = SimpleJSON.JSON.Parse(atlasText.text).AsObject;
         SimpleJSON.JSONArray arr = obj["SubTexture"].AsArray;
         frames = new TextureFrame[arr.Count];
         Vector2 textureSize = new Vector2(atlasMat.mainTexture.width, atlasMat.mainTexture.height);
         for (int i = 0; i < arr.Count; ++i)
         {
             SimpleJSON.JSONClass frameObj = arr[i].AsObject;
             TextureFrame         frame    = new TextureFrame();
             frame.atlasTextureSize = textureSize;
             frame.name             = frameObj["name"];
             frame.name             = frame.name.Replace('/', '_');
             frame.texture          = atlasMat.mainTexture;
             frame.material         = atlasMat;
             Rect rect = new Rect();
             rect.x      = frameObj["x"].AsFloat * textureScale;
             rect.y      = frameObj["y"].AsFloat * textureScale;
             rect.width  = frameObj["width"].AsFloat * textureScale;
             rect.height = frameObj["height"].AsFloat * textureScale;
             Rect frameSize = new Rect(0, 0, rect.width, rect.height);
             if (frameObj.ContainKey("frameX"))
             {
                 frameSize.x = frameObj["frameX"].AsFloat * textureScale;
             }
             if (frameObj.ContainKey("frameY"))
             {
                 frameSize.y = frameObj["frameY"].AsFloat * textureScale;
             }
             if (frameObj.ContainKey("frameWidth"))
             {
                 frameSize.width = frameObj["frameWidth"].AsFloat * textureScale;
             }
             if (frameObj.ContainKey("frameHeight"))
             {
                 frameSize.height = frameObj["frameHeight"].AsFloat * textureScale;
             }
             frame.rect      = rect;
             frame.frameSize = frameSize;
             frames[i]       = frame;
         }
     }
 }
コード例 #4
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 = GetTextureFrameByName(newTextureFrameName);

            if (sm != null && frame != null)
            {
                sm.atlasMat = frame.material;
                attachment.sharedMaterial = frame.material;
                sm.frame = frame;
                sm.UpdateUV();
            }
        }
コード例 #5
0
        /// <summary>
        /// Changes the sprite frame.
        /// </summary>
        /// <param name="spriteFrameName">Sprite frame name.</param>
        /// <param name="newTextureFrameName">New texture frame name.</param>
        public void ChangeSpriteFrame(string spriteFrameName, string newTextureFrameName)
        {
            Renderer attachment = GetAttachmentByName(spriteFrameName);

            if (!attachment)
            {
                return;
            }

            SpriteFrame  sf    = attachment.GetComponent <SpriteFrame>();
            TextureFrame frame = GetTextureFrameByName(newTextureFrameName);

            if (sf != null && frame != null)
            {
                sf.atlasMat = frame.material;
                attachment.sharedMaterial = frame.material;
                sf.frames[0] = frame;
                sf.frameName = newTextureFrameName;
                sf.UpdateVertex();
            }
        }
コード例 #6
0
ファイル: ShowArmature.cs プロジェクト: BING2213/Guernica
        static void ShowSpriteMesh(TextureFrame frame, Material mat, DragonBoneData.SkinSlotDisplayData displayData, Transform slot, ArmatureEditor armatureEditor, DragonBoneData.SlotData slotData)
        {
            armatureEditor.spriteMeshUsedMatKV[mat] = true;
            GameObject go = new GameObject(displayData.textureName);
            SpriteMesh sm = go.AddComponent <SpriteMesh>();

            sm.atlasMat  = mat;
            sm.vertices  = displayData.vertices;
            sm.frame     = frame;
            sm.uvs       = displayData.uvs;
            sm.triangles = displayData.triangles;
            sm.colors    = new Color[sm.vertices.Length];
            for (int i = 0; i < sm.colors.Length; ++i)
            {
                sm.colors[i] = Color.white;
            }
            if (displayData.weights != null && displayData.weights.Length > 0)
            {
                sm.CreateMesh(true);
                if (armatureEditor.ffdKV.ContainsKey(displayData.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;
                    }
                }
            }
            else
            {
                sm.CreateMesh(false);
                if (displayData.bonePose == null)
                {
                    //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;
                    }
                }
            }
            sm.transform.parent = slot;

            if (displayData.bonePose != null)
            {
                SkinnedMeshRenderer skinnedMesh = sm.GetComponent <SkinnedMeshRenderer>();
                if (skinnedMesh)
                {
                    skinnedMesh.quality = SkinQuality.Bone4;
                    if (displayData.weights != null && displayData.weights.Length > 0)
                    {
                        Transform[] bones = new Transform[displayData.bonePose.Length / 7];
                        for (int i = 0; i < displayData.bonePose.Length; i += 7)
                        {
                            int index     = i / 7;
                            int boneIndex = (int)displayData.bonePose[i];
                            bones[index] = armatureEditor.bones[boneIndex];
                        }

                        List <BoneWeight> boneWeights = new List <BoneWeight>();
                        for (int i = 0; i < displayData.weights.Length; ++i)
                        {
                            int boneCount = (int)displayData.weights[i];                            //骨骼数量

                            List <KeyValuePair <int, float> > boneWeightList = new List <KeyValuePair <int, float> >();
                            for (int j = 0; j < boneCount * 2; j += 2)
                            {
                                int   boneIdx = (int)displayData.weights[i + j + 1];
                                float weight  = displayData.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);
                            });
                            BoneWeight bw = new BoneWeight();
                            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;
                                }
                            }
                            boneWeights.Add(bw);
                            i += boneCount * 2;
                        }
                        Matrix4x4[] matrixArray = new Matrix4x4[bones.Length];
                        for (int i = 0; i < matrixArray.Length; ++i)
                        {
                            Transform  bone       = bones[i];
                            Vector3    bonePos    = bone.localPosition;
                            Quaternion boneRotate = bone.localRotation;

                            Matrix2D m2d = armatureEditor.bonePoseKV[displayData.textureName + bone.name];
                            bone.position = new Vector3(m2d.tx * 0.01f, -m2d.ty * 0.01f, bone.position.z);
                            bone.rotation = Quaternion.Euler(0f, 0f, -m2d.GetAngle());

                            matrixArray[i]  = bone.worldToLocalMatrix * armatureEditor.armature.localToWorldMatrix;
                            matrixArray[i] *= Matrix4x4.TRS(slot.localPosition, slot.localRotation, slot.localScale);

                            bone.localPosition = bonePos;
                            bone.localRotation = boneRotate;
                        }
                        skinnedMesh.bones = bones;
                        skinnedMesh.sharedMesh.boneWeights = boneWeights.ToArray();
                        skinnedMesh.sharedMesh.bindposes   = matrixArray;
                        skinnedMesh.rootBone = slot;
                        sm.bindposes         = matrixArray;
                        SpriteMesh.BoneWeightClass[] bwcs = new SpriteMesh.BoneWeightClass[boneWeights.Count];
                        for (int i = 0; i < boneWeights.Count; ++i)
                        {
                            SpriteMesh.BoneWeightClass bwc = new SpriteMesh.BoneWeightClass();
                            BoneWeight bw = boneWeights[i];
                            bwc.boneIndex0 = bw.boneIndex0;
                            bwc.boneIndex1 = bw.boneIndex1;
                            bwc.boneIndex2 = bw.boneIndex2;
                            bwc.boneIndex3 = bw.boneIndex3;
                            bwc.weight0    = bw.weight0;
                            bwc.weight1    = bw.weight1;
                            bwc.weight2    = bw.weight2;
                            bwc.weight3    = bw.weight3;
                            bwcs[i]        = bwc;
                        }
                        sm.weights = bwcs;
                    }
                }
            }
            DragonBoneData.TransformData tranform = displayData.transform;
            Vector3 localPos = Vector3.zero;

            if (!float.IsNaN(tranform.x))
            {
                localPos.x = tranform.x;
            }
            if (!float.IsNaN(tranform.y))
            {
                localPos.y = tranform.y;
            }
            sm.transform.localPosition = localPos;

            Vector3 localSc = Vector3.one;

            if (!float.IsNaN(tranform.scx))
            {
                localSc.x = tranform.scx;
            }
            if (!float.IsNaN(tranform.scy))
            {
                localSc.y = tranform.scy;
            }
            sm.transform.localScale = localSc;

            sm.color = slot.GetComponent <Slot>().color;
            sm.transform.localRotation = Quaternion.Euler(0, 0, tranform.rotate);
        }
コード例 #7
0
ファイル: ShowArmature.cs プロジェクト: BING2213/Guernica
        public static void ShowSkins(ArmatureEditor armatureEditor)
        {
            if (armatureEditor.armatureData.skinDatas != null && armatureEditor.armatureData.skinDatas.Length > 0)
            {
                DragonBoneArmature armature            = armatureEditor.armature.GetComponent <DragonBoneArmature>();
                Dictionary <Texture2D, Material> matKV = new Dictionary <Texture2D, Material>();
                List <Material> mats = new List <Material>();
                //创建贴图集的材质
                Material atlasMat = null;
                if (armatureEditor.altasTexture)
                {
                    Material mat  = null;
                    string   path = AssetDatabase.GetAssetPath(armatureEditor.altasTexture);
                    path = path.Substring(0, path.LastIndexOf('.')) + "_Mat.mat";
                    mat  = AssetDatabase.LoadAssetAtPath <Material>(path);
                    if (!mat)
                    {
                        mat = new Material(Shader.Find("DragonBone/DragonBone Simple"));
                        AssetDatabase.CreateAsset(mat, path);
                    }
                    mat.mainTexture = armatureEditor.altasTexture;
                    matKV[armatureEditor.altasTexture] = mat;
                    atlasMat = mat;
                    mats.Add(mat);
                }

                if (armatureEditor.otherTextures != null && armatureEditor.otherTextures.Length > 0)
                {
                    for (int r = 0; r < armatureEditor.otherTextures.Length; ++r)
                    {
                        ArmatureEditor.Atlas atlas = armatureEditor.otherTextures[r];
                        Material             mat   = null;

                        string path = AssetDatabase.GetAssetPath(atlas.texture);
                        path = path.Substring(0, path.LastIndexOf('.')) + "_Mat.mat";
                        mat  = AssetDatabase.LoadAssetAtPath <Material>(path);
                        if (!mat)
                        {
                            mat = new Material(Shader.Find("DragonBone/DragonBone Simple"));
                            AssetDatabase.CreateAsset(mat, path);
                        }
                        mat.mainTexture      = atlas.texture;
                        matKV[atlas.texture] = mat;
                        mats.Add(mat);
                    }
                }

                //create Frames
                Dictionary <Texture2D, SpriteFrame> frameKV = new Dictionary <Texture2D, SpriteFrame>();
                List <TextureFrame> tfs = new List <TextureFrame>();

                SpriteFrame frame = null;
                if (armatureEditor.altasTextAsset != null)
                {
                    GameObject  go = new GameObject();
                    SpriteFrame sf = go.AddComponent <SpriteFrame>();
                    sf.atlasMat  = atlasMat;
                    sf.atlasText = armatureEditor.altasTextAsset;
                    sf.ParseAtlasText();
                    sf.CreateQuad();
                    frameKV[armatureEditor.altasTexture] = sf;
                    frame = sf;
                    tfs.AddRange(frame.frames);
                }
                if (armatureEditor.otherTextures != null && armatureEditor.otherTextures.Length > 0)
                {
                    for (int r = 0; r < armatureEditor.otherTextures.Length; ++r)
                    {
                        ArmatureEditor.Atlas atlas = armatureEditor.otherTextures[r];
                        GameObject           go    = new GameObject();
                        SpriteFrame          sf    = go.AddComponent <SpriteFrame>();
                        sf.atlasMat  = matKV[atlas.texture];
                        sf.atlasText = atlas.atlasText;
                        sf.ParseAtlasText();
                        sf.CreateQuad();
                        frameKV[atlas.texture] = sf;
                        tfs.AddRange(sf.frames);
                    }
                }

                List <SpriteMetaData> metaDatas = new List <SpriteMetaData>();
                List <SpriteRenderer> sprites   = new List <SpriteRenderer>();

                int meshSpriteCount = 0;
                int len             = armatureEditor.armatureData.skinDatas.Length;
                for (int i = 0; i < len; ++i)
                {
                    DragonBoneData.SkinData skinData = armatureEditor.armatureData.skinDatas[i];
                    for (int j = 0; j < skinData.slots.Length; ++j)
                    {
                        DragonBoneData.SkinSlotData skinSlotData = skinData.slots[j];
                        Transform slot = armatureEditor.slotsKV[skinSlotData.slotName];
                        DragonBoneData.SlotData slotData = armatureEditor.slotsDataKV[skinSlotData.slotName];
                        if (slot && skinSlotData.displays != null && skinSlotData.displays.Length > 0)
                        {
                            for (int k = 0; k < skinSlotData.displays.Length; ++k)
                            {
                                DragonBoneData.SkinSlotDisplayData displayData = skinSlotData.displays[k];
                                if (displayData.type != "image" && displayData.type != "mesh" && displayData.type != "boundingBox")
                                {
                                    continue;
                                }

                                if (displayData.type.Equals("boundingBox"))
                                {
                                    if (displayData.subType == "polygon")
                                    {
                                        ShowCustomCollider(displayData, slot, armatureEditor, slotData);
                                    }
                                    continue;
                                }

                                ArmatureEditor.Atlas atlas = armatureEditor.GetAtlasByTextureName(displayData.texturePath);
                                if (!armatureEditor.isSingleSprite)
                                {
                                    atlasMat = matKV[atlas.texture];
                                    frame    = frameKV[atlas.texture];
                                }

                                if (displayData.type == "image")
                                {
                                    if (armatureEditor.useUnitySprite)
                                    {
                                        if (armatureEditor.isSingleSprite)
                                        {
                                            Sprite sprite     = armatureEditor.spriteKV[displayData.textureName];
                                            string spritePath = AssetDatabase.GetAssetPath(sprite);
                                            if (displayData.pivot.x != 0 || displayData.pivot.y != 0)
                                            {
                                                TextureImporter textureImporter = AssetImporter.GetAtPath(spritePath) as TextureImporter;
                                                textureImporter.textureType         = TextureImporterType.Sprite;
                                                textureImporter.spriteImportMode    = SpriteImportMode.Single;
                                                textureImporter.spritePixelsPerUnit = 100;
                                                textureImporter.spritePivot         = new Vector2((displayData.pivot.x + sprite.rect.width / 2) / sprite.rect.width, (displayData.pivot.y + sprite.rect.height / 2) / sprite.rect.height);
                                                AssetDatabase.ImportAsset(spritePath, ImportAssetOptions.ForceUpdate);
                                            }
                                            sprites.Add(ShowUnitySpriteSingle(sprite, displayData, slot, slotData));
                                        }
                                        else
                                        {
                                            SpriteMetaData metaData = new SpriteMetaData();
                                            metaData.name   = displayData.textureName;
                                            metaData.rect   = frame.GetFrameByName(displayData.texturePath).rect;
                                            metaData.rect.y = armatureEditor.altasTexture.height - metaData.rect.y - metaData.rect.height;
                                            if (displayData.pivot.x != 0 || displayData.pivot.y != 0)
                                            {
                                                metaData.alignment = (int)SpriteAlignment.Custom;
                                                metaData.pivot     = new Vector2((displayData.pivot.x + metaData.rect.width / 2) / metaData.rect.width, (displayData.pivot.y + metaData.rect.height / 2) / metaData.rect.height);
                                            }
                                            metaDatas.Add(metaData);
                                            sprites.Add(ShowUnitySprite(atlasMat, displayData, slot, metaData, slotData));
                                        }
                                    }
                                    else
                                    {
                                        ShowSpriteFrame(frame, atlasMat, displayData, slot, slotData);
                                    }
                                }
                                else if (displayData.type == "mesh")
                                {
                                    TextureFrame textureFrame = new TextureFrame();
                                    if (armatureEditor.isSingleSprite)
                                    {
                                        Sprite sprite = armatureEditor.spriteKV[displayData.textureName];
                                        textureFrame.name             = displayData.textureName;
                                        textureFrame.frameSize        = sprite.rect;
                                        textureFrame.rect             = sprite.rect;
                                        textureFrame.atlasTextureSize = new Vector2(sprite.rect.width, sprite.rect.height);

                                        string path           = AssetDatabase.GetAssetPath(sprite);
                                        string materialFolder = path.Substring(0, path.LastIndexOf("/"));
                                        materialFolder = materialFolder.Substring(0, materialFolder.LastIndexOf("/")) + "/Materials/";
                                        if (!Directory.Exists(materialFolder))
                                        {
                                            Directory.CreateDirectory(materialFolder);
                                        }
                                        string matPath = materialFolder + sprite.name + "_Mat.mat";
                                        atlasMat = AssetDatabase.LoadAssetAtPath <Material>(matPath);
                                        if (!atlasMat)
                                        {
                                            atlasMat = new Material(Shader.Find("DragonBone/DragonBone Simple"));
                                            AssetDatabase.CreateAsset(atlasMat, matPath);
                                        }
                                        atlasMat.mainTexture = AssetDatabase.LoadAssetAtPath <Texture>(path);

                                        mats.Add(atlasMat);
                                        textureFrame.material = atlasMat;
                                        textureFrame.texture  = atlasMat.mainTexture;
                                        tfs.Add(textureFrame);
                                    }
                                    else
                                    {
                                        foreach (TextureFrame st in frame.frames)
                                        {
                                            if (st.name.Equals(displayData.textureName))
                                            {
                                                textureFrame = st;
                                                break;
                                            }
                                        }
                                    }
                                    if (textureFrame.rect.width > 0 && textureFrame.rect.height > 0 && atlasMat && atlasMat.mainTexture)
                                    {
                                        ShowSpriteMesh(textureFrame, atlasMat, displayData, slot, armatureEditor, slotData);
                                        ++meshSpriteCount;
                                    }
                                }
                            }
                            slot.GetComponent <Slot>().displayIndex = slotData.displayIndex;
                        }
                    }
                }
                armature.materials     = mats.ToArray();
                armature.textureFrames = tfs.ToArray();

                foreach (SpriteFrame sf in frameKV.Values)
                {
                    GameObject.DestroyImmediate(sf.gameObject);
                }

                if (armatureEditor.useUnitySprite)
                {
                    if (!armatureEditor.isSingleSprite)
                    {
                        if (metaDatas.Count > 0)
                        {
                            string          textureAtlasPath = AssetDatabase.GetAssetPath(armatureEditor.altasTexture);
                            TextureImporter textureImporter  = AssetImporter.GetAtPath(textureAtlasPath) as TextureImporter;
                            textureImporter.maxTextureSize      = 2048;
                            textureImporter.spritesheet         = metaDatas.ToArray();
                            textureImporter.textureType         = TextureImporterType.Sprite;
                            textureImporter.spriteImportMode    = SpriteImportMode.Multiple;
                            textureImporter.spritePixelsPerUnit = 100;
                            AssetDatabase.ImportAsset(textureAtlasPath, ImportAssetOptions.ForceUpdate);
                            Object[] savedSprites = AssetDatabase.LoadAllAssetsAtPath(textureAtlasPath);
                            foreach (Object obj in savedSprites)
                            {
                                Sprite objSprite = obj as Sprite;
                                if (objSprite)
                                {
                                    len = sprites.Count;
                                    for (int i = 0; i < len; ++i)
                                    {
                                        if (sprites[i].name.Equals(objSprite.name))
                                        {
                                            sprites[i].sprite = objSprite;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (atlasMat != null)
                    {
                        if (meshSpriteCount == 0)
                        {
                            //can delete safely
                            foreach (Material mat in matKV.Values)
                            {
                                if (!armatureEditor.spriteMeshUsedMatKV.ContainsKey(mat))
                                {
                                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(mat));
                                }
                            }
                        }
                        else
                        {
                            foreach (SpriteRenderer sprite in sprites)
                            {
                                sprite.material = atlasMat;
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
        //init
        public void InitShow()
        {
            ShowArmature.AddBones(this);
            ShowArmature.AddSlot(this);
            ShowArmature.ShowBones(this);
            ShowArmature.ShowSlots(this);
            ShowArmature.ShowSkins(this);
            ShowArmature.SetIKs(this);
            AnimFile.CreateAnimFile(this);

            DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>();
            bool canDeleteArmature = false;

            if (armature && (dba.updateMeshs == null || dba.updateMeshs.Length == 0) &&
                (dba.updateFrames == null || dba.updateFrames.Length == 0))
            {
                canDeleteArmature = true;
            }

            Renderer[]        renders = _armature.GetComponentsInChildren <Renderer>();
            List <SpriteMesh> sms     = new List <SpriteMesh>();

            foreach (Renderer r in renders)
            {
                if (!r.enabled)
                {
                    r.enabled = true;
                    r.gameObject.SetActive(false);
                }
                else if (r.GetComponent <SpriteMesh>() != null)
                {
                    for (int i = 0; i < r.transform.childCount; ++i)
                    {
                        r.transform.GetChild(i).gameObject.SetActive(false);
                    }
                    sms.Add(r.GetComponent <SpriteMesh>());
                    canDeleteArmature = false;
                }
                else if (r.GetComponent <SpriteFrame>())
                {
                    //optimize memory
                    SpriteFrame  sf = r.GetComponent <SpriteFrame>();
                    TextureFrame tf = sf.frame;
                    sf.frames = new TextureFrame[] { tf };
                }
            }
            if (canDeleteArmature)
            {
//				Object.DestroyImmediate(dba);//don't destroy
            }
            else
            {
                dba.updateMeshs = sms.ToArray();
            }
            dba.attachments = renders;
            dba.slots       = slots.ToArray();
            dba.zSpace      = zoffset;
            dba.ResetSlotZOrder();

            string path = AssetDatabase.GetAssetPath(animTextAsset);

            path = path.Substring(0, path.LastIndexOf('/')) + "/" + _armature.name + ".prefab";
            GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(path);

            if (!prefab)
            {
                PrefabUtility.CreatePrefab(path, _armature.gameObject, ReplacePrefabOptions.ConnectToPrefab);
            }
            else
            {
                PrefabUtility.ReplacePrefab(_armature.gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);
            }
        }
コード例 #9
0
        //init
        public void InitShow()
        {
            ShowArmature.AddBones(this);
            ShowArmature.AddSlot(this);
            ShowArmature.ShowBones(this);
            ShowArmature.ShowSlots(this);
            ShowArmature.ShowSkins(this);
            ShowArmature.SetIKs(this);
            AnimFile.CreateAnimFile(this);

            DragonBoneArmature dba = _armature.GetComponent <DragonBoneArmature>();

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

            Renderer[] renders = _armature.GetComponentsInChildren <Renderer>(true);
            foreach (Renderer r in renders)
            {
                if (r.GetComponent <SpriteFrame>())
                {
                    //optimize memory
                    SpriteFrame  sf = r.GetComponent <SpriteFrame>();
                    TextureFrame tf = sf.frame;
                    sf.frames = new TextureFrame[] { tf };
                }
            }
            dba.attachments = renders;
            dba.slots       = slots.ToArray();
            dba.bones       = bones.ToArray();
            dba.zSpace      = zoffset;
            dba.ResetSlotZOrder();

            string path = AssetDatabase.GetAssetPath(animTextAsset);

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


            //create pose data
            PoseData poseData = ScriptableObject.CreateInstance <PoseData>();

            poseData.slotDatas = new PoseData.SlotData[slots.Count];
            for (int i = 0; i < slots.Count; ++i)
            {
                poseData.slotDatas[i]              = new PoseData.SlotData();
                poseData.slotDatas[i].color        = slots[i].color;
                poseData.slotDatas[i].displayIndex = slots[i].displayIndex;
                poseData.slotDatas[i].zorder       = slots[i].z;
            }
            poseData.boneDatas = new PoseData.TransformData[bones.Count];
            for (int i = 0; i < bones.Count; ++i)
            {
                poseData.boneDatas[i]          = new PoseData.TransformData();
                poseData.boneDatas[i].x        = bones[i].localPosition.x;
                poseData.boneDatas[i].y        = bones[i].localPosition.y;
                poseData.boneDatas[i].sx       = bones[i].localScale.x;
                poseData.boneDatas[i].sy       = bones[i].localScale.y;
                poseData.boneDatas[i].rotation = bones[i].localEulerAngles.z;
            }
            poseData.displayDatas = new PoseData.DisplayData[dba.attachments.Length];
            for (int i = 0; i < dba.attachments.Length; ++i)
            {
                poseData.displayDatas[i] = new PoseData.DisplayData();
                Renderer render = dba.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 = sm.vertices;
                    }
                    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;
            }
            AssetDatabase.CreateAsset(poseData, path + "_Pose.asset");
            dba.poseData = poseData;


            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);
            }
        }