Пример #1
0
        private static void BuildPlayers(string target)
        {
            var stopWatch = new System.Diagnostics.Stopwatch();

            stopWatch.Start();

            try
            {
                SimpleBuildSystem.WorkersToBuild = SimpleBuildSystem.AllWorkerTypes;
                SimpleBuildSystem.Target         = target;
                SimpleBuildSystem.Build();
            }
            finally
            {
                SimpleBuildSystem.WorkersToBuild = null;
                SimpleBuildSystem.Target         = null;

                stopWatch.Stop();
            }
        }
        private static void BuildPlayers(IList <UnityPlayerBuilder> playerBuilders, IList <string> selectedWorkerTypes, PlayerCompression compression)
        {
            PrepareWorkerAssembly(selectedWorkerTypes);

            var playerBuildEvents = SimpleBuildSystem.CreatePlayerBuildEventsAction();

            var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget;

            try
            {
                EditorApplication.LockReloadAssemblies();
                playerBuildEvents.BeginBuild();

                var exceptions = 0;
                var threads    = new List <Thread>();

                var spatialPath = SpatialCommand.SpatialPath;

                foreach (var playerBuilder in playerBuilders)
                {
                    playerBuilder.PlayerBuildEvents = playerBuildEvents;

                    playerBuilder.Clean();
                    playerBuilder.BuildPlayer();
                    var builder = playerBuilder;

                    var thread = new Thread(() =>
                    {
                        try
                        {
#pragma warning disable 0618 // Type or member is obsolete
                            builder.PackagePlayer(spatialPath, compression);
#pragma warning restore 0618 // Type or member is obsolete
                        }
                        catch (Exception e)
                        {
                            Debug.LogError(e);
                            Interlocked.Increment(ref exceptions);
                            throw;
                        }
                    });
                    thread.Start();
                    threads.Add(thread);
                }

                try
                {
                    for (var i = 0; i < threads.Count; ++i)
                    {
                        EditorUtility.DisplayProgressBar("Packaging players", "Packaging and zipping players. This may take a while.", (float)i / threads.Count);
                        threads[i].Join();
                    }
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }

                if (exceptions > 0)
                {
                    throw new Exception(string.Format("Building {0} of the players failed. Please look at logs.", exceptions));
                }

                Debug.Log("Finished building players.");
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
                playerBuildEvents.EndBuild();
#pragma warning disable 618
                EditorUserBuildSettings.SwitchActiveBuildTarget(currentBuildTarget);
#pragma warning restore 618
            }
        }
Пример #3
0
 public static void CleanAllPlayers()
 {
     SimpleBuildSystem.CleanPlayers();
 }
        internal static void OnScriptsReloaded()
        {
            if (!UnityPlayerBuilderMenu.IsAutopatchEnabled())
            {
                return;
            }

            if (!Directory.Exists(EditorPaths.AssetDatabaseDirectory))
            {
                return;
            }

            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            // Skip repackaging during command line builds, since users are explicitly building a set of players anyway.
            if (Environment.GetCommandLineArgs().Select(s => s.ToLowerInvariant()).Contains("-batchmode"))
            {
                Debug.Log("Skipping auto-patching in batchmode");
                return;
            }

            try
            {
                EditorApplication.LockReloadAssemblies();

                var generatedCodeSourcePaths = Directory.GetFiles(EditorPaths.AssetDirectory, "*Generated.Code.dll", SearchOption.AllDirectories);
                var scriptPaths = Directory.GetFiles(EditorPaths.ScriptAssembliesDirectory, "*Assembly-*.dll", SearchOption.AllDirectories).Where(p => !p.Contains("-Editor"));

                var allPaths = generatedCodeSourcePaths.Union(scriptPaths).Select <string, string>(Path.GetFullPath).ToList();

                var developmentPlayerBuilders =
                    UnityPlayerBuilders.DevelopmentPlayerBuilders(SimpleBuildSystem.GetWorkerTypesToBuild());

                var deploymentPlayerBuilders =
                    UnityPlayerBuilders.DeploymentPlayerBuilders(SimpleBuildSystem.GetWorkerTypesToBuild());

                var allPlayerBuilders = developmentPlayerBuilders
                                        .Union(deploymentPlayerBuilders)
                                        .Distinct(new CompareBuilders()).ToList();

                var playerBuildEvents = SimpleBuildSystem.CreatePlayerBuildEventsAction();

                foreach (var builder in allPlayerBuilders)
                {
                    // No point in patching + packaging players that have not been built yet.
                    if (builder.AssemblyDirectoryEmpty())
                    {
                        continue;
                    }

                    Debug.LogFormat("Auto-patching {0} files in {1} {2}", allPaths.Count, builder.BuildTarget, builder.WorkerType);

                    foreach (var sourcePath in allPaths)
                    {
                        builder.PatchAssembly(sourcePath);
                    }

                    builder.PackagePlayer(playerBuildEvents, SpatialCommand.SpatialPath, PlayerCompression.Disabled);
                }
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }
        }