コード例 #1
0
    private static void EndAsset()
    {
        if (!Directory.Exists(_exportPath))
        {
            Directory.CreateDirectory(_exportPath);
        }

        AssetBundleManifest abm = BuildPipeline.BuildAssetBundles(_exportPath, _abbList.ToArray(),
                                                                  BuildAssetBundleOptions.ChunkBasedCompression | BuildAssetBundleOptions.StrictMode |
                                                                  BuildAssetBundleOptions.DeterministicAssetBundle,
                                                                  buildTarget);

        if (abm != null)
        {
            string[] abs = abm.GetAllAssetBundles();
            for (int i = 0; i < abs.Length; i++)
            {
                RGLog.Debug("AB: " + abs[i]);
            }
        }
    }
コード例 #2
0
    public static void BuildDeveloper()
    {
        var filesPath = Path.Combine(Application.streamingAssetsPath, "files.txt");
        var fileData  = File.ReadAllText(filesPath);
        var vFiles    = ReadFileInfo(fileData);

        var outPathFix = Util.DataPath;

        RGLog.Debug("outPath ->" + outPathFix);
        if (Directory.Exists(outPathFix))
        {
            Directory.Delete(outPathFix, true);
        }

        // copy
        for (int i = 0; i < vFiles.Length; i++)
        {
            var vfData     = vFiles[i];
            var targetPath = Path.Combine(Application.streamingAssetsPath, vfData.Path).Replace("\\", "/");
            var outPath    = Path.Combine(outPathFix, vfData.Path).Replace("\\", "/");

            var path = Path.GetDirectoryName(outPath);
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            RGLog.Debug("outPath 2 ->" + outPathFix);

            File.Copy(targetPath, outPath);
        }

        var outFilesPath = Path.Combine(outPathFix, "files.txt").Replace("\\", "/");

        File.Copy(filesPath, outFilesPath);

        RGLog.Debug("构建开发使用资源");
    }
コード例 #3
0
    // 获得AssetBundle资源包名
    public static string GetPackageName(string path)
    {
        string[] model = path.ToLower().Split(RGResource.PATH_SEPARATOR);

        // 包路径
        string packageUrl = "";

        for (int i = 0; i < model.Length; i++)
        {
            RGLog.Debug(model[i]);
        }
        if (model.Length > 0)
        {
            if (model[0].Equals("ui"))
            {
                // ui
                packageUrl = "ui/" + model[1];
            }

            return(packageUrl.ToLower());
        }
        RGLog.DebugError(" GetPackagePath Error! Path is Empty");
        return(string.Empty);
    }
コード例 #4
0
    public static void BuileFileIndex()
    {
        string buildVersion = "0.0.1";

        List <string> _files = new List <string>();

        string resPath = _exportPath;

        if (!Directory.Exists(resPath))
        {
            Directory.CreateDirectory(resPath);
        }

        string newFilePath = string.Format("{0}{1}", resPath, "/files.txt");

        if (File.Exists(newFilePath))
        {
            File.Delete(newFilePath);
        }

        string[] allFiles = Directory.GetFiles(resPath, "*.*", SearchOption.AllDirectories);
        _files.AddRange(allFiles);

        var fs = new FileStream(newFilePath, FileMode.CreateNew);
        var sw = new StreamWriter(fs);

        for (int i = 0; i < _files.Count; i++)
        {
            string file = _files[i];
            if (file.EndsWith(".DS_Store"))
            {
                continue;
            }
            if (file.EndsWith("StreamingAssets"))
            {
                continue;
            }

            string ext = Path.GetExtension(file);
            if (ext.EndsWith(".meta"))
            {
                continue;
            }
            if (ext.EndsWith(".txt"))
            {
                continue;
            }
            if (ext.EndsWith(".manifest"))
            {
                continue;
            }
            if (ext.EndsWith(".mp4"))
            {
                continue;
            }
            if (ext.EndsWith(".zip"))
            {
                continue;
            }

            var verfile = new VersionFile();
            verfile.Path = file.Replace(resPath + Path.DirectorySeparatorChar, string.Empty)
                           .Replace(Path.DirectorySeparatorChar, '/');
            verfile.Hash    = Util.md5file(file);
            verfile.Version = buildVersion;
            FileInfo fileInfo = new FileInfo(file);
            verfile.Size = fileInfo.Length;
            sw.WriteLine(verfile);
        }
        sw.Close();
        fs.Close();
        sw.Dispose();
        fs.Dispose();
        RGLog.Debug(" Build File Index ");
    }
コード例 #5
0
    private void OnGUI()
    {
        EditorGUILayout.BeginVertical();
        fontStyle.fontSize         = 15;
        fontStyle.normal.textColor = Color.white;
        GUILayout.Label("正式资源操作", fontStyle);

        // ******************** 此处开始为热更操作 *********************
        GUILayout.Space(20);
        fontStyle.fontSize         = 15;
        fontStyle.normal.textColor = Color.white;
        GUILayout.Label("热更资源操作", fontStyle);
        GUILayout.Space(10);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("清理资源备选名单"))
        {
            RGLog.Debug(" 清理资源备选名单 ");
            GenerateHotAlternativeScriptable();
            ClearHotAlternativeScriptable();
        }
        if (GUILayout.Button("生成资源备选名单"))
        {
            RGLog.Debug(" 生成资源备选名单 ");

            GenerateHotObject();
        }
        GUILayout.EndHorizontal();

        if (hotObject != null)
        {
            if (hotObject.DataList.Count > 0)
            {
                if (GUILayout.Button("build hot bundle"))
                {
                    BuildABTools.BuildHotAll(hotObject.DataList);
                }

                GUILayout.Space(10);

                GUILayout.Label("热更资源名单[" + hotObject.DataList.Count + "]");

                EditorGUILayout.BeginScrollView(Vector2.zero, GUILayout.Height(hotObject.DataList.Count * 20));

                for (int i = 0; i < hotObject.DataList.Count; i++)
                {
                    if (hotObject.DataList[i].selected)
                    {
                        EditorGUILayout.LabelField(hotObject.DataList[i].package);
                    }
                }

                EditorGUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Space(10);
                fontStyle.fontSize         = 12;
                fontStyle.normal.textColor = Color.red;
                GUILayout.Label("备注:\n1.请在资源备选名单中选择要热更的资源\n2.然后再执行'生成热更资源名单' ", fontStyle);
            }
        }
        else
        {
            GenerateHotObject();
        }
        EditorGUILayout.EndVertical();
    }
コード例 #6
0
    public static void BuildHotPackage(List <HotObject> hotList)
    {
        // 把hot 转成字典 用于后面查询
        var hotDic = new Dictionary <string, bool>();

        for (int i = 0; i < hotList.Count; i++)
        {
            hotDic.Add(hotList[i].package, true);
        }

        // 版本路径
        string versionPath = GetVersionBundlePath();

        // hot 路径
        var hotPath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, "hot"));
        // hot vesion
        var hotVersionPath = Replace(string.Format("{0}{1}{2}", hotPath, Path.DirectorySeparatorChar, VersionInfo.BundleVersion));
        // hot file
        var hotFilePath = Replace(string.Format("{0}{1}{2}", hotPath, Path.DirectorySeparatorChar, "files.txt"));

        // res 路径
        var resPath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, "bundle"));
        // res version
        var resVersionPath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, VersionInfo.BundleVersion));
        // res file
        var resFilePath = Replace(string.Format("{0}{1}{2}", versionPath, Path.DirectorySeparatorChar, "files.txt"));

        // 线上file.txt路径
        var liveFilePath = "E:/work2/package/android/file.txt";

        // 清理目录
        ClearDirectory(hotPath);

        // hot new files context dic
        var hotNewFilesContextDic = new Dictionary <string, VersionFile>();
        // hot files context list
        var hotFilesPathContextList = new List <VersionFile>();

        // res files.txt 内容
        var resFiles = ReadFileInfo(File.ReadAllText(resFilePath));

        for (int i = 0; i < resFilePath.Length; i++)
        {
            if (hotDic.ContainsKey(resFiles[i].Path))
            {
                hotNewFilesContextDic.Add(resFiles[i].Path, resFiles[i]);
            }
        }

        // live files.txt 内容
        var liveFiles = ReadFileInfo(File.ReadAllText(liveFilePath));

        for (int i = 0; i < liveFilePath.Length; i++)
        {
            if (hotDic.ContainsKey(resFiles[i].Path))
            {
                hotFilesPathContextList.Add(hotNewFilesContextDic[resFiles[i].Path]);
                RGLog.Debug("hot file -> " + resFiles[i]);
            }
            else
            {
                hotFilesPathContextList.Add(liveFiles[i]);
            }
        }

        // hot files 文件写入
        var hotFs = new FileStream(hotFilePath, FileMode.CreateNew);
        var hotSw = new StreamWriter(hotFs);

        for (int i = 0; i < hotFilesPathContextList.Count; i++)
        {
            VersionFile verfile = hotFilesPathContextList[i];
            hotSw.WriteLine(verfile);
        }
        hotSw.Close();
        hotFs.Close();

        // copy 需要热更的文件到hot目录下
        for (int i = 0; i < hotFilesPathContextList.Count; i++)
        {
            if (hotDic.ContainsKey(hotFilesPathContextList[i].Path))
            {
                var rf = Replace(string.Format("{0}{1}{2}", resVersionPath, Path.DirectorySeparatorChar, hotFilesPathContextList[i].Path));
                var tf = Replace(string.Format("{0}{1}{2}", hotVersionPath, Path.DirectorySeparatorChar, hotFilesPathContextList[i].Path));

                string dir = Path.GetDirectoryName(tf);
                Directory.CreateDirectory(dir);

                File.Copy(rf, tf);
                RGLog.Debug("copy hot file -> " + hotFilesPathContextList[i].Path);
            }
        }

        RGLog.Debug("热更资源构建完毕");
    }
コード例 #7
0
    /// <summary>
    /// 生成 streaming upk包
    /// </summary>
    public static void BuildStreamingUPK()
    {
        //资源路径
        string assetPath = Replace(string.Format("{0}{1}{2}", Application.dataPath, Path.DirectorySeparatorChar, "StreamingAssets"));

        // UPK 资源路径
        string UPKPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "streaming.upk"));

        // UPK INFO 资源路径
        string InfoPath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "streaming.txt"));

        // files.txt 路径
        string filePath = Replace(string.Format("{0}{1}{2}", assetPath, Path.DirectorySeparatorChar, "files.txt"));

        //开始打包
        List <UPKInfo> infoList = new List <UPKInfo>();

        var fileData = File.ReadAllBytes(filePath);
        var files    = ReadFileInfo(filePath);

        for (int i = 0; i < files.Length; i++)
        {
            var file = files[i];
            var fs   = Replace(Path.Combine(assetPath, file.Path));

            FileInfo fileInfo = new FileInfo(fs);

            UPKInfo uinfo = new UPKInfo();
            uinfo.relativePath = file.Path;
            uinfo.absolutePath = fs;
            uinfo.length       = fileInfo.Length;

            infoList.Add(uinfo);
        }
        // 把files文件也加入
        FileInfo filesInfo  = new FileInfo(filePath);
        UPKInfo  filesuinfo = new UPKInfo();

        filesuinfo.relativePath = "files.txt";
        filesuinfo.absolutePath = filePath;
        filesuinfo.length       = filesInfo.Length;

        infoList.Add(filesuinfo);

        // 打包
        UPKEngine.Pack(infoList, UPKPath, InfoPath);

        // 删除 streamingAssets 内的其他资源
        // 删除文件
        string[] streamingFiles = Directory.GetFiles(assetPath);
        for (int i = 0; i < streamingFiles.Length; i++)
        {
            if (!streamingFiles[i].Equals(UPKPath) && !streamingFiles[i].Equals(InfoPath))
            {
                File.Delete(streamingFiles[i]);
            }
        }
        // 删除文件夹
        string[] streamingDirs = Directory.GetDirectories(assetPath);
        for (int i = 0; i < streamingDirs.Length; i++)
        {
            Directory.Delete(streamingDirs[i], true);
        }

        RGLog.Debug(" 生成 streaming upk 包完成");
    }