Exemplo n.º 1
0
        private Dictionary <string, DeploymentTargetLogger> GetDeploymentTargetLoggers(BuildTarget buildTarget)
        {
            DeploymentTargetManager deploymentTargetManager;

            try
            {
                deploymentTargetManager = DeploymentTargetManager.CreateInstance(EditorUserBuildSettings.activeBuildTargetGroup, buildTarget);
            }
            catch (NotSupportedException ex)
            {
                Debug.Log(ex.Message);
                Debug.Log("Deployment target logger not initialised");
                return(null);
            }

            var targets = deploymentTargetManager.GetKnownTargets();
            var loggers = new Dictionary <string, DeploymentTargetLogger>();

            foreach (var target in targets)
            {
                if (target.status != DeploymentTargetStatus.Ready)
                {
                    continue;
                }

                var logger = deploymentTargetManager.GetTargetLogger(target.id);
                logger.Clear();
                loggers.Add(target.id, logger);
            }

            return(loggers);
        }
Exemplo n.º 2
0
        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)
                {
                    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
                        {
                            var manager         = DeploymentTargetManager.CreateInstance(targetGroup, buildReport.summary.platform);
                            var buildProperties = BuildProperties.GetFromBuildReport(buildReport);
                            manager.LaunchBuildOnTarget(buildProperties, 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));
            }
        }