Esempio n. 1
0
    // 读取Json文件
    public static SkeletonDataAsset IngestSpineProject(string spineJsonPath, AtlasAsset atlasAsset = null)
    {
        string jsonContentStr = File.ReadAllText(spineJsonPath);

        string   primaryName = Path.GetFileNameWithoutExtension(spineJsonPath);
        FileInfo fInfo       = new FileInfo(spineJsonPath + ".json");
        string   assetPath   = Path.GetDirectoryName(fInfo.Directory.FullName);

        if (spineJsonPath != null && atlasAsset != null)
        {
            SkeletonDataAsset skelDataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();
            skelDataAsset.atlasAsset = atlasAsset;
            // skelDataAsset.skeletonJSON = spineJsonPath;
            skelDataAsset.jsonFileName    = primaryName;
            skelDataAsset.skeletonJsonStr = jsonContentStr;
            skelDataAsset.fromAnimation   = new string[0];
            skelDataAsset.toAnimation     = new string[0];
            skelDataAsset.duration        = new float[0];
            skelDataAsset.defaultMix      = defaultMix;
            skelDataAsset.scale           = defaultScale;

            return(skelDataAsset);
        }
        else
        {
            Debug.LogError("json 或 atlas 为 null !");
            return(null);
        }
    }
Esempio n. 2
0
    static SkeletonDataAsset IngestSpineProject(TextAsset spineJson, AtlasAsset atlasAsset = null)
    {
        string primaryName = Path.GetFileNameWithoutExtension(spineJson.name);
        string assetPath   = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson));
        string filePath    = assetPath + "/" + primaryName + "_SkeletonData.asset";

        if (spineJson != null && atlasAsset != null)
        {
            SkeletonDataAsset skelDataAsset = (SkeletonDataAsset)AssetDatabase.LoadAssetAtPath(filePath, typeof(SkeletonDataAsset));
            if (skelDataAsset == null)
            {
                skelDataAsset               = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();
                skelDataAsset.atlasAsset    = atlasAsset;
                skelDataAsset.skeletonJSON  = spineJson;
                skelDataAsset.fromAnimation = new string[0];
                skelDataAsset.toAnimation   = new string[0];
                skelDataAsset.duration      = new float[0];
                skelDataAsset.defaultMix    = defaultMix;
                skelDataAsset.scale         = defaultScale;

                AssetDatabase.CreateAsset(skelDataAsset, filePath);
                AssetDatabase.SaveAssets();
            }

            return(skelDataAsset);
        }
        else
        {
            EditorUtility.DisplayDialog("Error!", "Must specify both Spine JSON and Atlas TextAsset", "OK");
            return(null);
        }
    }
Esempio n. 3
0
    public static void DoIt()
    {
        string dirName       = "Assets/Animation";
        string spineFileName = "hounv";
        string textureName   = dirName + "/" + spineFileName + "/" + spineFileName + ".png";
        string atlasFileName = dirName + "/" + spineFileName + "/" + spineFileName + ".atlas.txt";
        string jsonFileName  = dirName + "/" + spineFileName + "/" + spineFileName + ".json.txt";


        string atlasAssetName        = dirName + "/" + spineFileName + "/" + spineFileName + ".asset";
        string skeletonDataAssetName = dirName + "/" + spineFileName + "/" + spineFileName + "skeltonData" + ".asset";

        ///1、 创建材质,并指贴图和shader
        Shader   shader = Shader.Find("Spine/SkeletonGhost");
        Material mat    = new Material(shader);
        Texture  tex    = Resources.LoadAssetAtPath(textureName, typeof(Texture)) as Texture;

        mat.SetTexture("_MainTex", tex);
        AssetDatabase.CreateAsset(mat, dirName + "/" + spineFileName + "/" + spineFileName + ".mat");
        AssetDatabase.SaveAssets();

        ///2、 创建atlas,并指xx
        AtlasAsset m_AtlasAsset = AtlasAsset.CreateInstance <AtlasAsset>();

        AssetDatabase.CreateAsset(m_AtlasAsset, atlasAssetName);
        Selection.activeObject = m_AtlasAsset;

        TextAsset textAsset = Resources.LoadAssetAtPath(atlasFileName, typeof(TextAsset)) as TextAsset;

        m_AtlasAsset.atlasFile    = textAsset;
        m_AtlasAsset.materials    = new Material[1];
        m_AtlasAsset.materials[0] = mat;
        AssetDatabase.SaveAssets();

        ///3、 创建SkeletonDataAsset,并指相关
        SkeletonDataAsset m_skeltonDataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();

        AssetDatabase.CreateAsset(m_skeltonDataAsset, skeletonDataAssetName);
        Selection.activeObject = m_skeltonDataAsset;

        m_skeltonDataAsset.atlasAssets    = new AtlasAsset[1];
        m_skeltonDataAsset.atlasAssets[0] = m_AtlasAsset;
        TextAsset m_jsonAsset = Resources.LoadAssetAtPath(jsonFileName, typeof(TextAsset)) as TextAsset;

        m_skeltonDataAsset.skeletonJSON = m_jsonAsset;
        AssetDatabase.SaveAssets();


        /// 创建场景物件
        GameObject gameObject = new GameObject(spineFileName, typeof(SkeletonAnimation));

        EditorUtility.FocusProjectWindow();
        Selection.activeObject = gameObject;

        SkeletonAnimation m_skelAnim = gameObject.GetComponent <SkeletonAnimation>();

        m_skelAnim.skeletonDataAsset = m_skeltonDataAsset;
        //m_skelAnim.initialSkinName = "normal";
    }
    static void CreateSkeletonDataFromSelection()
    {
        List <TextAsset>         jsonList       = new List <TextAsset>();
        tk2dSpriteCollectionData collectionData = null;

        foreach (Object obj in Selection.objects)
        {
            if (obj is TextAsset)
            {
                TextAsset t = obj as TextAsset;
                if (IsSpineJSON(t))
                {
                    jsonList.Add(t);
                }
            }
            else if (obj is GameObject)
            {
                GameObject go = obj as GameObject;
                var        spriteCollection = go.GetComponent <tk2dSpriteCollection>();
                if (spriteCollection != null)
                {
                    if (spriteCollection.spriteCollection != null)
                    {
                        collectionData = spriteCollection.spriteCollection;
                    }
                }
            }
        }

        if (collectionData == null)
        {
            return;
        }

        foreach (TextAsset t in jsonList)
        {
            string path = Path.GetDirectoryName(AssetDatabase.GetAssetPath(t)) + "/" + t.name + "_SkeletonData.asset";

            SkeletonDataAsset skeletonDataAsset = (SkeletonDataAsset)AssetDatabase.LoadAssetAtPath(path, typeof(SkeletonDataAsset));
            if (skeletonDataAsset == null)
            {
                skeletonDataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();
                AssetDatabase.CreateAsset(skeletonDataAsset, path);
            }

            skeletonDataAsset.skeletonJSON     = t;
            skeletonDataAsset.spriteCollection = collectionData;
            skeletonDataAsset.defaultMix       = 0.2f;
            skeletonDataAsset.fromAnimation    = new string[0];
            skeletonDataAsset.toAnimation      = new string[0];
            skeletonDataAsset.duration         = new float[0];

            EditorUtility.SetDirty(skeletonDataAsset);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }
 public void GetConfig()
 {
     if (_config == null)
     {
         _config = AssetDatabase.LoadAssetAtPath(configPath, typeof(SpineXiimoonConfig)) as SpineXiimoonConfig;
         if (_config == null)
         {
             _config = SkeletonDataAsset.CreateInstance <SpineXiimoonConfig>();
             AssetDatabase.CreateAsset(_config, configPath);
             AssetDatabase.SaveAssets();
         }
     }
 }
Esempio n. 6
0
    public void CreateSpineObject()
    {
        // 1.Spine/Skeletonのmaterialを生成
        Material material = new Material(Shader.Find("Spine/Skeleton"));

        material.mainTexture = texture;

        // 2.AtlasAssetを生成して、1のmaterialを紐づける
        AtlasAsset atlasAsset = AtlasAsset.CreateInstance <AtlasAsset> ();

        atlasAsset.atlasFile     = atlasText;
        atlasAsset.materials     = new Material[1];
        atlasAsset.materials [0] = material;

        // 3.SkeletonDataAssetを生成して、初期データを投入する
        SkeletonDataAsset dataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset> ();

        dataAsset.atlasAssets     = new AtlasAsset[1];
        dataAsset.atlasAssets [0] = atlasAsset;
        dataAsset.skeletonJSON    = jsonText;
        dataAsset.fromAnimation   = new string[0];
        dataAsset.toAnimation     = new string[0];
        dataAsset.duration        = new float[0];
        dataAsset.defaultMix      = 0.2f;
        dataAsset.scale           = 1.0f;

        // 4.実際にUnityに配置するGameObjectを生成して、SkeletonAnimationをadd
        GameObject        obj          = new GameObject("SpineObject");
        SkeletonAnimation anim         = obj.AddComponent <SkeletonAnimation> ();
        MeshRenderer      meshRenderer = obj.GetComponent <MeshRenderer>();

        meshRenderer.sortingLayerName = "spine";
        meshRenderer.sortingOrder     = 0;
        // 5.SkeletonAnimationにSkeletonDataAssetを紐付け、skinName、reset(),animationNameを設定する。
        anim.skeletonDataAsset = dataAsset;

        // Reset()前に呼び出す必要あり。後に呼ぶとskinデータが反映されない
        anim.initialSkinName = "goblin";

        // Reset()時にDataAssetからAnimationデータを読みだして格納している
        anim.Reset();

        // ループの設定はAnimation指定前じゃないと反映されない
        anim.loop          = true;
        anim.AnimationName = "walk";

        // アニメ終了イベントをセット
        anim.state.Complete += OnCompleteSpineAnim;

        obj.transform.SetParent(this.gameObject.transform);
    }
Esempio n. 7
0
    public static SkeletonAnimation CreateSkeAnimFromZip(string fullZipPath)
    {
        // ======================
        // 解析zip
        // ======================
        FileInfo      zipFInfo   = new FileInfo(fullZipPath);
        DirectoryInfo zipDirInfo = zipFInfo.Directory;
        string        spineName  = Path.GetFileNameWithoutExtension(fullZipPath);

        ZipFile  zf         = new ZipFile(fullZipPath);
        ZipEntry jsonEntry  = zf.GetEntry(spineName + ".json");
        ZipEntry atlasEntry = zf.GetEntry(spineName + ".atlas");

        Stream jsonStream  = zf.GetInputStream(jsonEntry);
        Stream atlasStream = zf.GetInputStream(atlasEntry);

        String jsonContent  = "";
        string atlasContent = "";

        using (StreamReader reader = new StreamReader(jsonStream))
        {
            jsonContent = reader.ReadToEnd();
        }

        using (StreamReader reader = new StreamReader(atlasStream))
        {
            atlasContent = reader.ReadToEnd();
        }

        // ===================
        // Atlas 文件解析
        // ===================
        AtlasAsset atlasAsset = AtlasAsset.CreateInstance <AtlasAsset>();

        atlasAsset.atlasFileContent = atlasContent;

        string[]      atlasLines = atlasContent.Split('\n');
        List <string> pageFiles  = new List <string>();

        for (int i = 0; i < atlasLines.Length - 1; i++)
        {
            if (atlasLines[i].Length == 0)
            {
                pageFiles.Add(atlasLines[i + 1]);
            }
        }

        atlasAsset.materials = new Material[pageFiles.Count];

        for (int i = 0; i < pageFiles.Count; i++)
        {
            string textureKey = pageFiles[i];
            string nameOnly   = Path.GetFileNameWithoutExtension(textureKey);
            Debug.Log("贴图Key " + textureKey + "   " + nameOnly);
            // 正确的textureKey应该是一个裸文件路径
            //if (textureKey.StartsWith("/"))
            //    textureKey = "." + textureKey;

            Material mat = new Material(Shader.Find("Spine/Skeleton"));
            mat.name = nameOnly;

            string fullPngPath = Path.Combine(zipDirInfo.FullName, textureKey.Replace(".png", ".jpg.mask"));

            if (!File.Exists(fullPngPath))
            {
                Debug.LogError("找不到引用的png: " + textureKey);
                return(null);
            }

            string fullJpgPath = Path.Combine(zipDirInfo.FullName, textureKey.Replace(".png", ".jpg"));

            bool isSeperated = false;
            if (File.Exists(fullJpgPath))
            {
                isSeperated = true;
            }

            Texture2D tex2D = null;
            if (isSeperated)
            {
                Bitmap colorImg = new Bitmap(fullJpgPath);
                Bitmap alphaImg = new Bitmap(fullPngPath);

                tex2D = new Texture2D(colorImg.Width, colorImg.Height, TextureFormat.ARGB32, false);

                for (int row = 0; row < colorImg.Height; row++)
                {
                    for (int col = 0; col < colorImg.Width; col++)
                    {
                        System.Drawing.Color srcColor = colorImg.GetPixel(col, colorImg.Height - row - 1);
                        float alpha = alphaImg.GetPixel(col, row).A;
                        tex2D.SetPixel(col, row, new UnityEngine.Color(srcColor.R, srcColor.G, srcColor.B, alpha));
                    }
                }
            }
            else
            {
                Bitmap       bitmap    = new Bitmap(fullPngPath);
                MemoryStream bmpStream = new MemoryStream();
                bitmap.Save(bmpStream, System.Drawing.Imaging.ImageFormat.Png);
                bmpStream.Seek(0, SeekOrigin.Begin);

                tex2D = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false);
                tex2D.LoadImage(bmpStream.ToArray());
            }

            tex2D.filterMode = FilterMode.Bilinear;
            tex2D.wrapMode   = TextureWrapMode.Clamp;
            tex2D.Apply();

            // 调试模式 - 将atlas图片存为文件
            if (ToolManager.Instance.DebugMode)
            {
                File.WriteAllBytes(textureKey + ".png", tex2D.EncodeToPNG());
            }

            mat.mainTexture         = tex2D;
            mat.mainTexture.name    = nameOnly;
            atlasAsset.materials[i] = mat;
        }

        // ===================
        // Json 文件解析
        // ===================
        SkeletonDataAsset skelDataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();

        skelDataAsset.atlasAsset      = atlasAsset;
        skelDataAsset.jsonFileName    = spineName;
        skelDataAsset.skeletonJsonStr = jsonContent;
        skelDataAsset.fromAnimation   = new string[0];
        skelDataAsset.toAnimation     = new string[0];
        skelDataAsset.duration        = new float[0];
        skelDataAsset.defaultMix      = defaultMix;
        skelDataAsset.scale           = defaultScale;

        // ===================
        // 实例化Spine对象
        // ===================
        return(SpineFileReader.SpawnAnimatedSkeleton(skelDataAsset));
    }
Esempio n. 8
0
    static public void BatchCreateSpineData()
    {
        //string dirName = Application.dataPath + "/Arts/Spine/";
        string filedirName = "Assets/Arts/Spine/";

        string spineFileName = "";

        //选择多个对象批量生成
        UnityEngine.Object[] objects = Selection.objects;
        for (int iter = 0; iter < objects.Length; ++iter)
        {
            spineFileName = objects[iter].name;
            string path          = filedirName + spineFileName + "/" + spineFileName;
            string textureName   = path + ".png";
            string jsonFileName  = path + ".json.txt";
            string atlasFileName = path + ".atlas.txt";

            Material mat;
            ///1、 创建材质,并指贴图和shader和设置图片格式
            {
                Shader shader = Shader.Find("Spine/FadeInOut"); //默认的shader,这个可以修改

                mat = new Material(shader);
                Texture         tex             = AssetDatabase.LoadAssetAtPath(textureName, typeof(Texture)) as Texture;
                TextureImporter textureImporter = AssetImporter.GetAtPath(textureName) as TextureImporter;
                textureImporter.textureType   = TextureImporterType.Advanced;
                textureImporter.mipmapEnabled = false;
                textureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;

                mat.SetTexture("_MainTex", tex);

                AssetDatabase.CreateAsset(mat, path + ".mat");
                AssetDatabase.SaveAssets();
            }

            ///2、 创建atlas,并指xx
            AtlasAsset m_AtlasAsset = AtlasAsset.CreateInstance <AtlasAsset>();
            AssetDatabase.CreateAsset(m_AtlasAsset, path + ".asset");
            Selection.activeObject = m_AtlasAsset;

            TextAsset textAsset = AssetDatabase.LoadAssetAtPath(atlasFileName, typeof(TextAsset)) as TextAsset;
            m_AtlasAsset.atlasFile    = textAsset;
            m_AtlasAsset.materials    = new Material[1];
            m_AtlasAsset.materials[0] = mat;
            AssetDatabase.SaveAssets();


            ///3、 创建SkeletonDataAsset,并指相关
            SkeletonDataAsset m_skeltonDataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();
            AssetDatabase.CreateAsset(m_skeltonDataAsset, path + "_SkeletonData.asset");
            Selection.activeObject = m_skeltonDataAsset;

            m_skeltonDataAsset.atlasAsset = m_AtlasAsset;
            TextAsset m_jsonAsset = AssetDatabase.LoadAssetAtPath(jsonFileName, typeof(TextAsset)) as TextAsset;
            m_skeltonDataAsset.skeletonJSON = m_jsonAsset;
            m_skeltonDataAsset.scale        = 0.01f;
            AssetDatabase.SaveAssets();


            /// 创建场景物件
            GameObject gameObject = new GameObject(spineFileName, typeof(SkeletonAnimation));
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = gameObject;

            SkeletonAnimation m_skelAnim = gameObject.GetComponent <SkeletonAnimation>();
            m_skelAnim.skeletonDataAsset = m_skeltonDataAsset;
        }
    }
Esempio n. 9
0
    public void CreateSpineObject()
    {
        Material material = new Material(Resources.Load("spine/Shaders/Spine-Skeleton") as Shader);

        material.mainTexture = texture;

        Spine.Unity.AtlasAsset atlasAsset = Spine.Unity.AtlasAsset.CreateInstance <Spine.Unity.AtlasAsset>();
        atlasAsset.atlasFile    = atlasText;
        atlasAsset.materials    = new Material[1];
        atlasAsset.materials[0] = material;

        SkeletonDataAsset dataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();

        dataAsset.atlasAssets    = new Spine.Unity.AtlasAsset[1];
        dataAsset.atlasAssets[0] = atlasAsset;
        dataAsset.skeletonJSON   = jsonText;
        dataAsset.fromAnimation  = new string[0];
        dataAsset.toAnimation    = new string[0];
        dataAsset.duration       = new float[0];
        dataAsset.defaultMix     = 0.2f;
        dataAsset.scale          = 0.01f;

        GameObject        obj  = gameObject;
        SkeletonAnimation anim = obj.GetComponent <SkeletonAnimation>();

        if (null == anim)
        {
            anim = obj.AddComponent <SkeletonAnimation>();
        }

        meshRenderer = obj.GetComponent <MeshRenderer>();

        if (null == meshRenderer)
        {
            meshRenderer = obj.AddComponent <MeshRenderer>();
        }

        // meshRenderer.sortingLayerName = "spine";
        meshRenderer.sortingOrder  = MeshSortingOrder;
        anim.skeletonDataAsset     = dataAsset;
        oldMesRendererSortingOrder = MeshSortingOrder;

        anim.initialSkinName = "default";

        //anim.Reset();
        anim.loop          = IsLoop;
        anim.AnimationName = DefaultAnimationName;

        //anim.state.Complete += OnCompleteSpineAnim;

        //obj.transform.SetParent(this.gameObject.transform);
        //obj.transform.localPosition = Vector3.zero;
        obj.transform.localScale = SpineScale;

        List <Transform> childrens = new List <Transform>();

        childrens.AddRange(obj.transform.GetComponentsInChildren <Transform>());

        //for (int i = 0; i < childrens.Count; ++i){

        //    childrens[i].gameObject.layer = LayerMask.NameToLayer("UI");
        //}

        anim.Awake();

        //gameObject.SetActive(true);

        IsLoaded = true;
        if (anim.state != null)
        {
            anim.state.Complete += OnAni_Complete;
        }
    }
Esempio n. 10
0
    public static SkeletonAnimation CreateSkeAnimFromZip(string fullZipPath)
    {
        // ======================
        // 解析zip
        // ======================
        FileInfo      zipFInfo   = new FileInfo(fullZipPath);
        DirectoryInfo zipDirInfo = zipFInfo.Directory;
        string        spineName  = Path.GetFileNameWithoutExtension(fullZipPath);

        ZipFile  zf         = new ZipFile(fullZipPath);
        ZipEntry jsonEntry  = zf.GetEntry(spineName + ".json");
        ZipEntry atlasEntry = zf.GetEntry(spineName + ".atlas");

        Stream jsonStream  = zf.GetInputStream(jsonEntry);
        Stream atlasStream = zf.GetInputStream(atlasEntry);

        String jsonContent  = "";
        string atlasContent = "";

        using (StreamReader reader = new StreamReader(jsonStream))
        {
            jsonContent = reader.ReadToEnd();
        }

        using (StreamReader reader = new StreamReader(atlasStream))
        {
            atlasContent = reader.ReadToEnd();
        }

        // ===================
        // Atlas 文件解析
        // ===================
        AtlasAsset atlasAsset = AtlasAsset.CreateInstance <AtlasAsset>();

        atlasAsset.atlasFileContent = atlasContent;

        string[]      atlasLines = atlasContent.Split('\n');
        List <string> pageFiles  = new List <string>();

        for (int i = 0; i < atlasLines.Length - 1; i++)
        {
            if (atlasLines[i].Length == 0)
            {
                pageFiles.Add(atlasLines[i + 1]);
            }
        }

        atlasAsset.materials = new Material[pageFiles.Count];

        for (int i = 0; i < pageFiles.Count; i++)
        {
            string textureKey = pageFiles[i];
            string nameOnly   = Path.GetFileNameWithoutExtension(textureKey);
            Debug.Log("贴图Key " + textureKey + "   " + nameOnly);
            // 正确的textureKey应该是一个裸文件路径
            //if (textureKey.StartsWith("/"))
            //    textureKey = "." + textureKey;

            Material mat = new Material(Shader.Find("Spine/Skeleton"));
            mat.name = nameOnly;

            string fullPngPath = Path.Combine(zipDirInfo.FullName, textureKey.Replace(".png", ".jpg.mask"));

            if (!File.Exists(fullPngPath))
            {
                Debug.LogError(String.Format("找不到引用的png: {0} {1}", textureKey, fullPngPath));
                return(null);
            }

            string fullJpgPath = Path.Combine(zipDirInfo.FullName, textureKey.Replace(".png", ".jpg"));

            bool isSeperated = false;
            if (File.Exists(fullJpgPath))
            {
                isSeperated = true;
            }

            Texture2D tex2D = null;

            //int alphaCnt = 0;
            //int rCnt = 0;
            //int gCnt = 0;
            //int bCnt = 0;
            // WWW www = new WWW();

            if (isSeperated)
            {
                Bitmap colorImg = new Bitmap(fullJpgPath);
                Bitmap alphaImg = new Bitmap(fullPngPath);

                //int imageWidth = colorImg.Width;
                //int imageHeight = colorImg.Height;

                //Bitmap combineImg = new Bitmap(imageWidth, imageHeight, colorImg.PixelFormat);

                //Rectangle rect = new Rectangle(0, 0, imageWidth, imageHeight);

                //BitmapData colorData = colorImg.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                //BitmapData alphaData = alphaImg.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                //BitmapData combineData = combineImg.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

                //Debug.Log(colorData.Stride + " / " + imageWidth);
                //int byteCnt = Math.Abs(colorData.Stride) * imageHeight;
                //byte[] colorBytes = new byte[byteCnt];
                //byte[] alphaBytes = new byte[byteCnt];

                //System.Runtime.InteropServices.Marshal.Copy(colorData.Scan0, colorBytes, 0, byteCnt);
                //System.Runtime.InteropServices.Marshal.Copy(alphaData.Scan0, alphaBytes, 0, byteCnt);

                //for (int counter = 0; counter < colorBytes.Length; counter += 4)
                //{
                //    colorBytes[counter+3] = 0;
                //    if (counter < 300)
                //        Debug.Log(alphaBytes[counter]);
                //}

                //System.Runtime.InteropServices.Marshal.Copy(colorBytes, 0, combineData.Scan0, byteCnt);

                //colorImg.UnlockBits(colorData);
                //alphaImg.UnlockBits(alphaData);
                //combineImg.UnlockBits(combineData);

                tex2D = new Texture2D(colorImg.Width, colorImg.Height, TextureFormat.ARGB32, false);

                System.Drawing.Color srcColor;
                System.Drawing.Color alpColor;
                int alpha;
                UnityEngine.Color finalColor;

                // 最大瓶颈在这个 for 循环
                for (int row = 0; row < colorImg.Height; row++)
                {
                    for (int col = 0; col < colorImg.Width; col++)
                    {
                        srcColor = colorImg.GetPixel(col, colorImg.Height - row - 1);
                        alpColor = alphaImg.GetPixel(col, colorImg.Height - row - 1);
                        alpha    = alpColor.R;

                        // System.Drawing.Color color = combineImg.GetPixel(col, colorImg.Height - row - 1);

                        // NOTE Bitmap是0-255,Texture是0-1
                        finalColor.r = srcColor.R / 255f;
                        finalColor.g = srcColor.G / 255f;
                        finalColor.b = srcColor.B / 255f;
                        finalColor.a = alpha / 255f;
                        tex2D.SetPixel(col, row, finalColor);

                        // tex2D.SetPixel(col, row, new UnityEngine.Color(color.R/255f, color.G/255f, color.B/255f, color.A/255f));
                    }
                }
            }
            else
            {
                Bitmap       bitmap    = new Bitmap(fullPngPath);
                MemoryStream bmpStream = new MemoryStream();
                bitmap.Save(bmpStream, System.Drawing.Imaging.ImageFormat.Png);
                bmpStream.Seek(0, SeekOrigin.Begin);

                tex2D = new Texture2D(bitmap.Width, bitmap.Height, TextureFormat.ARGB32, false);
                tex2D.LoadImage(bmpStream.ToArray());
            }

            tex2D.filterMode = FilterMode.Bilinear;
            tex2D.wrapMode   = TextureWrapMode.Clamp;
            tex2D.Apply();

            // 调试模式 - 将atlas图片存为文件
            if (ToolManager.Instance.DebugMode)
            {
                File.WriteAllBytes(textureKey + ".png", tex2D.EncodeToPNG());
            }

            mat.mainTexture         = tex2D;
            mat.mainTexture.name    = nameOnly;
            atlasAsset.materials[i] = mat;
        }

        // ===================
        // Json 文件解析
        // ===================
        SkeletonDataAsset skelDataAsset = SkeletonDataAsset.CreateInstance <SkeletonDataAsset>();

        skelDataAsset.atlasAsset      = atlasAsset;
        skelDataAsset.jsonFileName    = spineName;
        skelDataAsset.skeletonJsonStr = jsonContent;
        skelDataAsset.fromAnimation   = new string[0];
        skelDataAsset.toAnimation     = new string[0];
        skelDataAsset.duration        = new float[0];
        skelDataAsset.defaultMix      = defaultMix;
        skelDataAsset.scale           = defaultScale;

        // ===================
        // 实例化Spine对象
        // ===================
        return(SpineFileReader.SpawnAnimatedSkeleton(skelDataAsset));
    }