Beispiel #1
0
        void OnDestroy()
        {
            if (AssetManagement.Prefs.manifestUpdateRequest)
            {
                AssetInfoManifestGenerator.Generate();
            }

            Disposable.Dispose();
        }
Beispiel #2
0
        private static void InitializeOnLoadMethod()
        {
            if (Application.isBatchMode)
            {
                return;
            }

            if (Prefs.manifestUpdateRequest)
            {
                AssetInfoManifestGenerator.Generate();
            }
        }
        public static void Build(string externalResourcesPath)
        {
            var exportPath = GetExportPath();

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

            if (Directory.Exists(exportPath))
            {
                Directory.Delete(exportPath, true);
            }

            EditorApplication.LockReloadAssemblies();

            #if ENABLE_CRIWARE
            CriAssetGenerator.Generate(exportPath, externalResourcesPath);
            #endif

            // CriAssetGeneratorでCriのManifestファイルを生成後に実行.
            var assetBundleManifest = BuildAssetBundle.BuildAllAssetBundles(exportPath);

            // ビルド成果物の情報をAssetInfoManifestに書き込み.
            AssetInfoManifestGenerator.SetAssetFileInfo(exportPath, externalResourcesPath, assetBundleManifest);

            // 再度AssetInfoManifestだけビルドを実行.
            BuildAssetBundle.BuildAssetInfoManifest(exportPath, externalResourcesPath);

            // 不要ファイル削除.
            BuildAssetBundle.DeleteUnUseFiles(exportPath);

            // AssetBundleファイルをパッケージ化.
            BuildAssetBundle.BuildPackage(exportPath);

            EditorApplication.UnlockReloadAssemblies();

            UnityConsole.Event(ExternalResources.ConsoleEventName, ExternalResources.ConsoleEventColor, "Build ExternalResource Complete.");
        }
Beispiel #4
0
        void OnGUI()
        {
            if (!initialized)
            {
                return;
            }

            var editorConfig      = ProjectFolders.Instance;
            var assetManageConfig = AssetManageConfig.Instance;

            var externalResourcesPath = editorConfig.ExternalResourcesPath;

            EditorGUILayout.Separator();

            var backgroundColor = new Color(0.3f, 0.3f, 0.5f);
            var labelColor      = new Color(0.8f, 0.8f, 0.8f, 0.8f);

            EditorLayoutTools.DrawLabelWithBackground("AssetInfoManifest", backgroundColor, labelColor);

            if (GUILayout.Button("Generate"))
            {
                // アセット情報ファイルを生成.
                AssetInfoManifestGenerator.Generate(externalResourcesPath, assetManageConfig);
            }

            GUILayout.Space(6f);

            EditorLayoutTools.DrawLabelWithBackground("ExternalResource", backgroundColor, labelColor);

            if (GUILayout.Button("Generate"))
            {
                if (ExternalResourceManager.BuildConfirm())
                {
                    var build = true;

                    #if ENABLE_CRIWARE_ADX || ENABLE_CRIWARE_SOFDEC
                    // CRIの最新アセットに更新.
                    CriAssetUpdater.Execute();
                    #endif

                    try
                    {
                        EditorApplication.LockReloadAssemblies();

                        // アセット情報ファイルを生成.
                        AssetInfoManifestGenerator.Generate(externalResourcesPath, assetManageConfig);

                        // 依存関係の検証.
                        var validate = AssetDependencies.Validate(externalResourcesPath);

                        if (!validate)
                        {
                            var messeage = "There is an incorrect reference.\nDo you want to cancel the build?";

                            if (!EditorUtility.DisplayDialog("InvalidDependant", messeage, "build", "cancel"))
                            {
                                build = false;

                                // ExternalResourceフォルダ以外の参照が含まれる場合は依存関係を表示.
                                InvalidDependantWindow.Open(externalResourcesPath);
                            }
                        }

                        // ビルド.
                        if (build)
                        {
                            ExternalResourceManager.Build(externalResourcesPath, assetManageConfig);
                        }
                    }
                    finally
                    {
                        EditorApplication.UnlockReloadAssemblies();
                    }
                }
            }

            EditorGUILayout.Separator();
        }
Beispiel #5
0
        void OnGUI()
        {
            if (!initialized)
            {
                return;
            }

            EditorGUILayout.Separator();

            EditorLayoutTools.Title("AssetInfoManifest");

            GUILayout.Space(2f);

            if (GUILayout.Button("Generate"))
            {
                // アセット情報ファイルを生成.
                AssetInfoManifestGenerator.Generate();
            }

            GUILayout.Space(6f);

            EditorLayoutTools.Title("ExternalResource");

            GUILayout.Space(2f);

            if (GUILayout.Button("Generate"))
            {
                if (BuildManager.BuildConfirm())
                {
                    var build = true;

                    #if ENABLE_CRIWARE_ADX || ENABLE_CRIWARE_SOFDEC
                    // CRIの最新アセットに更新.
                    CriAssetUpdater.Execute();
                    #endif

                    try
                    {
                        EditorApplication.LockReloadAssemblies();

                        // アセット情報ファイルを生成.
                        var assetInfoManifest = AssetInfoManifestGenerator.Generate();

                        // 依存関係の検証.
                        var validate = BuildManager.AssetDependenciesValidate(assetInfoManifest);

                        if (!validate)
                        {
                            var message = "There is an incorrect reference.\nDo you want to cancel the build?";

                            if (!EditorUtility.DisplayDialog("Invalid Dependencies", message, "build", "cancel"))
                            {
                                build = false;

                                // ExternalResourceフォルダ以外の参照が含まれる場合は依存関係を表示.
                                InvalidDependantWindow.Open();
                            }
                        }

                        // ビルド.
                        if (build)
                        {
                            var exportPath = BuildManager.GetExportPath();

                            if (!string.IsNullOrEmpty(exportPath))
                            {
                                if (onBuildStart != null)
                                {
                                    onBuildStart.OnNext(Unit.Default);
                                }

                                BuildManager.Build(exportPath, assetInfoManifest)
                                .ToObservable()
                                .Subscribe()
                                .AddTo(Disposable);
                            }
                            else
                            {
                                Debug.LogError("The export path is not set.");

                                var config = ManageConfig.Instance;

                                if (config != null)
                                {
                                    Selection.activeObject = config;
                                }
                            }
                        }
                    }
                    finally
                    {
                        EditorApplication.UnlockReloadAssemblies();
                    }
                }
            }

            EditorGUILayout.Separator();
        }
        public static void Build(string externalResourcesPath, AssetManageConfig assetManageConfig)
        {
            var exportPath = GetExportPath();

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

            if (Directory.Exists(exportPath))
            {
                Directory.Delete(exportPath, true);
            }

            EditorApplication.LockReloadAssemblies();

            try
            {
                // アセット情報ファイルを生成.
                var assetInfoManifest = AssetInfoManifestGenerator.Generate(externalResourcesPath, assetManageConfig);

                // キャッシュ済みアセットバンドルのハッシュ値取得.
                var cachedAssetBundleHashs = BuildAssetBundle.GetCachedAssetBundleHash();

                // CRIアセットを生成.
                #if ENABLE_CRIWARE_ADX || ENABLE_CRIWARE_SOFDEC
                CriAssetGenerator.Generate(exportPath, externalResourcesPath, assetInfoManifest);
                #endif

                // AssetBundleをビルド.
                var assetBundleManifest = BuildAssetBundle.BuildAllAssetBundles();

                // 不要になった古いAssetBundle削除.
                BuildAssetBundle.CleanUnUseAssetBundleFiles();

                // ビルド成果物の情報をAssetInfoManifestに書き込み.

                var assetBundlePath = BuildAssetBundle.GetAssetBundleOutputPath();

                AssetInfoManifestGenerator.SetAssetBundleFileInfo(assetBundlePath, externalResourcesPath, assetBundleManifest);

                #if ENABLE_CRIWARE_ADX || ENABLE_CRIWARE_SOFDEC
                AssetInfoManifestGenerator.SetCriAssetFileInfo(exportPath, externalResourcesPath, assetBundleManifest);
                #endif

                // アセットバンドルの参照情報をAssetInfoManifestに書き込み.
                BuildAssetBundle.SetDependencies(assetInfoManifest, assetBundleManifest);

                // 再度AssetInfoManifestだけビルドを実行.
                BuildAssetBundle.BuildAssetInfoManifest(externalResourcesPath);

                // 更新が必要なパッケージファイルを削除.
                BuildAssetBundle.CleanOldPackage(cachedAssetBundleHashs);

                // AssetBundleファイルをパッケージ化.
                BuildAssetBundle.BuildPackage(exportPath, assetInfoManifest, assetManageConfig.CryptPassword);

                // 出力先フォルダを開く.
                UnityEditorUtility.OpenFolder(exportPath);

                UnityConsole.Event(ExternalResources.ConsoleEventName, ExternalResources.ConsoleEventColor, "Build ExternalResource Complete.");
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                throw;
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }
        }
Beispiel #7
0
        public static async Task <string> Build(string exportPath, AssetInfoManifest assetInfoManifest, bool openExportFolder = true)
        {
            if (string.IsNullOrEmpty(exportPath))
            {
                return(null);
            }

            if (Directory.Exists(exportPath))
            {
                Directory.Delete(exportPath, true);
            }

            var versionHash = string.Empty;

            var assetManagement = AssetManagement.Instance;

            assetManagement.Initialize();

            var buildAssetBundle = new BuildAssetBundle(BundlePipeline);

            EditorApplication.LockReloadAssemblies();

            try
            {
                var stopwatch = System.Diagnostics.Stopwatch.StartNew();

                var logBuilder = new StringBuilder();

                var manageConfig = ManageConfig.Instance;

                var cryptoKey = manageConfig.CryptoKey;
                var cryptoIv  = manageConfig.CryptoIv;

                var assetBundlePath = buildAssetBundle.GetAssetBundleOutputPath();

                // 暗号化鍵情報の変更チェック.

                var cryptoChanged = BuildAssetBundlePackage.CheckCryptoFile(assetBundlePath, cryptoKey, cryptoIv);

                using (new DisableStackTraceScope())
                {
                    var processTime = System.Diagnostics.Stopwatch.StartNew();

                    //------ アセットバンドル名を設定------

                    using (new BuildLogScope(logBuilder, processTime, "ApplyAllAssetBundleName"))
                    {
                        assetManagement.ApplyAllAssetBundleName();
                    }

                    //------ キャッシュ済みアセットバンドルの最終更新日時取得 ------

                    Dictionary <string, DateTime> cachedFileLastWriteTimeTable = null;

                    using (new BuildLogScope(logBuilder, processTime, "GetCachedFileLastWriteTimeTable"))
                    {
                        cachedFileLastWriteTimeTable = await buildAssetBundle.GetCachedFileLastWriteTimeTable();
                    }

                    //------ CRIアセットを生成 ------

                    #if ENABLE_CRIWARE_ADX || ENABLE_CRIWARE_SOFDEC
                    using (new BuildLogScope(logBuilder, processTime, "GenerateCriAsset"))
                    {
                        CriAssetGenerator.Generate(exportPath, assetInfoManifest);
                    }
                    #endif

                    //------ AssetBundleをビルド ------

                    BuildResult buildResult = null;

                    using (new BuildLogScope(logBuilder, processTime, "BuildAllAssetBundles"))
                    {
                        buildResult = buildAssetBundle.BuildAllAssetBundles();
                    }

                    if (!buildResult.IsSuccess)
                    {
                        Debug.LogError("Build ExternalResource failed.");

                        return(null);
                    }

                    //------ 未登録のアセットバンドル情報追加 ------

                    using (new BuildLogScope(logBuilder, processTime, "AddUnregisteredAssetInfos"))
                    {
                        buildAssetBundle.AddUnregisteredAssetInfos(assetInfoManifest, buildResult);
                    }

                    //------ 不要になった古いAssetBundle削除 ------

                    using (new BuildLogScope(logBuilder, processTime, "CleanUnUseAssetBundleFiles"))
                    {
                        buildAssetBundle.CleanUnUseAssetBundleFiles(buildResult);
                    }

                    //------ AssetBundleファイルをパッケージ化 ------

                    // 暗号化鍵情報の書き込み.

                    using (new BuildLogScope(logBuilder, processTime, "CreateCryptoFile"))
                    {
                        BuildAssetBundlePackage.CreateCryptoFile(assetBundlePath, cryptoKey, cryptoIv);
                    }

                    // 更新対象のアセット情報取得.

                    var assetInfos        = new AssetInfo[0];
                    var updatedAssetInfos = new AssetInfo[0];

                    using (new BuildLogScope(logBuilder, processTime, "GetUpdateTargetAssetInfo"))
                    {
                        assetInfos = buildAssetBundle.GetAllTargetAssetInfo(assetInfoManifest);

                        // 暗号化キーが変わっていたら全て更新対象.
                        if (cryptoChanged)
                        {
                            updatedAssetInfos = assetInfos;
                        }
                        // 差分がある対象だけ抽出.
                        else
                        {
                            updatedAssetInfos = await buildAssetBundle.GetUpdateTargetAssetInfo(assetInfoManifest, cachedFileLastWriteTimeTable);
                        }
                    }

                    // パッケージファイル作成.

                    using (new BuildLogScope(logBuilder, processTime, "BuildPackage"))
                    {
                        await BuildAssetBundlePackage.BuildAllAssetBundlePackage(exportPath, assetBundlePath, assetInfos, updatedAssetInfos, cryptoKey, cryptoIv);
                    }

                    //------ ビルド成果物の情報をAssetInfoManifestに書き込み ------

                    using (new BuildLogScope(logBuilder, processTime, "AssetInfoManifest : SetAssetBundleFileInfo"))
                    {
                        await AssetInfoManifestGenerator.SetAssetBundleFileInfo(assetBundlePath, assetInfoManifest, buildResult);

                        #if ENABLE_CRIWARE_ADX || ENABLE_CRIWARE_SOFDEC
                        await AssetInfoManifestGenerator.SetCriAssetFileInfo(exportPath, assetInfoManifest);
                        #endif
                    }

                    //------ アセットバンドルの参照情報をAssetInfoManifestに書き込み ------

                    using (new BuildLogScope(logBuilder, processTime, "AssetInfoManifest : SetAssetBundleDependencies"))
                    {
                        buildAssetBundle.SetDependencies(assetInfoManifest, buildResult);
                    }

                    //------ バージョンハッシュ情報をAssetInfoManifestに書き込み ------

                    using (new BuildLogScope(logBuilder, processTime, "AssetInfoManifest : SetAssetInfoHash"))
                    {
                        buildAssetBundle.SetAssetInfoHash(assetInfoManifest);
                    }

                    //------ 再度AssetInfoManifestだけビルドを実行 ------

                    using (new BuildLogScope(logBuilder, processTime, "Rebuild AssetInfoManifest"))
                    {
                        buildAssetBundle.BuildAssetInfoManifest();
                    }

                    //------ AssetInfoManifestファイルをパッケージ化 ------

                    using (new BuildLogScope(logBuilder, processTime, "BuildPackage AssetInfoManifest"))
                    {
                        await BuildAssetBundlePackage.BuildAssetInfoManifestPackage(exportPath, assetBundlePath, cryptoKey, cryptoIv);
                    }
                }

                versionHash = assetInfoManifest.VersionHash;

                //------ バージョンをファイル出力------

                GenerateVersionFile(exportPath, versionHash);

                //------ ログ出力------

                stopwatch.Stop();

                // ビルド情報.

                var buildLogText = new StringBuilder();

                var totalSeconds = stopwatch.Elapsed.TotalSeconds;

                buildLogText.AppendFormat("Build ExternalResource Complete. ({0:F2}sec)", totalSeconds).AppendLine();
                buildLogText.AppendLine();
                buildLogText.AppendFormat("VersionHash : {0}", versionHash).AppendLine();
                buildLogText.AppendLine();
                buildLogText.AppendLine(logBuilder.ToString());
                buildLogText.AppendLine();

                UnityConsole.Event(ExternalResources.ConsoleEventName, ExternalResources.ConsoleEventColor, buildLogText.ToString());

                //------ 出力先フォルダを開く------

                if (openExportFolder)
                {
                    UnityEditorUtility.OpenFolder(exportPath);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                throw;
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }

            return(versionHash);
        }