Пример #1
0
 static UnityBuildActions()
 {
     Settings  = new UnityEditorToolSettings();
     Arguments = new UnityEditorToolArguments();
     Arguments.BuildTargetExecutable = "Game";
     Arguments.BuildTargetPath       = "bin";
 }
Пример #2
0
    public static UnityEditorToolArguments MergeArguments(UnityEditorToolArguments arguments,
                                                          UnityEditorToolArguments globalDefaults)
    {
        arguments = arguments ?? new UnityEditorToolArguments();

        var retval = new UnityEditorToolArguments();

        retval.BatchMode             = arguments.BatchMode ?? globalDefaults.BatchMode;
        retval.Quit                  = arguments.Quit ?? globalDefaults.Quit;
        retval.BuildTarget           = arguments.BuildTarget ?? globalDefaults.BuildTarget;
        retval.BuildTargetExecutable = arguments.BuildTargetExecutable ?? globalDefaults.BuildTargetExecutable;
        retval.BuildTargetPath       = arguments.BuildTargetPath ?? globalDefaults.BuildTargetPath;

        var dict = retval.customArguments as IDictionary <string, object>;

        foreach (var k in arguments.customArguments)
        {
            dict.Add(k);
        }
        foreach (var k in globalDefaults.customArguments)
        {
            dict.Add(k);
        }

        retval.ExecuteMethod = arguments.ExecuteMethod ?? globalDefaults.ExecuteMethod;
        retval.LogFile       = arguments.LogFile ?? globalDefaults.LogFile;
        retval.ProjectPath   = arguments.ProjectPath ?? globalDefaults.ProjectPath;
        return(retval);
    }
Пример #3
0
 private void WarnIfLogFileNotSet(UnityEditorToolArguments arguments)
 {
     if (arguments.LogFile == null)
     {
         log.Warning("LogFile is not specified by Unity Editor arguments.");
         log.Warning("Please specify it for ability to forward Unity log to console.");
     }
 }
Пример #4
0
    internal ProcessArgumentBuilder CustomizeCommandLineArguments(UnityEditorToolArguments args,
                                                                  ProcessArgumentBuilder builder,
                                                                  ICakeEnvironment environment)
    {
        if (args.BatchMode == null || args.BatchMode.Value)
        {
            builder.Append("-batchmode");
        }

        if (args.BuildTarget != null && args.BuildTarget != UnityBuildTargetType.None && args.BuildTargetPath != null)
        {
            var filePath = FilePath.FromString((args.BuildTargetExecutable ?? "Game") + SuffixFor(args.BuildTarget.Value));
            var path     = args.BuildTargetPath.CombineWithFilePath(filePath);

            builder
            .Append("-build" + args.BuildTarget)
            .AppendQuoted(path.MakeAbsolute(environment).FullPath);
        }

        if (args.ExecuteMethod != null)
        {
            builder
            .Append("-executeMethod")
            .Append(args.ExecuteMethod);
        }

        if (args.LogFile != null)
        {
            builder
            .Append("-logFile")
            .AppendQuoted(args.LogFile.FullPath);
        }

        if (args.ProjectPath != null)
        {
            builder
            .Append("-projectPath")
            .AppendQuoted(args.ProjectPath.MakeAbsolute(environment).FullPath);
        }

        if (args.Quit == null || args.Quit.Value)
        {
            builder
            .Append("-quit");
        }

        foreach (var customArgument in args.Custom)
        {
            builder.Append(string.Format("--{0}={1}", customArgument.Key, customArgument.Value));
        }

        return(builder);
    }
Пример #5
0
    private void RunWithRealTimeLog(UnityEditorToolArguments arguments, UnityEditorToolSettings settings)
    {
        var logForwardCancellation = new CancellationTokenSource();

        var process = RunProcess(arguments, settings);

        System.Threading.Tasks.Task.Run(() =>
        {
            process.WaitForExit();
            logForwardCancellation.Cancel();
        });

        ForwardLogFileToOutputUntilCancel(arguments.LogFile, logForwardCancellation.Token);

        ProcessExitCode(process.GetExitCode());
    }
Пример #6
0
    public void RunUnityEditor(FilePath unityEditorPath, UnityEditorToolArguments arguments, UnityEditorToolSettings settings)
    {
        if (unityEditorPath != null)
        {
            settings          = new UnityEditorToolSettings(settings);
            settings.ToolPath = unityEditorPath;
        }

        ErrorIfRealTimeLogSetButLogFileNotSet(settings, arguments);
        WarnIfLogFileNotSet(arguments);

        if (settings.RealTimeLog.GetValueOrDefault() && arguments.LogFile != null)
        {
            RunWithRealTimeLog(arguments, settings);
        }
        else
        {
            RunWithLogForwardOnError(arguments, settings);
        }
    }
Пример #7
0
    private void RunWithLogForwardOnError(UnityEditorToolArguments arguments, UnityEditorToolSettings settings)
    {
        try
        {
            Run(arguments, settings);
        }
        catch
        {
            if (arguments.LogFile == null)
            {
                log.Error("Execution of Unity Editor failed.");
                log.Warning("Cannot forward log file to output because LogFile argument is missing.");
            }
            else
            {
                log.Error("Execution of Unity Editor failed.");
                log.Error("Please analyze log below for the reasons of failure.");
                ForwardLogFileToOutputInOnePass(arguments.LogFile);
            }

            throw;
        }
    }
Пример #8
0
 public void RunUnityEditor(UnityEditorToolArguments arguments, UnityEditorToolSettings settings)
 {
     RunUnityEditor((FilePath)null, arguments, settings);
 }
Пример #9
0
 public void RunUnityEditor(UnityEditorDescriptor unityEditor, UnityEditorToolArguments arguments, UnityEditorToolSettings settings)
 {
     RunUnityEditor(unityEditor.Path, arguments, settings);
 }
Пример #10
0
 private void ErrorIfRealTimeLogSetButLogFileNotSet(UnityEditorToolSettings settings, UnityEditorToolArguments arguments)
 {
     if (settings.RealTimeLog.GetValueOrDefault() && arguments.LogFile == null)
     {
         log.Error("Cannot forward log in real time because LogFile is not specified.");
     }
 }
Пример #11
0
    private IProcess RunProcess(UnityEditorToolArguments args, UnityEditorToolSettings settings)
    {
        var argumentBuilder = CustomizeCommandLineArguments(args, new ProcessArgumentBuilder(), environment);

        return(RunProcess(settings, argumentBuilder));
    }
Пример #12
0
    private void Run(UnityEditorToolArguments args, UnityEditorToolSettings settings)
    {
        var argumentBuilder = CustomizeCommandLineArguments(args, new ProcessArgumentBuilder(), environment);

        Run(settings, argumentBuilder);
    }
Пример #13
0
    public static void UnityEditor(FilePath unityEditor = null, UnityEditorToolArguments arguments = null)
    {
        var tool = new UnityEditorTool(Context.FileSystem, Context.Environment, Context.ProcessRunner, Context.Tools, Context.Log);

        tool.RunUnityEditor(unityEditor, UnityEditorToolArguments.MergeArguments(arguments, Arguments), Settings);
    }