Ejemplo n.º 1
0
        protected override RunResult OnRun(RunContext context)
        {
            AndroidClassicPipelineShared.SetupPlayerConnection(context);

#if UNITY_ANDROID
            var artifact = context.GetBuildArtifact <AndroidArtifact>();
            var fileName = artifact.OutputTargetFile.FullName;
            if (Path.GetExtension(fileName) != ".apk")
            {
                return(context.Failure($"Expected .apk in path, but got '{fileName}'."));
            }

            var path = $"\"{Path.GetFullPath(fileName)}\"";
            var adb  = ADB.GetInstance();
            try
            {
                EditorUtility.DisplayProgressBar("Installing", $"Installing {path}", 0.3f);
                adb.Run(new[] { "install", "-r", "-d", path }, $"Failed to install '{fileName}'");
            }
            catch (Exception ex)
            {
                return(context.Failure(ex));
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            UnityEngine.Debug.Log($"{path} successfully installed.");

            var applicationIdentifier = context.GetComponentOrDefault <ApplicationIdentifier>();
            var runTarget             = $"\"{applicationIdentifier.PackageName}/com.unity3d.player.UnityPlayerActivity\"";
            try
            {
                EditorUtility.DisplayProgressBar("Launching", $"Launching {runTarget}", 0.6f);
                adb.Run(new[]
                {
                    "shell", "am", "start",
                    "-a", "android.intent.action.MAIN",
                    "-c", "android.intent.category.LAUNCHER",
                    "-f", "0x10200000",
                    "-S",
                    "-n", runTarget
                }, $"Failed to launch {runTarget}");
            }
            catch (Exception ex)
            {
                return(context.Failure(ex));
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
            UnityEngine.Debug.Log($"{runTarget} successfully launched.");

            return(context.Success(new AndroidRunInstance()));
#else
            return(context.Failure("Active Editor platform has to be set to Android."));
#endif
        }
        internal static void SetupPlayerConnection(RunContext context)
        {
            var config = context.GetComponentOrDefault <ClassicBuildProfile>().Configuration;

            if (config == BuildType.Debug || config == BuildType.Develop)
            {
                AndroidClassicPipelineShared.ClearForwardTunneling();
                AndroidClassicPipelineShared.ClearReverseTunneling();
                if (context.TryGetComponent <PlayerConnectionSettings>(out PlayerConnectionSettings value) && value.Mode == PlayerConnectionInitiateMode.Connect)
                {
                    AndroidClassicPipelineShared.SetupReverseTunneling();
                }
                else
                {
                    var packageName = context.GetComponentOrDefault <ApplicationIdentifier>().PackageName;
                    AndroidClassicPipelineShared.SetupForwardTunneling(packageName);
                }
            }