コード例 #1
0
        private static void Zip(string zipAbsolutePath, string basePath, PlayerCompression useCompression)
        {
            var zipFileFullPath = Path.GetFullPath(zipAbsolutePath);

            using (new ShowProgressBarScope($"Package {basePath}"))
            {
                RedirectedProcess.Run(Common.SpatialBinary, "file", "zip", $"--output=\"{zipFileFullPath}\"",
                                      $"--basePath=\"{Path.GetFullPath(basePath)}\"", "\"**\"",
                                      $"--compression={useCompression == PlayerCompression.Enabled}");
            }
        }
コード例 #2
0
        private static string ZipArgs(string basePath, string zipFileFullPath,
                                      PlayerCompression useCompression)
        {
            var filePattern = "**";
            var subFolder   = "";

            return(string.Format(
                       "file zip --output=\"{0}\" --basePath=\"{1}\" --relativePath=. \"{2}\" --compression={3}",
                       zipFileFullPath,
                       Path.GetFullPath(basePath),
                       PathUtil.EnsureTrailingSlash(subFolder) + filePattern,
                       useCompression == PlayerCompression.Enabled));
        }
コード例 #3
0
        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
            }
        }
コード例 #4
0
 internal void PackagePlayer(IPlayerBuildEvents events, string spatialPath, PlayerCompression useCompression)
 {
     events.BeginPackage(WorkerType, BuildTarget, config, PackagePath);
     SpatialZip.Zip(spatialPath, ZipPath, PackagePath, ".", "**", useCompression);
 }
コード例 #5
0
 public void PackagePlayer(string spatialPath, PlayerCompression useCompression)
 {
     PackagePlayer(PlayerBuildEvents, spatialPath, useCompression);
 }
コード例 #6
0
 private static string ZipArgs(string basePath, string subFolder, string filePattern, string zipFileFullPath, PlayerCompression useCompression)
 {
     filePattern = string.IsNullOrEmpty(filePattern) ? "**" : filePattern;
     return(string.Format("{0} --output=\"{1}\" --basePath=\"{2}\" --relativePath=. \"{3}\" --compression={4}",
                          ZipSubCommand,
                          zipFileFullPath,
                          Path.GetFullPath(basePath),
                          PathUtil.EnsureTrailingSlash(subFolder) + filePattern,
                          useCompression == PlayerCompression.Enabled));
 }
コード例 #7
0
        internal static void Zip(string spatialCommand, string zipAbsolutePath, string basePath, string subFolder, string filePattern, PlayerCompression useCompression)
        {
            var zipFileFullPath = Path.GetFullPath(zipAbsolutePath);
            var startInfo       = new ProcessStartInfo
            {
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                FileName       = spatialCommand,
                Arguments      = ZipArgs(basePath, subFolder, filePattern, zipFileFullPath, useCompression),
                CreateNoWindow = true
            };

            var zipProcess = SpatialRunner.RunCommandWithSpatialInThePath(spatialCommand, startInfo);

            var output = zipProcess.StandardOutput.ReadToEnd();
            var errOut = zipProcess.StandardError.ReadToEnd();

            zipProcess.WaitForExit();
            if (zipProcess.ExitCode != 0)
            {
                throw new Exception(string.Format("Could not package the folder {0}/{1}. The following error occurred: {2}, {3}\n", basePath, subFolder, output, errOut));
            }
        }
コード例 #8
0
        private static void ZipThroughSpatial(string zipAbsolutePath, string basePath, PlayerCompression useCompression)
        {
            var zipFileFullPath = Path.GetFullPath(zipAbsolutePath);

            SpatialCommandRunner.RunSpatialCommand(ZipArgs(basePath, zipFileFullPath, useCompression),
                                                   string.Format("package the folder {0}", basePath));
        }
コード例 #9
0
 internal static void Zip(string zipAbsolutePath, string basePath, PlayerCompression compression)
 {
     ZipThroughSpatial(zipAbsolutePath, basePath, compression);
 }