示例#1
0
        public static async Task BuildAssetInfoManifestPackage(string exportPath, string assetBundlePath, string aesKey, string aesIv)
        {
            var assetInfo = AssetInfoManifest.GetManifestAssetInfo();

            var cryptoKey = new AesCryptoStreamKey(aesKey, aesIv);

            var task = CreateBuildTask(exportPath, assetBundlePath, assetInfo, true, cryptoKey);

            await task;
        }
        //----- field -----

        //----- property -----

        //----- method -----

        public void Build(string exportPath, string assetBundlePath, AssetInfoManifest assetInfoManifest, string password, Action <int, int> reportProgress)
        {
            var assetInfos = assetInfoManifest.GetAssetInfos()
                             .Where(x => x.IsAssetBundle)
                             .Where(x => !string.IsNullOrEmpty(x.AssetBundle.AssetBundleName))
                             .GroupBy(x => x.AssetBundle.AssetBundleName)
                             .Select(x => x.FirstOrDefault())
                             .ToList();

            assetInfos.Add(AssetInfoManifest.GetManifestAssetInfo());

            var total = assetInfos.Count;

            reportProgress(0, total);

            var progress = new Progress();

            var events = new List <WaitHandle>();

            // スレッドで分割処理.

            var workerNo    = 0;
            var workerPaths = new List <AssetInfo> [MaxWorkerCount];

            foreach (var assetInfo in assetInfos)
            {
                if (workerPaths[workerNo] == null)
                {
                    workerPaths[workerNo] = new List <AssetInfo>();
                }

                workerPaths[workerNo].Add(assetInfo);

                workerNo = (workerNo + 1) % MaxWorkerCount;
            }

            foreach (var item in workerPaths)
            {
                if (item == null)
                {
                    continue;
                }

                events.Add(StartWorker(exportPath, assetBundlePath, password, item.ToArray(), progress));
            }

            while (!WaitHandle.WaitAll(events.ToArray(), 100))
            {
                reportProgress(progress.count, total);
            }

            reportProgress(progress.count, total);
        }
示例#3
0
        public AssetInfo[] GetAllTargetAssetInfo(AssetInfoManifest assetInfoManifest)
        {
            var assetInfos = assetInfoManifest.GetAssetInfos()
                             .Where(x => x.IsAssetBundle)
                             .Where(x => !string.IsNullOrEmpty(x.AssetBundle.AssetBundleName))
                             .GroupBy(x => x.AssetBundle.AssetBundleName)
                             .Select(x => x.FirstOrDefault())
                             .ToList();

            assetInfos.Add(AssetInfoManifest.GetManifestAssetInfo());

            return(assetInfos.ToArray());
        }
示例#4
0
        /// <summary>
        /// マニフェストファイルに存在しないキャッシュファイルを破棄.
        /// </summary>
        public string[] GetDisUsedFilePaths()
        {
            if (simulateMode)
            {
                return(null);
            }

            if (manifest == null)
            {
                return(null);
            }

            var installDir = GetFilePath(null);

            if (string.IsNullOrEmpty(installDir))
            {
                return(null);
            }

            if (!Directory.Exists(installDir))
            {
                return(null);
            }

            var directory = Path.GetDirectoryName(installDir);

            if (!Directory.Exists(directory))
            {
                return(null);
            }

            var cacheFiles = Directory.GetFiles(installDir, "*", SearchOption.AllDirectories);

            var allAssetInfos = manifest.GetAssetInfos().ToList();

            allAssetInfos.Add(AssetInfoManifest.GetManifestAssetInfo());

            var managedFiles = allAssetInfos
                               .Select(x => GetFilePath(x))
                               .Distinct()
                               .ToHashSet();

            return(cacheFiles
                   .Select(x => PathUtility.ConvertPathSeparator(x))
                   .Where(x => Path.GetExtension(x) == PackageExtension)
                   .Where(x => !managedFiles.Contains(x))
                   .ToArray());
        }
        /// <summary>
        /// アセット情報ファイルを更新.
        /// </summary>
        public IObservable <Unit> UpdateAssetInfoManifest()
        {
            if (simulateMode)
            {
                return(Observable.ReturnUnit());
            }

            if (localMode)
            {
                return(Observable.ReturnUnit());
            }

            var manifestAssetInfo = AssetInfoManifest.GetManifestAssetInfo();

            return(Observable.FromMicroCoroutine(() => UpdateAssetBundleInternal(manifestAssetInfo)));
        }
        private void BuildAssetInfoTable()
        {
            assetInfosByAssetBundleName.Clear();

            if (manifest != null)
            {
                assetInfosByAssetBundleName = manifest.GetAssetInfos()
                                              .Where(x => x.IsAssetBundle)
                                              .GroupBy(x => x.AssetBundle.AssetBundleName)
                                              .ToDictionary(x => x.Key, x => x.ToArray());
            }

            // ※ アセット管理情報内にAssetInfoManifestの情報は入っていないので明示的に追加する.

            var manifestAssetInfo = AssetInfoManifest.GetManifestAssetInfo();

            assetInfosByAssetBundleName[manifestAssetInfo.AssetBundle.AssetBundleName] = new AssetInfo[] { manifestAssetInfo };
        }
示例#7
0
        /// <summary> AssetInfoManifest読み込み </summary>
        private async Task LoadAssetInfoManifest()
        {
            Debug.Log("Load AssetInfoManifest.package.");

            var projectFolders = ProjectFolders.Instance;

            assetInfoManifestFilePath = GetAssetInfoManifestFilePath(files);

            var manifestAssetInfo = AssetInfoManifest.GetManifestAssetInfo();

            var assetPath = PathUtility.Combine(projectFolders.ExternalResourcesPath, manifestAssetInfo.ResourcePath);

            var cryptoKey = GetCryptoKey();

            using (var fileStream = new FileStream(assetInfoManifestFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var aesStream = new SeekableCryptoStream(fileStream, cryptoKey))
                {
                    var bundleLoadRequest = AssetBundle.LoadFromStreamAsync(aesStream);

                    while (!bundleLoadRequest.isDone)
                    {
                        await Task.Delay(25);
                    }

                    var assetBundle = bundleLoadRequest.assetBundle;

                    var loadAssetAsync = assetBundle.LoadAssetAsync(assetPath, typeof(AssetInfoManifest));

                    while (!loadAssetAsync.isDone)
                    {
                        await Task.Delay(25);
                    }

                    assetInfoManifest = loadAssetAsync.asset as AssetInfoManifest;

                    assetBundle.Unload(false);
                }
            }
        }
        /// <summary>
        /// マニフェストファイルに存在しないキャッシュファイルを破棄.
        /// </summary>
        private void CleanUnuseCache()
        {
            if (simulateMode)
            {
                return;
            }

            if (manifest == null)
            {
                return;
            }

            var installDir = BuildFilePath(null);

            if (string.IsNullOrEmpty(installDir))
            {
                return;
            }

            if (!Directory.Exists(installDir))
            {
                return;
            }

            var sw = System.Diagnostics.Stopwatch.StartNew();

            var builder = new StringBuilder();

            var directory = Path.GetDirectoryName(installDir);

            if (Directory.Exists(directory))
            {
                var cacheFiles = Directory.GetFiles(installDir, "*", SearchOption.AllDirectories);

                var allAssetInfos = manifest.GetAssetInfos().ToList();

                allAssetInfos.Add(AssetInfoManifest.GetManifestAssetInfo());

                var managedFiles = allAssetInfos
                                   .Select(x => BuildFilePath(x))
                                   .Select(x => PathUtility.ConvertPathSeparator(x))
                                   .Distinct()
                                   .ToHashSet();

                var targets = cacheFiles
                              .Select(x => PathUtility.ConvertPathSeparator(x))
                              .Where(x => Path.GetExtension(x) == PackageExtension)
                              .Where(x => !managedFiles.Contains(x))
                              .ToArray();

                foreach (var target in targets)
                {
                    if (!File.Exists(target))
                    {
                        continue;
                    }

                    File.SetAttributes(target, FileAttributes.Normal);
                    File.Delete(target);

                    builder.AppendLine(target);
                }

                var deleteDirectorys = DirectoryUtility.DeleteEmpty(installDir);

                deleteDirectorys.ForEach(x => builder.AppendLine(x));

                sw.Stop();

                var log = builder.ToString();

                if (!string.IsNullOrEmpty(log))
                {
                    UnityConsole.Info("Delete unuse cached assetbundles ({0}ms)\n{1}", sw.Elapsed.TotalMilliseconds, log);
                }
            }
        }