Ejemplo n.º 1
0
    /// <summary>
    /// 自动构建ab
    /// </summary>
    /// <param name="assets"></param>
    /// <param name="outPath"></param>
    /// <param name="abName"></param>
    /// <param name="bbo"></param>
    static public void BuildABs(string[] assets, string outPath, string abName, BuildAssetBundleOptions bbo)
    {
        AssetBundleBuild[] bab = new AssetBundleBuild[1];
        bab[0].assetBundleName = abName;//打包的资源包名称 随便命名
        bab[0].assetNames      = assets;
        if (string.IsNullOrEmpty(outPath))
        {
            outPath = GetOutPutPath();
        }

        string tmpPath     = BuildScript.GetAssetTmpPath();
        string tmpFileName = Path.Combine(tmpPath, abName);

        BuildPipeline.BuildAssetBundles(tmpPath, bab, bbo, target);

        string   targetFileName = Path.Combine(outPath, abName);
        FileInfo tInfo          = new FileInfo(targetFileName);

        if (tInfo.Exists)
        {
            tInfo.Delete();
        }
        FileInfo fino = new FileInfo(tmpFileName);

        fino.CopyTo(targetFileName);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates the streaming crc list.
    /// </summary>
    /// <param name="sb">Sb.</param>
    public static uint CreateStreamingCrcList(StringBuilder sb, string outPath = null)
    {
        var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
        string tmpPath       = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath);

        ExportResources.CheckDirectory(tmpPath);
        string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".txt";

        EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f);

        string outTmpPath = Path.Combine(tmpPath, crc32filename + ".txt");

        using (StreamWriter sr = new StreamWriter(outTmpPath, false))
        {
            sr.Write(sb.ToString());
        }
        //
        //打包到streaming path
        AssetDatabase.Refresh();
        string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME);

        Debug.Log("write to path=" + outPath);
        Debug.Log(sb.ToString());
        //读取crc
        string abPath = string.Empty;

        if (string.IsNullOrEmpty(outPath))
        {
            abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename);
        }
        else
        {
            abPath = Path.Combine(outPath, crc32outfilename);
        }

        BuildScript.BuildABs(new string[] { assetPath }, outPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle);

        CrcCheck.Clear();

        uint fileCrc = CrcCheck.GetLocalFileCrc(abPath);

        EditorUtility.ClearProgressBar();
        Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath);
        if (!string.IsNullOrEmpty(outPath))
        {
            string   newName = Path.Combine(outPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString()));
            FileInfo finfo   = new FileInfo(abPath);
            finfo.MoveTo(newName);
            Debug.Log(" change name to " + newName);
        }
        return(fileCrc);
    }