コード例 #1
0
    // 包含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);
    }
コード例 #2
0
    // Prefab build, 单次build缓存
    public static string BuildSpriteCollection(tk2dSpriteCollectionData data)
    {
        if (data == null)
        {
            Log.Error("[BuildSpriteColleccion]Null SpriteCol Data!!!");
            return("");
        }
        GameObject spriteColPrefab = PrefabUtility.FindPrefabRoot(data.gameObject) as GameObject;

        Log.Assert(spriteColPrefab);

        string path = AssetDatabase.GetAssetPath(spriteColPrefab);  // prefab只用来获取路径,不打包不挖空

        if (string.IsNullOrEmpty(path))
        {
            Log.Info("Null Sprite Collection {0}", path);
            return("");   // !!! SpriteCollection可能动态生成的,不打包它
        }
        bool needBuild = BuildTools.CheckNeedBuild(path);

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

        path = __GetPrefabBuildPath(path);

        GameObject copySpriteColObj            = GameObject.Instantiate(spriteColPrefab) as GameObject;
        tk2dSpriteCollectionData spriteColData = copySpriteColObj.GetComponent <tk2dSpriteCollectionData>();

        foreach (Material mat in spriteColData.materials) // many materials
        {
            string matPath = BuildDepMaterial(mat, GameDef.PictureScale);
            if (!string.IsNullOrEmpty(matPath))  // 材质可能动态创建的,无需打包
            //CResourceDependencies.Create(spriteColData, CResourceDependencyType.SPRITE_COLLECTION, matPath);
            {
                KAssetDep.Create <CTk2dSpriteCollectionDep>(spriteColData, matPath);
            }
        }

        spriteColData.materials = new Material[0]; // 挖空spriteCollections
        spriteColData.textures  = new Texture[0];
        foreach (var def in spriteColData.spriteDefinitions)
        {
            def.material = null;
            // 进行缩放!
            //if (def.positions != null)
            //{
            //    // position!  size!
            //    for (var ip = 0; ip < def.positions.Length; ip++)
            //    {
            //        def.positions[ip] = def.positions[ip] / GameDef.PictureScale;
            //    }
            //    for (var ip = 0; ip < def.untrimmedBoundsData.Length; ip++)
            //    {
            //        def.untrimmedBoundsData[ip] = def.untrimmedBoundsData[ip] / GameDef.PictureScale;
            //    }
            //    for (var ip = 0; ip < def.boundsData.Length; ip++)
            //    {
            //        def.boundsData[ip] = def.boundsData[ip] / GameDef.PictureScale;
            //    }
            //}
        }

        var result = DoBuildAssetBundle(DepBuildToFolder + "/Col_" + path, copySpriteColObj, needBuild);  // Build主对象, 被挖空Material了的

        GameObject.DestroyImmediate(copySpriteColObj);

        return(result.Path);
    }