예제 #1
0
        internal virtual List <string> GetCreateArguments()
        {
            var toolsConfig = GdkToolsConfiguration.GetOrCreateInstance();

            var args = new List <string>
            {
                "create",
                $"--deployment_name={Name}",
                $"--launch_json_path=\"{Path.Combine(Tools.Common.SpatialProjectRootDir, LaunchJson)}\"",
                $"--region={Region.ToString()}",
                $"--runtime_version={toolsConfig.RuntimeVersion}"
            };

            if (!string.IsNullOrEmpty(SnapshotPath))
            {
                args.Add($"--snapshot_path=\"{Path.Combine(Tools.Common.SpatialProjectRootDir, SnapshotPath)}\"");
            }

            if (Tags.Count > 0)
            {
                args.Add($"--tags={string.Join(",", Tags)}");
            }

            return(args);
        }
예제 #2
0
        private static string GetHostForEnvironment()
        {
            var toolsConfig = GdkToolsConfiguration.GetOrCreateInstance();

            return(toolsConfig.EnvironmentPlatform == "cn-production"
                ? "https://console.spatialoschina.com"
                : "https://console.improbable.io");
        }
예제 #3
0
        private static void LaunchMobileClient()
        {
            try
            {
                // Find ADB tool
                var sdkRootPath = EditorPrefs.GetString("AndroidSdkRoot");
                if (string.IsNullOrEmpty(sdkRootPath))
                {
                    Debug.LogError($"Could not find Android SDK. Please set the SDK location in your editor preferences.");
                    return;
                }

                var adbPath = Path.Combine(sdkRootPath, "platform-tools", "adb");

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Installing APK", 0.3f);

                // Find apk to install
                if (!TryGetApkPath(AbsoluteApkPath, out var apkPath))
                {
                    Debug.LogError($"Could not find a built out Android binary in \"{AbsoluteApkPath}\" to launch.");
                    return;
                }

                // Ensure an android device/emulator is present
                if (RedirectedProcess.Run(adbPath, "get-state") != 0)
                {
                    Debug.LogError("No Android device/emulator detected.");
                    return;
                }

                // Install apk on connected phone / emulator
                RedirectedProcess.Run(adbPath, "install", "-r", apkPath);

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Launching Client", 0.9f);

                // Optional arguments to be passed, same as standalone
                // Use this to pass through the local ip to connect to
                var runtimeIp = GdkToolsConfiguration.GetOrCreateInstance().RuntimeIp;
                var arguments = new StringBuilder();
                if (!string.IsNullOrEmpty(runtimeIp))
                {
                    arguments.Append($"+{RuntimeConfigNames.ReceptionistHost} {runtimeIp}");
                }

                // Get chosen android package id and launch
                var bundleId = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
                RedirectedProcess.Run(adbPath, "shell", "am", "start", "-S",
                                      "-n", $"{bundleId}/com.unity3d.player.UnityPlayerActivity",
                                      "-e", "\"arguments\"", $"\\\"{arguments.ToString()}\\\"");

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Done", 1.0f);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
        internal virtual List <string> GetCreateArguments()
        {
            var toolsConfig = GdkToolsConfiguration.GetOrCreateInstance();

            var args = new List <string>
            {
                "create",
                $"--deployment_name={Name}",
                $"--launch_json_path=\"{Path.Combine(Common.SpatialProjectRootDir, LaunchJson)}\"",
                $"--runtime_version={toolsConfig.RuntimeVersion}"
            };

            switch (DeploymentLocationType)
            {
            case DeploymentLocationType.Region:
                args.Add($"--region={Region.ToString()}");
                break;

            case DeploymentLocationType.Cluster:
                args.Add($"--cluster={Cluster}");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (!string.IsNullOrEmpty(SnapshotPath))
            {
                args.Add($"--snapshot_path=\"{Path.Combine(Common.SpatialProjectRootDir, SnapshotPath)}\"");
            }

            if (Tags.Count > 0)
            {
                args.Add($"--tags={string.Join(",", Tags)}");
            }

            return(args);
        }
예제 #5
0
        private void OnGUI()
        {
            if (style == null)
            {
                style = new DeploymentLauncherWindowStyle();
            }

            if (launcherConfig == null)
            {
                EditorGUILayout.HelpBox($"Could not find a {nameof(DeploymentLauncherConfig)} instance.\nPlease create one via the Assets > Create > SpatialOS menu.", MessageType.Info);
                return;
            }

            if (projectName == null)
            {
                EditorGUILayout.HelpBox("Could not parse your SpatialOS project name. See the Console for more details", MessageType.Error);
                return;
            }

            using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPos))
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        using (new EditorGUI.DisabledScope(manager.IsActive))
                        {
                            if (GUILayout.Button(style.ProjectRefreshButtonContents, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                            {
                                projectName = GetProjectName();
                                launcherConfig.SetProjectName(projectName);
                                MarkConfigAsDirty();
                            }
                        }

                        EditorGUILayout.LabelField("Project Name", projectName);
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        using (new EditorGUI.DisabledScope(manager.IsActive))
                        {
                            if (GUILayout.Button(style.EditRuntimeVersionButtonContents, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                            {
                                GdkToolsConfigurationWindow.ShowWindow();
                            }
                        }

                        var config = GdkToolsConfiguration.GetOrCreateInstance();

                        EditorGUILayout.LabelField("Runtime Version", config.RuntimeVersion);
                    }

                    CommonUIElements.DrawHorizontalLine(5, style.HorizontalLineColor);

                    launcherConfig.AssemblyConfig = DrawAssemblyConfig(launcherConfig.AssemblyConfig);

                    GUILayout.Label("Deployment Configurations", EditorStyles.boldLabel);

                    for (var index = 0; index < launcherConfig.DeploymentConfigs.Count; index++)
                    {
                        var deplConfig = launcherConfig.DeploymentConfigs[index];
                        var(shouldRemove, updated) = DrawDeploymentConfig(deplConfig);
                        if (shouldRemove)
                        {
                            launcherConfig.DeploymentConfigs.RemoveAt(index);
                            index--;
                        }
                        else
                        {
                            launcherConfig.DeploymentConfigs[index] = updated;
                        }
                    }

                    using (new GUILayout.HorizontalScope())
                    {
                        GUILayout.FlexibleSpace();

                        if (GUILayout.Button("Add new deployment configuration"))
                        {
                            var deploymentConfig = new DeploymentConfig
                            {
                                AssemblyName = launcherConfig.AssemblyConfig.AssemblyName,
                                Deployment   = new BaseDeploymentConfig
                                {
                                    Name = $"deployment_{launcherConfig.DeploymentConfigs.Count}"
                                }
                            };

                            launcherConfig.DeploymentConfigs.Add(deploymentConfig);
                        }
                    }

                    if (launcherConfig.DeploymentConfigs.Count > 0)
                    {
                        using (new GUILayout.HorizontalScope())
                        {
                            selectedDeploymentIndex = EditorGUILayout.Popup("Deployment", selectedDeploymentIndex,
                                                                            launcherConfig.DeploymentConfigs.Select(config => config.Deployment.Name).ToArray());

                            var isValid = IsSelectedValid(launcherConfig.DeploymentConfigs, selectedDeploymentIndex);

                            var hasErrors = isValid && launcherConfig.DeploymentConfigs[selectedDeploymentIndex].GetErrors().Any();

                            using (new EditorGUI.DisabledScope(!isValid || hasErrors || manager.IsActive))
                            {
                                if (GUILayout.Button("Launch deployment"))
                                {
                                    var deplConfig = launcherConfig.DeploymentConfigs[selectedDeploymentIndex];

                                    manager.Launch(deplConfig.ProjectName, deplConfig.AssemblyName, deplConfig.Deployment);

                                    foreach (var simPlayerDepl in deplConfig.SimulatedPlayerDeploymentConfigs)
                                    {
                                        manager.Launch(deplConfig.ProjectName, deplConfig.AssemblyName, simPlayerDepl);
                                    }
                                }
                            }
                        }
                    }

                    CommonUIElements.DrawHorizontalLine(5, style.HorizontalLineColor);
                    GUILayout.Label("Live Deployments", EditorStyles.boldLabel);
                    DrawDeploymentList();

                    scrollPos = scrollView.scrollPosition;

                    if (check.changed)
                    {
                        MarkConfigAsDirty();
                    }

                    if (manager.IsActive)
                    {
                        using (new EditorGUILayout.HorizontalScope())
                        {
                            EditorGUILayout.HelpBox(GetStatusMessage(), MessageType.Info);

                            if (!(manager.CurrentTask is AuthTask) &&
                                GUILayout.Button("Cancel", GUILayout.Height(38), GUILayout.Width(75)))
                            {
                                CancelCurrentTask();
                            }
                        }

                        var rect = EditorGUILayout.GetControlRect(false, 20);
                        style.DrawSpinner(Time.realtimeSinceStartup * 10, rect);

                        Repaint();
                    }
                }
        }
예제 #6
0
        private static void LaunchAndroid(bool shouldConnectLocally)
        {
            try
            {
                // Find ADB tool
                var sdkRootPath = EditorPrefs.GetString("AndroidSdkRoot");
                if (string.IsNullOrEmpty(sdkRootPath))
                {
                    Debug.LogError($"Could not find Android SDK. Please set the SDK location in your editor preferences.");
                    return;
                }

                var adbPath = Path.Combine(sdkRootPath, "platform-tools", "adb");

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Installing APK", 0.3f);

                // Find apk to install
                if (!TryGetApkPath(AbsoluteApkPath, out var apkPath))
                {
                    Debug.LogError($"Could not find a built out Android binary in \"{AbsoluteApkPath}\" to launch.");
                    return;
                }

                // Ensure an android device/emulator is present
                if (RedirectedProcess.Command(adbPath)
                    .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                    .WithArgs("get-state").Run() != 0)
                {
                    Debug.LogError("No Android device/emulator detected.");
                    return;
                }

                // Install apk on connected phone / emulator
                if (RedirectedProcess.Command(adbPath)
                    .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                    .WithArgs("install", "-r", $"\"{apkPath}\"").Run() != 0)
                {
                    Debug.LogError("Failed to install the apk on the device/emulator. If the application is already installed on your device/emulator, " +
                                   "try uninstalling it before launching the mobile client.");
                    return;
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Launching Client", 0.9f);

                // Optional arguments to be passed, same as standalone
                // Use this to pass through the local ip to connect to
                var runtimeIp = GdkToolsConfiguration.GetOrCreateInstance().RuntimeIp;
                var arguments = new StringBuilder();
                if (shouldConnectLocally)
                {
                    if (string.IsNullOrEmpty(runtimeIp))
                    {
                        Debug.LogWarning("No local runtime IP was specified. Ensure you set one in SpatialOS > GDK tools configuration.");
                    }

                    arguments.Append($"+{RuntimeConfigNames.Environment} {RuntimeConfigDefaults.LocalEnvironment} ");
                    arguments.Append($"+{RuntimeConfigNames.ReceptionistHost} {runtimeIp} ");
                }
                else
                {
                    arguments.Append($"+{RuntimeConfigNames.Environment} {RuntimeConfigDefaults.CloudEnvironment} ");
                }

                // Get chosen android package id and launch
                var bundleId = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
                RedirectedProcess.Command(adbPath)
                .WithArgs("shell", "am", "start", "-S", "-n", $"{bundleId}/com.unity3d.player.UnityPlayerActivity",
                          "-e", "\"arguments\"", $"\\\"{arguments.ToString()}\\\"")
                .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                .Run();

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Done", 1.0f);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }