Example #1
0
        public void Run(Job[] jobs, bool restoreActiveBuildTarget = true, UnityEngine.Object context = null)
        {
            if (jobs == null || jobs.Length == 0)
            {
                DestroyImmediate(this);
                throw new Exception($"Trimmer BuildRunner: No jobs given.");
            }

            EnsureNotRunning();

            var results = new ProfileBuildResult[jobs.Length];

            for (int i = 0; i < jobs.Length; i++)
            {
                var job = jobs[i];
                if ((job.profile == null || job.target == 0 || job.target == BuildTarget.NoTarget) && job.distro == null)
                {
                    DestroyImmediate(this);
                    throw new Exception($"Trimmer BuildRunner: Invalid job at index {i}: Profile or target or distro not set ({job.profile} / {job.target} / {job.distro})");
                }
                results[i].profile = job.profile;
            }

            Current               = this;
            this.jobs             = jobs;
            this.results          = results;
            restoreActiveTargetTo = EditorUserBuildSettings.activeBuildTarget;
            jobIndex              = -1;

            token         = TaskToken.Start(context?.name ?? "Trimmer", options: Progress.Options.Synchronous);
            token.context = context;
            Progress.SetPriority(token.taskId, Progress.Priority.High);
            token.Report(0, jobs.Length);

            //Debug.Log($"Trimmer BuildRunner: Got jobs:\n{string.Join("\n", jobs.Select(j => $"- {j.profile?.name ?? "<none>"} {j.target}"))}");

            ContinueWith(ContinueTask.NextJob);
        }