====== EditorConnection ====== The ''EditionConnection'' class controls the editor-side of the Player/Editor network bridge used for letting the player talk to the editor((running tests, reporting back logs, etc)). ===== Connects fail when using Patch + Run on Android ===== The port used to connect the player to the editor is stored within the Android data files. These are placed in the ''.obb'' file, when Android is in "Split Package" mode. When using Patch and Run, only the code changes are installed to the device. However, this can mean the player uses an old port for trying to connect to the editor. The connection won't succeed. You must either deploy the full obb file to the device, or connect to the player manually using an IP Address. ===== Android Connections ===== Normally calling ''EditorConnection.instance.Initialize()'' is enough to connect to the player, but on Android, there seems to be an additional step needed((this is sourced from the com.unity.test-framework package, in AndroidPlatformSetup.cs)). When the player is listening for a connection, you must use an internal method to connect through the localhost proxy connection. For example: [Button] private void ConnectEditorToAndroidPlayer() { EditorConnection.instance.Initialize(); var connectionResult = -1; var maxTryCount = 10; var tryCount = maxTryCount; while (tryCount-- > 0 && connectionResult == -1) { Debug.Log("Searching for player connection..."); var method = Type.GetType("UnityEditor.EditorConnectionInternal,UnityEditor") .GetMethod("ConnectPlayerProxy", BindingFlags.Static | BindingFlags.Public); connectionResult = (int) method.Invoke(null, new object[] { IPAddress.Loopback.ToString(), 34999 }); // connectionResult = EditorConnectionInternal.ConnectPlayerProxy(IPAddress.Loopback.ToString(), 34999); // connectionResult = EditorConnectionInternal.ConnectPlayerProxy(IPAddress.Loopback.ToString(), 34999); if (EditorUtility.DisplayCancelableProgressBar("Editor Connection", "Connecting to the player", 1 - ((float) tryCount / maxTryCount))) { EditorUtility.ClearProgressBar(); throw new Exception("Cancelled."); } } EditorUtility.ClearProgressBar(); if (connectionResult == -1) throw new Exception( "Timed out trying to connect to the player. Player failed to launch or crashed soon after launching"); }