コード例 #1
0
        public static void Launch(bool shouldConnectLocally, string deviceId, string runtimeIp, bool useSimulator)
        {
            try
            {
                EditorUtility.DisplayProgressBar("Preparing your Mobile Client", "Preparing launch arguments", 0.0f);

                if (!TryGetXCTestRunPath(useSimulator, out var xcTestRunPath))
                {
                    Debug.LogError(
                        "Unable to find a xctestrun file for the correct architecture. Did you build your client using the correct Target SDK? " +
                        "Go to Project Settings > Player > iOS > Other Settings > Target SDK to select the correct one before building your iOS worker.");
                    return;
                }

                var arguments = MobileLaunchUtils.PrepareArguments(shouldConnectLocally, runtimeIp);

                if (!TryModifyEnvironmentVariables(xcTestRunPath, arguments))
                {
                    Debug.LogError($"Was unable to read and modify {xcTestRunPath}.");
                    return;
                }

                if (useSimulator)
                {
                    EditorUtility.DisplayProgressBar("Launching Mobile Client", "Start iOS Simulator", 0.5f);

                    // Start simulator
                    if (RedirectedProcess.Command("xcrun")
                        .WithArgs("instruments", "-w", deviceId, "-t", "Blank")
                        .Run() != 0)
                    {
                        Debug.LogError("Was unable to start iOS Simulator.");
                        return;
                    }
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Installing your app", 0.7f);

                if (!TryLaunchApplication(deviceId, xcTestRunPath))
                {
                    Debug.LogError("Failed to start app on iOS device.");
                }

                EditorUtility.DisplayProgressBar("Launching Mobile Client", "Done", 1.0f);
            }
            finally
            {
                var traceDirectories = Directory
                                       .GetDirectories(Path.Combine(Application.dataPath, ".."), "*.trace")
                                       .Where(s => s.EndsWith(".trace"));
                foreach (var directory in traceDirectories)
                {
                    Directory.Delete(directory, true);
                }

                EditorUtility.ClearProgressBar();
            }
        }
コード例 #2
0
        public static void Launch(bool shouldConnectLocally, string runtimeIp)
        {
            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(Common.BuildScratchDirectory, out var apkPath))
                {
                    Debug.LogError($"Could not find a built out Android binary in \"{Common.BuildScratchDirectory}\" 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);

                var arguments = MobileLaunchUtils.PrepareArguments(shouldConnectLocally, runtimeIp);

                // 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}\\\"")
                .InDirectory(Path.GetFullPath(Path.Combine(Application.dataPath, "..")))
                .Run();

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