Example #1
0
        static void CopyToStreamingAsset(AssetBundleManifest assetBundleManifest)
        {
            AssetBundleVersionWraper versionWraper             = new AssetBundleVersionWraper();
            Dictionary <string, AssetBundleLoadInfo> loadInfos = new Dictionary <string, AssetBundleLoadInfo>();
            var buildMap = assetBundleManifest.GetAllAssetBundles();

            foreach (var bundleBuild in buildMap)
            {
                var bundleName = bundleBuild;
                loadInfos.Add(bundleName, new AssetBundleLoadInfo
                {
                    Name         = bundleName,
                    Hash         = assetBundleManifest.GetAssetBundleHash(bundleName).ToString(),
                    Dependancies = assetBundleManifest.GetAllDependencies(bundleName).ToList(),
                    Md5Str       = AssetUtils.BuildFileMd5(Path.Combine(AssetBundlePathConst.assetBundleOutPath, bundleName)),
                });
            }

            foreach (var loadInfo in loadInfos)
            {
                Debug.Log($"json={loadInfo.Value.Dependancies.Count},key={loadInfo.Value.Hash}");
            }
            versionWraper.LoadInfos = loadInfos;
            var sourcesPath = AssetBundlePathConst.assetBundleOutPath;
            var targetPath  = Path.Combine(Application.streamingAssetsPath, AssetBundlePathConst.RuntimeAssetsRoot);

            AssetBundlePathTools.CreateFolder(targetPath);
            AssetBundlePathTools.CopyDirectory(sourcesPath, targetPath);

            JsonSerializerSettings setting = new JsonSerializerSettings();

            setting.NullValueHandling = NullValueHandling.Ignore;
            string json = JsonConvert.SerializeObject(versionWraper, setting);

            Debug.Log($"json={json}");
            string filePath = Path.Combine(targetPath, "Version.txt");

            File.WriteAllText(filePath, json, Encoding.UTF8);
        }