static public void LaunchOnTargets(BuildTargetGroup targetGroup, BuildTarget buildTarget, Build.Reporting.BuildReport buildReport, List <DeploymentTargetId> launchTargets)
{
try
{
// Early out so as not to show/update progressbars unnecessarily
if (buildReport == null || !DeploymentTargetManager.IsExtensionSupported(targetGroup, buildReport.summary.platform))
{
throw new System.NotSupportedException();
}
ProgressHandler progressHandler = new ProgressHandler("Deploying Player",
delegate(string title, string message, float globalProgress)
{
if (EditorUtility.DisplayCancelableProgressBar(title, message, globalProgress))
{
throw new DeploymentOperationAbortedException();
}
}, 0.1f); // BuildPlayer.cpp starts off at 0.1f for some reason
var taskManager = new ProgressTaskManager(progressHandler);
// Launch on all selected targets
taskManager.AddTask(() =>
{
int successfulLaunches = 0;
var exceptions = new List <DeploymentOperationFailedException>();
foreach (var target in launchTargets)
{
try
{
DeploymentTargetManager.LaunchBuildOnTarget(targetGroup, buildReport, target, taskManager.SpawnProgressHandlerFromCurrentTask());
successfulLaunches++;
}
catch (DeploymentOperationFailedException e)
{
exceptions.Add(e);
}
}
foreach (var e in exceptions)
{
UnityEngine.Debug.LogException(e);
}
if (successfulLaunches == 0)
{
// TODO: Maybe more specifically no compatible targets?
throw new NoTargetsFoundException("Could not launch build");
}
});
taskManager.Run();
}
catch (DeploymentOperationFailedException e)
{
UnityEngine.Debug.LogException(e);
EditorUtility.DisplayDialog(e.title, e.Message, "Ok");
}
catch (DeploymentOperationAbortedException)
{
System.Console.WriteLine("Deployment aborted");
}
catch (NoTargetsFoundException)
{
throw new UnityException(string.Format("Could not find any valid targets to launch on for {0}", buildTarget));
}
}