/// <summary>
        ///     Cleans player build directories and assemblies.
        /// </summary>
        public static void CleanPlayers()
        {
            Debug.LogFormat("Starting SpatialOS Unity Clean");

            if (!string.IsNullOrEmpty(Target))
            {
                Debug.LogFormat("Cleaning target '{0}', available targets are '{1}', '{2}'", Target, UnityPlayerBuilders.DeploymentTarget, UnityPlayerBuilders.DevelopmentTarget);
            }

            var workersToClean = GetWorkerTypesToBuild();

            foreach (var playerTarget in workersToClean)
            {
                Debug.LogFormat("Cleaning player {0}", playerTarget);
            }

            RunIf(UnityPlayerBuilders.DevelopmentTarget, () => CleanPlayerAssemblies(UnityPlayerBuilders.DevelopmentPlayerBuilders(workersToClean)));
            RunIf(UnityPlayerBuilders.DeploymentTarget, () => CleanPlayerAssemblies(UnityPlayerBuilders.DeploymentPlayerBuilders(workersToClean)));

            Debug.LogFormat("Finished SpatialOS Unity Clean");
        }
        /// <summary>
        ///     Performs default build steps for a Unity worker.
        /// </summary>
        private static void DefaultBuild()
        {
            Debug.LogFormat("Starting SpatialOS Build");

            if (!string.IsNullOrEmpty(Target))
            {
                Debug.LogFormat(@"Building target ""{0}"", available targets are ""{1}"", ""{2}""", Target, UnityPlayerBuilders.DeploymentTarget, UnityPlayerBuilders.DevelopmentTarget);
            }

            EntityPrefabExportMenus.ExportAllEntityPrefabs();

            var workersToBuild = GetWorkerTypesToBuild();

            foreach (var playerTarget in workersToBuild)
            {
                Debug.LogFormat(@"Building player {0}", playerTarget);
            }

            RunIf(UnityPlayerBuilders.DevelopmentTarget, () => UnityPlayerBuilders.BuildDevelopmentPlayers(workersToBuild));
            RunIf(UnityPlayerBuilders.DeploymentTarget, () => UnityPlayerBuilders.BuildDeploymentPlayers(workersToBuild));

            Debug.LogFormat("Finished SpatialOS Build");
        }
        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();
            }
        }