using System; using Cute; namespace Wizard; public class UserRegionUpdater { private enum UpdateRegionType { CURRENT, INSTALL } private RegionCodeUpdateTask _regionUpdateTask; private UpdateRegionType _updateType = UpdateRegionType.INSTALL; private bool _isUpdateRegion; public UserRegionUpdater() { _regionUpdateTask = new RegionCodeUpdateTask(); } public void UpDateRegion(Action callback) { string value = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.INSTALL_REGION_CODE); string currentRegionStr = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.CURRENT_REGION_CODE); if (string.IsNullOrEmpty(value) && !string.IsNullOrEmpty(currentRegionStr)) { _isUpdateRegion = true; _updateType = UpdateRegionType.INSTALL; } else if (!string.IsNullOrEmpty(currentRegionStr) && value != currentRegionStr) { _isUpdateRegion = true; _updateType = UpdateRegionType.CURRENT; } if (!_isUpdateRegion) { callback(); return; } _regionUpdateTask.SetParameter((int)_updateType); UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(_regionUpdateTask, delegate { PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.INSTALL_REGION_CODE, currentRegionStr); callback(); }, BaseTask.OnRequestFailed, BaseTask.OnFailedErrorCode)); } }