Пример #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>();

            if (dba && (dba.updateMeshs == null || dba.updateMeshs.Length == 0) &&
                (dba.updateFrames == null || dba.updateFrames.Length == 0))
            {
                Object.DestroyImmediate(dba);
            }

            Renderer[] renders = _armature.GetComponentsInChildren <Renderer>();
            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);
                    }
                }
                else if (r.GetComponent <SpriteFrame>())
                {
                    //optimize memory
                    SpriteFrame sf = r.GetComponent <SpriteFrame>();
                    SpriteFrame.TextureFrame tf = sf.frame;
                    sf.frames = new SpriteFrame.TextureFrame[] { tf };
                }
            }
            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
        public void ParseAtlasText()
        {
            if (atlasText != null && atlasMat != null && atlasMat.mainTexture != null)
            {
                m_textureSize = new Vector2(atlasMat.mainTexture.width, atlasMat.mainTexture.height);

                SimpleJSON.JSONClass obj = SimpleJSON.JSON.Parse(atlasText.text).AsObject;
                SimpleJSON.JSONArray arr = obj["SubTexture"].AsArray;
                frames = new SpriteFrame.TextureFrame[arr.Count];
                for (int i = 0; i < arr.Count; ++i)
                {
                    SimpleJSON.JSONClass     frameObj = arr[i].AsObject;
                    SpriteFrame.TextureFrame frame    = new SpriteFrame.TextureFrame();
                    frame.name = frameObj["name"];
                    frame.name = frame.name.Replace('/', '_');
                    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"))
                    {
                        frame.frameSize.width = frameObj["frameX"].AsFloat * textureScale;
                    }
                    if (frameObj.ContainKey("frameY"))
                    {
                        frame.frameSize.width = frameObj["frameY"].AsFloat * textureScale;
                    }
                    if (frameObj.ContainKey("frameWidth"))
                    {
                        frame.frameSize.width = frameObj["frameWidth"].AsFloat * textureScale;
                    }
                    if (frameObj.ContainKey("frameHeight"))
                    {
                        frame.frameSize.width = frameObj["frameHeight"].AsFloat * textureScale;
                    }
                    frame.rect      = rect;
                    frameSize       = new Rect(frameSize.x * 0.01f, frameSize.y * 0.01f, frameSize.width * 0.01f, frameSize.height * 0.01f);
                    frame.frameSize = frameSize;
                    frames[i]       = frame;
                }
            }
        }