コード例 #1
0
ファイル: Utility.cs プロジェクト: cyber1496/UnityBuilder
        public static void ExecuteScript(ProcessRequest request)
        {
            EditorUtility.DisplayProgressBar("UnityBuilder.ExternalToolKit", $"ExecuteScript:{request.ScriptFilePath}", 0f);
            int exitCode = -1;

            try
            {
                var process = CreateProcess(request);
                BuildLogger.Log($"[{request.ProcessArguments}]");
                process.Start();
                string message = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                exitCode = process.ExitCode;
                process.Dispose();
                System.IO.File.WriteAllText(request.LogFilePath, message);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                request.Callback?.Invoke(new ProcessResult {
                    ExitCode = exitCode
                });
            }
        }
        private static void DebugPrintCommandSet(ref BuildCommandSet commandSet)
        {
            // TODO: this debug printing function is ugly as sin, fix it
            var msg = new StringBuilder();

            if (!commandSet.commands.IsNullOrEmpty())
            {
                foreach (var bundle in commandSet.commands)
                {
                    msg.AppendFormat("Bundle: '{0}'\n", bundle.assetBundleName);
                    if (!bundle.explicitAssets.IsNullOrEmpty())
                    {
                        msg.Append("\tExplicit Assets:\n");
                        foreach (var asset in bundle.explicitAssets)
                        {
                            // TODO: Create GUIDToAssetPath that takes GUID struct
                            var addressableName = string.IsNullOrEmpty(asset.address) ? AssetDatabase.GUIDToAssetPath(asset.asset.ToString()) : asset.address;
                            msg.AppendFormat("\t\tAsset: {0} - '{1}'\n", asset.asset, addressableName);
                            if (!asset.includedObjects.IsNullOrEmpty())
                            {
                                msg.Append("\t\t\tIncluded Objects:\n");
                                foreach (var obj in asset.includedObjects)
                                {
                                    msg.AppendFormat("\t\t\t\t{0}\n", obj);
                                }
                            }

                            if (!asset.referencedObjects.IsNullOrEmpty())
                            {
                                msg.Append("\t\t\tReferenced Objects:\n");
                                foreach (var obj in asset.referencedObjects)
                                {
                                    msg.AppendFormat("\t\t\t\t{0}\n", obj);
                                }
                            }
                        }
                    }

                    if (!bundle.assetBundleObjects.IsNullOrEmpty())
                    {
                        msg.Append("\tAsset Bundle Objects:\n");
                        foreach (var obj in bundle.assetBundleObjects)
                        {
                            msg.AppendFormat("\t\t{0}: {1}\n", obj.serializationIndex, obj.serializationObject);
                        }
                    }

                    if (!bundle.assetBundleDependencies.IsNullOrEmpty())
                    {
                        msg.Append("\tAsset Bundle Dependencies:\n");
                        foreach (var dependency in bundle.assetBundleDependencies)
                        {
                            msg.AppendFormat("\t\t{0}\n", dependency);
                        }
                    }
                    msg.Append("\n");
                }
            }
            BuildLogger.Log(msg);
        }
コード例 #3
0
        public bool Convert(AddressableAssetEntry[] input, out BuildInput output, bool useCache = true)
        {
            // If enabled, try loading from cache
            Hash128 hash = new Hash128();

            if (useCache)
            {
                hash = CalculateInputHash(input);
                if (LoadFromCache(hash, out output))
                {
                    return(true);
                }
            }

            // Convert inputs
            output             = new BuildInput();
            output.definitions = new BuildInput.Definition[0];

            if (input.IsNullOrEmpty())
            {
                BuildLogger.Log("Unable to continue packing addressable assets. Input is null or empty.");
                return(true);
            }

            var outputDefList = new List <BuildInput.Definition>();

            foreach (var entry in input)
            {
                if (!entry.active)
                {
                    continue;
                }

                var assetPath = AssetDatabase.GUIDToAssetPath(entry.guid.ToString());
                var address   = string.IsNullOrEmpty(entry.address) ? assetPath : entry.address;

                var def = new BuildInput.Definition();
                def.assetBundleName = System.IO.Path.GetFileNameWithoutExtension(address) + "_" + entry.guid.ToString();
                def.explicitAssets  = new[] { new BuildInput.AddressableAsset()
                                              {
                                                  asset = entry.guid, address = address
                                              } };

                outputDefList.Add(def);
            }

            output.definitions = outputDefList.ToArray();

            // Cache results
            if (useCache)
            {
                SaveToCache(hash, output);
            }
            return(true);
        }
コード例 #4
0
        private static BuildPlayerOptions GetBuildPlayerOptions()
        {
            BuildLogger.LogSeparator("Generating Build Options");

            var projectConfig = BuildConfig.ReadProjectConfig();
            var scenePaths    = BuildUtils.GetScenePaths();

            BuildLogger.Log($"BuildArtifactPath: {projectConfig.WebGlBuildName}");
            BuildLogger.LogArray("Scenes:", scenePaths);

            return(new BuildPlayerOptions()
            {
                scenes = scenePaths,
                locationPathName = projectConfig.WebGlBuildName,
                target = BuildTarget.WebGL,
                options = BuildOptions.None
            });
        }
コード例 #5
0
        private void BuildAssetBundles()
        {
            if (!BuildPathValidator.ValidOutputFolder(m_Settings.outputPath, true))
            {
                EditorUtility.DisplayDialog("Invalid Output Folder", string.Format(BuildPathValidator.kPathNotValidError, m_Settings.outputPath), "Ok");
                return;
            }

            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return;
            }

            if (m_Settings.useExperimentalPipeline)
            {
                ExperimentalBuildPipeline();
                return;
            }

            var buildTimer = new Stopwatch();

            buildTimer.Start();

            var exitCode = LegacyBuildPipeline();

            buildTimer.Stop();
            if (exitCode == BuildPipelineCodes.Success)
            {
                BuildLogger.Log("Build Asset Bundles successful in: {0:c}", buildTimer.Elapsed);
            }
            else if (exitCode == BuildPipelineCodes.Canceled)
            {
                BuildLogger.LogWarning("Build Asset Bundles canceled in: {0:c}", buildTimer.Elapsed);
            }
            else
            {
                BuildLogger.LogError("Build Asset Bundles failed in: {0:c}. Error: {1}.", buildTimer.Elapsed, exitCode);
            }
        }
コード例 #6
0
        public static BuildPipelineCodes BuildPlayerScripts(ScriptCompilationSettings settings, out ScriptCompilationResult result, bool useCache = true)
        {
            var buildTimer = new Stopwatch();

            buildTimer.Start();

            BuildPipelineCodes exitCode;

            using (var progressTracker = new BuildProgressTracker(1))
            {
                using (var buildCleanup = new BuildStateCleanup(false, kTempPlayerBuildPath))
                {
                    var scriptDependency = new ScriptDependency(useCache, progressTracker);
                    exitCode = scriptDependency.Convert(settings, kTempPlayerBuildPath, out result);
                    if (exitCode < BuildPipelineCodes.Success)
                    {
                        return(exitCode);
                    }
                }
            }

            buildTimer.Stop();
            if (exitCode >= BuildPipelineCodes.Success)
            {
                BuildLogger.Log("Build Player Scripts successful in: {0:c}", buildTimer.Elapsed);
            }
            else if (exitCode == BuildPipelineCodes.Canceled)
            {
                BuildLogger.LogWarning("Build Player Scripts canceled in: {0:c}", buildTimer.Elapsed);
            }
            else
            {
                BuildLogger.LogError("Build Player Scripts failed in: {0:c}", buildTimer.Elapsed);
            }

            return(exitCode);
        }
コード例 #7
0
            protected override ReturnCode onRun()
            {
                var scheme = helper.Scheme;

                BuildLogger.Log(scheme.ToString());
                EditorUserBuildSettings.development    = scheme.Development;
                EditorUserBuildSettings.allowDebugging = scheme.Development;
                PlayerSettings.SetApplicationIdentifier(helper.BuildTargetGroup, scheme.ApplicationIdentifier);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(helper.BuildTargetGroup,
                                                                 scheme.GetScriptingDefineSymbols(helper.BuildTargetGroup));
                PlayerSettings.companyName = scheme.CompanyName;
                PlayerSettings.productName = scheme.ProductName;
                PlayerSettings.iOS.appleDeveloperTeamID = scheme.IOS.AppleDeveloperTeamID;
                EditorPrefs.SetString(IOS.PREFS_KEY_XCODE_PATH, helper.GetReplacedPath(scheme.IOS.XcodePath));
                EditorUserBuildSettings.buildAppBundle = scheme.Android.UseBuildAppBundle;
                EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
                //PlayerSettings.Android.useCustomKeystore = scheme.Android.UseCustomKeystore;
                PlayerSettings.Android.keystoreName = helper.GetReplacedPath(scheme.Android.KeystoreName);
                PlayerSettings.Android.keystorePass = scheme.Android.KeystorePass;
                PlayerSettings.Android.keyaliasName = scheme.Android.KeyaliasName;
                PlayerSettings.Android.keyaliasPass = scheme.Android.KeyaliasPass;
                EditorPrefs.SetString(Deploygate.PREFS_KEY, helper.GetReplacedPath(scheme.Deploygate.Authorization));
                return(ReturnCode.Success);
            }
        public static BuildPipelineCodes BuildAssetBundles(BuildInput input, BuildSettings settings, BuildCompression compression, string outputFolder, out BuildResultInfo result, object callbackUserData = null, bool useCache = true)
        {
            var buildTimer = new Stopwatch();

            buildTimer.Start();

            if (ProjectValidator.HasDirtyScenes())
            {
                result = new BuildResultInfo();
                buildTimer.Stop();
                BuildLogger.LogError("Build Asset Bundles failed in: {0:c}. Error: {1}.", buildTimer.Elapsed, BuildPipelineCodes.UnsavedChanges);
                return(BuildPipelineCodes.UnsavedChanges);
            }

            var exitCode = BuildPipelineCodes.Success;

            result = new BuildResultInfo();

            AssetDatabase.SaveAssets();

            // TODO: Until new AssetDatabaseV2 is online, we need to switch platforms
            EditorUserBuildSettings.SwitchActiveBuildTarget(settings.group, settings.target);

            var stepCount = BundleDependencyStep.StepCount + BundlePackingStep.StepCount + BundleWritingStep.StepCount;

            using (var progressTracker = new BuildProgressTracker(stepCount))
            {
                using (var buildCleanup = new BuildStateCleanup(true, kTempBundleBuildPath))
                {
                    BuildDependencyInfo buildInfo;
                    exitCode = BundleDependencyStep.Build(input, settings, out buildInfo, useCache, progressTracker);
                    if (exitCode < BuildPipelineCodes.Success)
                    {
                        return(exitCode);
                    }

                    if (PostBuildDependency != null)
                    {
                        exitCode = PostBuildDependency.Invoke(buildInfo, callbackUserData);
                        if (exitCode < BuildPipelineCodes.Success)
                        {
                            return(exitCode);
                        }
                    }

                    BuildWriteInfo writeInfo;
                    exitCode = BundlePackingStep.Build(buildInfo, out writeInfo, useCache, progressTracker);
                    if (exitCode < BuildPipelineCodes.Success)
                    {
                        return(exitCode);
                    }

                    if (PostBuildPacking != null)
                    {
                        exitCode = PostBuildPacking.Invoke(buildInfo, writeInfo, callbackUserData);
                        if (exitCode < BuildPipelineCodes.Success)
                        {
                            return(exitCode);
                        }
                    }

                    exitCode = BundleWritingStep.Build(settings, compression, outputFolder, buildInfo, writeInfo, out result, useCache, progressTracker);
                    if (exitCode < BuildPipelineCodes.Success)
                    {
                        return(exitCode);
                    }

                    if (PostBuildWriting != null)
                    {
                        exitCode = PostBuildWriting.Invoke(buildInfo, writeInfo, result, callbackUserData);
                        if (exitCode < BuildPipelineCodes.Success)
                        {
                            return(exitCode);
                        }
                    }
                }
            }

            buildTimer.Stop();
            if (exitCode >= BuildPipelineCodes.Success)
            {
                BuildLogger.Log("Build Asset Bundles successful in: {0:c}", buildTimer.Elapsed);
            }
            else if (exitCode == BuildPipelineCodes.Canceled)
            {
                BuildLogger.LogWarning("Build Asset Bundles canceled in: {0:c}", buildTimer.Elapsed);
            }
            else
            {
                BuildLogger.LogError("Build Asset Bundles failed in: {0:c}. Error: {1}.", buildTimer.Elapsed, exitCode);
            }

            return(exitCode);
        }
        public static void BuildAssetBundles()
        {
            var buildTimer = new Stopwatch();

            buildTimer.Start();

            var input       = BuildInterface.GenerateBuildInput();
            var settings    = GenerateBuildSettings();
            var compression = BuildCompression.DefaultUncompressed;

            // Rebuild sprite atlas cache for correct dependency calculation & writting
            Packer.RebuildAtlasCacheIfNeeded(settings.target, true, Packer.Execution.Normal);

            // Generate command set
            BuildCommandSet commands;
            var             packer = new Unity5Packer();

            if (!packer.Convert(input, settings.target, out commands))
            {
                return;
            }

            //DebugPrintCommandSet(ref commands);

            // Calculate dependencies
            BuildCommandSet depCommands;
            var             dependencyCalculator = new Unity5DependencyCalculator();

            if (!dependencyCalculator.Convert(commands, out depCommands))
            {
                return;
            }

            DebugPrintCommandSet(ref depCommands);

            // TODO: implement incremental building when LLAPI supports it

            // Write out resource files
            BuildOutput output;
            var         resourceWriter = new ResourceWriter();

            if (!resourceWriter.Convert(depCommands, settings, out output))
            {
                return;
            }

            // Archive and compress resource files
            uint[] crc;
            var    archiveWriter = new ArchiveWriter();

            if (!archiveWriter.Convert(output, compression, settings.outputFolder, out crc))
            {
                return;
            }

            // Generate Unity5 compatible manifest files
            string[] manifestfiles;
            var      manifestWriter = new Unity5ManifestWriter();

            if (!manifestWriter.Convert(depCommands, output, crc, settings.outputFolder, out manifestfiles))
            {
                return;
            }

            buildTimer.Stop();
            BuildLogger.Log("Build Asset Bundles complete in: {0:c}", buildTimer.Elapsed);
        }
コード例 #10
0
    //-------------------------------------------------------------------------------------------------------------------------
    public static void Build(string config, string log_filename, BuildTarget target, string output)
    {
        BuildLogger logger = new BuildLogger(log_filename, false);

        logger.Log("Building Platform: " + target.ToString());
        logger.Log("Building Config:   " + config);
        logger.Log("");

        string[] level_list = FindScenes();
        logger.Log("Scenes to be processed: " + level_list.Length);

        foreach (string s in level_list)
        {
            string cutdown_level_name = s.Remove(s.IndexOf(".unity"));
            logger.Log("   " + cutdown_level_name);
        }

        // Make sure the paths exist before building.
        try
        {
            Directory.CreateDirectory(output);
        }
        catch
        {
            logger.Log("Failed to create directories: " + output);
        }

        string results = "";

        try
        {
            results = BuildPipeline.BuildPlayer(level_list, output, target, BuildOptions.None);
        }
        catch
        {
            logger.Log("Errors Found.");
            logger.Log(results);
            logger.Close();
        }

        logger.Log("");

        if (results.Length == 0)
            logger.Log("No Build Errors");
        else
        {
            logger.Log("Errors Found.");
            logger.Log(results);
        }

        logger.Close();
    }