Example #1
0
        private static void ApplyAssetBundleName(AssetManageManager assetManageManager, AssetInfoManifest manifest)
        {
            var assetInfos = manifest.GetAssetInfos().ToArray();

            var count = assetInfos.Length;

            AssetDatabase.StartAssetEditing();

            for (var i = 0; i < count; i++)
            {
                var assetInfo = assetInfos[i];

                EditorUtility.DisplayProgressBar("ApplyAssetBundleName", assetInfo.ResourcePath, (float)i / count);

                var assetPath = PathUtility.Combine(assetManageManager.ExternalResourcesPath, assetInfo.ResourcePath);

                if (assetInfo.IsAssetBundle)
                {
                    assetManageManager.SetAssetBundleName(assetPath, assetInfo.AssetBundle.AssetBundleName);
                }
            }

            AssetDatabase.StopAssetEditing();

            EditorUtility.ClearProgressBar();
        }
Example #2
0
        /// <summary> 未登録のアセットバンドル情報追加 </summary>
        public void AddUnregisteredAssetInfos(AssetInfoManifest assetInfoManifest, BuildResult buildResult)
        {
            var assetBundleAssetInfos = assetInfoManifest.GetAssetInfos()
                                        .Where(x => x.IsAssetBundle)
                                        .GroupBy(x => x.AssetBundle.AssetBundleName)
                                        .ToArray();

            foreach (var bundleInfo in buildResult.BundleBuildResults.BundleInfos)
            {
                var assetBundleName = bundleInfo.Key;

                // マニフェストファイルは登録しない.
                if (AssetInfoManifest.AssetBundleName == assetBundleName)
                {
                    continue;
                }

                // 既に登録済み.
                if (assetBundleAssetInfos.Any(x => x.Key == assetBundleName))
                {
                    continue;
                }

                var fileName = Path.GetFileName(bundleInfo.Value.FileName);

                var assetInfo = new AssetInfo(fileName, "(undefined)", null);

                var assetBundleInfo = new AssetBundleInfo(assetBundleName);

                assetInfo.SetAssetBundleInfo(assetBundleInfo);

                assetInfoManifest.AddAssetInfo(assetInfo);
            }
        }
Example #3
0
        /// <summary> アセットのルートハッシュ情報を書き込み </summary>
        public void SetAssetInfoHash(AssetInfoManifest assetInfoManifest)
        {
            // 文字数が大きくなりすぎないように300ファイル分毎に分割.
            var chunkInfos = assetInfoManifest.GetAssetInfos()
                             .Chunk(300)
                             .ToArray();

            var versionHashBuilder = new StringBuilder();

            foreach (var assetInfos in chunkInfos)
            {
                var hashBuilder = new StringBuilder();

                foreach (var assetInfo in assetInfos)
                {
                    hashBuilder.AppendLine(assetInfo.Hash);
                }

                var hash = hashBuilder.ToString().GetHash();

                versionHashBuilder.AppendLine(hash);
            }

            var versionHash = versionHashBuilder.ToString().GetHash();

            Reflection.SetPrivateField(assetInfoManifest, "versionHash", versionHash);
        }
Example #4
0
        private static void ApplyAssetBundleName(AssetManagement assetManagement, AssetInfoManifest manifest)
        {
            var projectFolders = ProjectFolders.Instance;

            var externalResourcesPath = projectFolders.ExternalResourcesPath;
            var shareResourcesPath    = projectFolders.ShareResourcesPath;

            var assetInfos = manifest.GetAssetInfos().ToArray();

            var count = assetInfos.Length;

            using (new AssetEditingScope())
            {
                for (var i = 0; i < count; i++)
                {
                    var assetInfo = assetInfos[i];

                    var apply = false;

                    if (assetInfo.IsAssetBundle)
                    {
                        var assetPath = ExternalResources.GetAssetPathFromAssetInfo(externalResourcesPath, shareResourcesPath, assetInfo);

                        apply = assetManagement.SetAssetBundleName(assetPath, assetInfo.AssetBundle.AssetBundleName);
                    }

                    if (apply)
                    {
                        EditorUtility.DisplayProgressBar("ApplyAssetBundleName", assetInfo.ResourcePath, (float)i / count);
                    }
                }
            }

            EditorUtility.ClearProgressBar();
        }
        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 };
        }
Example #6
0
        /// <summary> アップロードするファイルデータ構築. </summary>
        private FileInfo[] BuildUploadFileInfos()
        {
            Debug.Log("Build upload file infos.");

            var fileInfos = new List <FileInfo>();

            var folderPathLength = folderPath.Length;

            var allAssetInfos = assetInfoManifest.GetAssetInfos().ToArray();

            var fileHashTable = new Dictionary <string, string>();

            var assetInfoManifestFileName = Path.GetFileNameWithoutExtension(AssetInfoManifest.ManifestFileName);

            foreach (var assetInfo in allAssetInfos)
            {
                var fileName = Path.GetFileNameWithoutExtension(assetInfo.FileName);

                if (fileHashTable.ContainsKey(fileName))
                {
                    continue;
                }

                fileHashTable.Add(fileName, assetInfo.Hash);
            }

            foreach (var file in files)
            {
                var fileName = Path.GetFileNameWithoutExtension(file);

                var hash = string.Empty;

                if (assetInfoManifestFileName == fileName)
                {
                    hash = FileUtility.GetHash(file);
                }
                else
                {
                    hash = fileHashTable.GetValueOrDefault(fileName);
                }

                var path       = file.SafeSubstring(folderPathLength);
                var objectPath = PathUtility.Combine(bucketFolder, path);

                var fileInfo = new FileInfo()
                {
                    FilePath   = file,
                    ObjectPath = objectPath,
                    Hash       = hash,
                };

                fileInfos.Add(fileInfo);
            }

            return(fileInfos.ToArray());
        }
Example #7
0
        /// <summary> アセットバンドルの参照情報を書き込み </summary>
        public static void SetDependencies(AssetInfoManifest assetInfoManifest, AssetBundleManifest assetBundleManifest)
        {
            var assetInfos = assetInfoManifest.GetAssetInfos().Where(x => x.IsAssetBundle).ToArray();

            foreach (var assetInfo in assetInfos)
            {
                var dependencies = assetBundleManifest.GetDirectDependencies(assetInfo.AssetBundle.AssetBundleName);

                assetInfo.AssetBundle.SetDependencies(dependencies);
            }
        }
        //----- 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);
        }
Example #9
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());
        }
Example #10
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)
                             .Where(x => IsCriAsset(x))
                             .Select(x => PathUtility.ConvertPathSeparator(x))
                             .ToArray();

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

            return(cacheFiles
                   .Where(x => !managedFiles.Contains(x))
                   .ToArray());
        }
Example #11
0
        //----- params -----

        //----- field -----

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

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

        /// <summary>
        /// CriAssetをアセットバンドルの出力先にコピー.
        /// </summary>
        public static void Generate(string exportPath, AssetInfoManifest assetInfoManifest)
        {
            var projectFolders = ProjectFolders.Instance;

            if (projectFolders == null)
            {
                return;
            }

            var externalResourcesPath = projectFolders.ExternalResourcesPath;

            Func <AssetInfo, bool> isCriAssetInfo = x =>
            {
                if (string.IsNullOrEmpty(x.FileName))
                {
                    return(false);
                }

                var extension = Path.GetExtension(x.ResourcePath);

                return(CriAssetDefinition.AssetAllExtensions.Contains(extension));
            };

            var assetInfos = assetInfoManifest.GetAssetInfos().Where(x => isCriAssetInfo(x)).ToArray();

            foreach (var assetInfo in assetInfos)
            {
                var source = PathUtility.Combine(new string[] { UnityPathUtility.GetProjectFolderPath(), externalResourcesPath, assetInfo.ResourcePath });
                var dest   = PathUtility.Combine(new string[] { exportPath, assetInfo.FileName });

                var directory = Path.GetDirectoryName(dest);

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

                File.Copy(source, dest, true);
            }
        }
Example #12
0
        /// <summary> アセットバンドルの参照情報を書き込み </summary>
        public void SetDependencies(AssetInfoManifest assetInfoManifest, BuildResult buildResult)
        {
            var assetInfos = assetInfoManifest.GetAssetInfos().Where(x => x.IsAssetBundle).ToArray();

            foreach (var assetInfo in assetInfos)
            {
                if (!assetInfo.IsAssetBundle)
                {
                    continue;
                }

                var assetBundleName = assetInfo.AssetBundle.AssetBundleName;

                var detail = buildResult.GetDetails(assetBundleName);

                if (!detail.HasValue)
                {
                    throw new InvalidDataException("AssetBundle build info not found. : " + assetBundleName);
                }

                assetInfo.AssetBundle.SetDependencies(detail.Value.Dependencies);
            }
        }
Example #13
0
        /// <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 managedFiles = manifest.GetAssetInfos()
                                   .Select(x => BuildFilePath(x))
                                   .Select(x => PathUtility.ConvertPathSeparator(x))
                                   .Distinct()
                                   .ToHashSet();

                var targets = cacheFiles
                              .Select(x => PathUtility.ConvertPathSeparator(x))
                              .Where(x =>
                {
                    var extension = Path.GetExtension(x);

                    return(CriAssetDefinition.AssetAllExtensions.Any(y => y == extension));
                })
                              .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 criassets ({0}ms)\n{1}", sw.Elapsed.TotalMilliseconds, log);
                }
            }
        }
Example #14
0
        public static bool AssetDependenciesValidate(AssetInfoManifest assetInfoManifest)
        {
            var projectFolders = ProjectFolders.Instance;

            var config = ManageConfig.Instance;

            var externalResourcesPath = projectFolders.ExternalResourcesPath;

            var allAssetInfos = assetInfoManifest.GetAssetInfos().ToArray();

            var ignoreValidatePaths = config.IgnoreValidateTarget
                                      .Where(x => x != null)
                                      .Select(x => AssetDatabase.GetAssetPath(x))
                                      .ToArray();

            Func <string, bool> checkInvalid = path =>
            {
                // 除外対象拡張子はチェック対象外.

                var extension = Path.GetExtension(path);

                if (IgnoreDependentCheckExtensions.Any(y => y == extension))
                {
                    return(false);
                }

                // 除外対象.

                if (ignoreValidatePaths.Any(x => path.StartsWith(x)))
                {
                    return(false);
                }

                // 外部アセット対象ではない.

                if (!path.StartsWith(externalResourcesPath))
                {
                    return(true);
                }

                return(false);
            };

            using (new DisableStackTraceScope())
            {
                foreach (var assetInfo in allAssetInfos)
                {
                    var assetPath = PathUtility.Combine(externalResourcesPath, assetInfo.ResourcePath);

                    var dependencies = AssetDatabase.GetDependencies(assetPath);

                    var invalidDependencies = dependencies.Where(x => checkInvalid(x)).ToArray();

                    if (invalidDependencies.Any())
                    {
                        var builder = new StringBuilder();

                        builder.AppendFormat("Asset: {0}", assetPath).AppendLine();
                        builder.AppendLine("Invalid Dependencies:");

                        foreach (var item in invalidDependencies)
                        {
                            builder.AppendLine(item);
                        }

                        Debug.LogWarningFormat(builder.ToString());

                        return(false);
                    }
                }
            }

            return(true);
        }