public void UpdateUserData(Dictionary <string, string> data, UserDataPermission permission) { if (!this.initialized) { return; } base.StartCoroutine(this.UpdateUserDataInChunks(data, permission)); }
public IEnumerator LogPlayerData(Dictionary <string, string> pairs, UserDataPermission permission = UserDataPermission.Private) { UpdateUserDataRequest req = new UpdateUserDataRequest(); { req.Data = pairs; req.Permission = permission; }; Action <Action <UpdateUserDataResult>, Action <PlayFabError> > apiCall = (onsuccess, onError) => { PlayFabClientAPI.UpdateUserData(req, onsuccess, onError); }; yield return(ExecuteApiCallWithRetry(apiCall)); }
private void AddToPendingCloudCache(Dictionary <string, string> data, UserDataPermission permission) { if (this.pendingCloudData == null) { this.pendingCloudData = new Dictionary <string, PendingData>(); } foreach (KeyValuePair <string, string> keyValuePair in data) { if (this.pendingCloudData.ContainsKey(keyValuePair.Key)) { this.pendingCloudData[keyValuePair.Key].SetData(keyValuePair.Value, permission); } else { this.pendingCloudData.Add(keyValuePair.Key, new PendingData(keyValuePair.Value, permission)); } } }
private bool UpdateDictionaryChunk(int maxChunkSize, UserDataPermission newPermission) { if (this.IsSendingChunkCache) { if (this.sendCache.Count == 0) { this.IsSendingChunkCache = false; } return(this.pendingCloudData.Count > 0); } this.sendCachePermission = newPermission; this.IsSendingChunkCache = true; this.sendCache.Clear(); Dictionary <string, PendingData> .KeyCollection keys = this.pendingCloudData.Keys; string[] array = new string[this.pendingCloudData.Count]; keys.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { if (i >= maxChunkSize || this.pendingCloudData[array[i]].Permission != this.sendCachePermission) { break; } this.sendCache.Add(array[i], this.pendingCloudData[array[i]].Data); this.pendingCloudData.Remove(array[i]); } if (this.sendCache.Count > 0) { UpdateUserDataRequest request = new UpdateUserDataRequest { Data = this.sendCache, Permission = new UserDataPermission?(this.sendCachePermission) }; PlayFabClientAPI.UpdateUserData(request, new Action <UpdateUserDataResult>(this.OnUserDataUpdated), new Action <PlayFabError>(this.OnUserDataUpdateError), null, null); } else { this.IsSendingChunkCache = false; } return(this.pendingCloudData.Count > 0); }
private IEnumerator UpdateUserDataInChunks(Dictionary <string, string> data, UserDataPermission permission) { this.AddToPendingCloudCache(data, permission); if (this.IsSendingChunkCache || this.waitingForMoreData) { if (this.waitingForMoreData) { this.waitForSeconds = 2f; } yield break; } this.waitingForMoreData = true; this.waitForSeconds = 2f; while (this.waitForSeconds > 0f) { this.waitForSeconds -= GameTime.RealTimeDelta; yield return(null); } this.waitingForMoreData = false; EventManager.Send(new PlayFabEvent(PlayFabEvent.Type.UserDataUploadStarted)); UserDataPermission sendPermission = UserDataPermission.Private; while (this.Initialized && this.UpdateDictionaryChunk(10, sendPermission)) { while (this.IsSendingChunkCache) { yield return(null); } if (sendPermission == UserDataPermission.Private) { sendPermission = UserDataPermission.Public; } else { sendPermission = UserDataPermission.Private; } } EventManager.Send(new PlayFabEvent(PlayFabEvent.Type.UserDataUploadEnded)); yield break; }
public void SetData(string data, UserDataPermission permission) { this.Data = data; this.Permission = permission; }
public PendingData(string data, UserDataPermission permission) { this.SetData(data, permission); }
public void LogPlayerDataAsync(string key, string value, UserDataPermission permission = UserDataPermission.Private) { StartCoroutine(LogPlayerData(new Dictionary <string, string> { { key, value } })); }