Example #1
0
    // CSpineData 加载完后,在读取依赖的SkeletonDataAsset和SpriteCollection
    protected void LoadCSpineData(string path, Action <SkeletonDataAsset> dataCallback)
    {
        var loader = CStaticAssetLoader.Load(path, (isOk, obj) =>
        {
            //string resourcePath = args[0] as string;
            //Action<SkeletonDataAsset> externalCallback = args[1] as Action<SkeletonDataAsset>;
            if (isOk)
            {
                CSpineData spineData = obj as CSpineData;

                LoadSpineDataAsset(spineData.DataAssetPath, (SkeletonDataAsset dataAsset) =>
                {
                    var loader2 = CTk2dSpriteCollectionDep.LoadSpriteCollection(spineData.SpriteCollectionPath, (_obj) =>
                    {
                        tk2dSpriteCollectionData colData = _obj as tk2dSpriteCollectionData;
                        Logger.Assert(colData);

                        dataAsset.spriteCollection = colData;

                        dataCallback(dataAsset);
                    });
                    ResourceLoaders.Add(loader2);
                });
            }
            else
            {
                Logger.LogWarning("[CSpineAnimationDep:LoadCSpineData] Not Ok {0}", path);
                dataCallback(null);
            }
        });

        ResourceLoaders.Add(loader);
    }
    // 包含json!,不包含圖集
    static CDepCollectInfo GetBuildSpineData(SkeletonDataAsset data)
    {
        string path = AssetDatabase.GetAssetPath(data);

        // DataAsset
        bool needBuildDataAsset = BuildTools.CheckNeedBuild(path);

        if (needBuildDataAsset)
        {
            BuildTools.MarkBuildVersion(path);
        }

        // Spine的JSON
        string textAssetPath          = AssetDatabase.GetAssetPath(data.skeletonJSON);
        bool   needBuildJsonTextAsset = BuildTools.CheckNeedBuild(textAssetPath);

        if (needBuildJsonTextAsset)
        {
            BuildTools.MarkBuildVersion(textAssetPath);
        }

        //string originPath = path;
        //string tmpPath = "Assets/~TempSkeletonDataAsset.asset";
        //bool copyResult = AssetDatabase.CopyAsset(path, tmpPath);
        //Log.Assert(copyResult);
        //SkeletonDataAsset copyData = AssetDatabase.LoadAssetAtPath(tmpPath, typeof(SkeletonDataAsset)) as SkeletonDataAsset;
        if (data.spriteCollection == null || data.skeletonJSON == null)
        {
            Log.Error("Err Spine Data: {0}, Lack of SpriteCollection or Json", data.name);
            //return "";
        }

        string spriteColPath      = BuildSpriteCollection(data.spriteCollection);
        string spriteColAssetPath = AssetDatabase.GetAssetPath(data.spriteCollection.gameObject);
        bool   needBuildSpriteCol = BuildTools.CheckNeedBuild(spriteColAssetPath);

        if (needBuildSpriteCol)
        {
            BuildTools.MarkBuildVersion(spriteColAssetPath);
        }

        SkeletonDataAsset copyData = GameObject.Instantiate(data) as SkeletonDataAsset;

        copyData.spriteCollection = null; // 挖空图集, 保留Json!


        // SpineData包括了这个SkeletonData!
        var skeletonDataBuildResult = __DoBuildScriptableObject(DepBuildToFolder + "/SkeletonData_" + data.name, copyData, needBuildDataAsset || needBuildJsonTextAsset);  // json文件直接放在SkeletonDataAsset打包! 分离图集

        CSpineData spineData = ScriptableObject.CreateInstance <CSpineData>();

        spineData.SpriteCollectionPath = spriteColPath;
        spineData.DataAssetPath        = skeletonDataBuildResult.Path; // 保留json文件,不挖空 copyData.skeletonJSON

        path = __GetPrefabBuildPath(path);
        // DataAsset或圖集或Json任一重打包了,都要重新打包CSpineData(記錄圖集保存地方和Jsondataasset保存地方)
        var spineDataBuildResult = __DoBuildScriptableObject(DepBuildToFolder + "/SpineData_" + path, spineData, needBuildDataAsset || needBuildSpriteCol || needBuildJsonTextAsset);

        spineDataBuildResult.Child = skeletonDataBuildResult;

        GameObject.DestroyImmediate(copyData);

        return(spineDataBuildResult);
    }