private void InitializeClient() { var arguments = LaunchArguments.GetArguments(); var environment = CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.Environment, string.Empty); if (string.IsNullOrEmpty(environment)) { environment = PlayerPrefs.GetString(RuntimeConfigNames.Environment, string.Empty); } else { PlayerPrefs.SetString(RuntimeConfigNames.Environment, environment); } if (!string.IsNullOrEmpty(environment)) { ShouldConnectLocally = environment == RuntimeConfigDefaults.LocalEnvironment; } if (ShouldConnectLocally) { IpAddress = GetHostIp(); PlayerPrefs.SetString(HostIpPlayerPrefsKey, IpAddress); } else { PlayerPrefs.DeleteKey(HostIpPlayerPrefsKey); } PlayerPrefs.Save(); }
/// <summary> /// Extracts the Ip address that should be used to connect via the receptionist. The order is as follows: /// 1. Try to extract the ip address from command line arguments passed in. This currently only works for Android. /// 2. If we are running on an Android Emulator: Use the Ip address necessary to connect locally. /// 3. If we are on a physical device (Android & iOS): Try to extract the value from the stored player preferences. /// 4. Check if we stored anything inside the IpAddress field and use it, if we have. /// 5. Return the default ReceptionistHost (localhost). /// </summary> /// <returns></returns> private string GetHostIp() { var arguments = LaunchArguments.GetArguments(); var hostIp = CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.ReceptionistHost, string.Empty); if (!string.IsNullOrEmpty(hostIp)) { return(hostIp); } if (Application.isMobilePlatform) { switch (DeviceInfo.ActiveDeviceType) { case MobileDeviceType.Virtual: #if UNITY_ANDROID return(DeviceInfo.AndroidEmulatorDefaultCallbackIp); #else break; #endif case MobileDeviceType.Physical: return(PlayerPrefs.GetString(HostIpPlayerPrefsKey, IpAddress)); } } if (!string.IsNullOrEmpty(IpAddress)) { return(IpAddress); } return(RuntimeConfigDefaults.ReceptionistHost); }
private string GetReceptionistHostFromArguments() { var arguments = LaunchArguments.GetArguments(); var hostIp = CommandLineUtility.GetCommandLineValue(arguments, RuntimeConfigNames.ReceptionistHost, string.Empty); return(hostIp); }