TransactionResult playGameTransaction(MutableData mutableData) { Dictionary <string, object> leaders = mutableData.Value as Dictionary <string, object>; string _color = settingplayer.Instances.Color; //inicializo un tablero de juegos, si no existe; if (leaders == null) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("no se ha creado la sala de juego " + tableroNAme)); return(TransactionResult.Abort()); } Debug.Log(leaders[_color].ToString()); if (leaders[_color].ToString() == UIHandler.instance.usuario.CurrentUser.UserId)//accedo a el valor de color de este usuario y verifico si este color no esta ocupado en el tablero de juego { mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); } else if (leaders[Otrocolor(_color)].ToString() == UIHandler.instance.usuario.CurrentUser.UserId) { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("no ha actualizado el color de jugador a " + _color)); return(TransactionResult.Abort()); } else { UnityMainThreadDispatcher.Instance().Enqueue(IDebugLog("sala de juego: " + tableroNAme + " llena")); return(TransactionResult.Abort()); } // You must set the Value to indicate data at that location has changed. }
//Run a transaction public void RunTransaction(DatabaseReference reference, Action <MutableData> action) { reference.RunTransaction(mutableData => { action(mutableData); return(TransactionResult.Success(mutableData)); }); }
public void OnClickMaxScores() { const int MaxScoreRecordCount = 10; DatabaseReference mDatabaseRef = FirebaseDatabase.DefaultInstance.RootReference; mDatabaseRef.Child("top10").RunTransaction(mutableData => { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } else if (mutableData.ChildrenCount >= MaxScoreRecordCount) { long minScore = long.MaxValue; object minVal = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } long childScore = (long)((Dictionary <string, object>)child)["score"]; if (childScore < minScore) { minScore = childScore; minVal = child; } } if (minScore > score) { // The new score is lower than the existing 5 scores, abort. return(TransactionResult.Abort()); } // Remove the lowest score. leaders.Remove(minVal); } Dictionary <string, object> entryValues = new Dictionary <string, object>(); entryValues.Add("score", score); entryValues.Add("name", userName); entryValues.Add("email", userEmail); leaders.Add(entryValues); mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }).ContinueWith( task => { Debug.Log(string.Format("OnClickMaxScores::IsCompleted:{0} IsCanceled:{1} IsFaulted:{2}", task.IsCompleted, task.IsCanceled, task.IsFaulted)); } ); }
public void saveRankCount(string child) { // reference.Child("rank/count").SetValueAsync(value); Debug.Log("in save rank count function"); FirebaseDatabase.DefaultInstance.GetReference("rank/count").RunTransaction(mutableData => { Debug.Log("inside run transaction "); var c = mutableData.Value; Debug.Log(c); if (c == null) { Debug.Log("null count transaction"); } else { int countVal = int.Parse(c.ToString()); Debug.Log("count tran value : " + c); mutableData.Value = countVal + 1; Debug.Log("count tran value c+1 : " + (countVal + 1)); saveRankerPosition(child, (countVal + 1)); } return(TransactionResult.Success(mutableData)); }); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddProfileTransaction(MutableData mutableData) { List <object> profiles = mutableData.Value as List <object>; if (profiles == null) { profiles = new List <object>(); } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newProfile = new Dictionary <string, object>(); newProfile["named"] = name1; newProfile["company"] = company; newProfile["email"] = email; newProfile["title"] = title; newProfile["phone"] = phone; newProfile["email"] = email; newProfile["webpage"] = webpage; newProfile["linkedin"] = linkedin; newProfile["image"] = image; newProfile["profile"] = profile; profiles.Add(newProfile); // You must set the Value to indicate data at that location has changed. mutableData.Value = profiles; return(TransactionResult.Success(mutableData)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } // If the current list of scores is greater or equal to our maximum allowed number, // we see if the new score should be added and remove the lowest existing score. long childScore = long.MaxValue; object overlap = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } //loop to see if the leaderboard contains the same Email //If a matching Email was found, then set the overlap variable to the found record Dictionary <string, object> dict = (Dictionary <string, object>)child; childScore = (long)((Dictionary <string, object>)child)["score"]; //If the database has this user's email already if (dict.ContainsValue(email)) { //If the score in the database is greater than the new score, then abort if (childScore >= score) { // If the new score is less than the highscore, we abort return(TransactionResult.Abort()); } else { // Otherwise, we remove the current lowest to be replaced with the new score. overlap = child; leaders.Remove(overlap); break; } } } // Now we add the new score as a new entry that contains the name, score and address. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["score"] = score; newScoreMap["name"] = firstName; newScoreMap["email"] = email; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; LeaderboardList = leaders; return(TransactionResult.Success(mutableData)); }
private void UpdateValue(string chapter, int level, Vector2Int pos, int used) { string key = $"{pos.x}:{pos.y}"; FireBaseDatabase.Database.Child(FireBaseSavePaths.HeatMapLocation(chapter, level)).RunTransaction(mutableData => { List <object> storedData = mutableData.Value as List <object>; if (storedData == null) { storedData = new List <object>(); } int newUses = used; foreach (var child in storedData) { var parsedChild = child as Dictionary <string, object>; if (parsedChild == null) { continue; } if (!parsedChild.ContainsKey("Key")) { continue; } if (parsedChild["Key"].ToString() != key) { continue; } if (!parsedChild.ContainsKey("Uses")) { continue; } string data = parsedChild["Uses"].ToString(); int childValue = int.Parse(data); newUses += childValue; storedData.Remove(child); break; } Dictionary <string, object> newMap = new Dictionary <string, object>(); newMap["Key"] = key; newMap["Uses"] = newUses; storedData.Add(newMap); mutableData.Value = storedData; return(TransactionResult.Success(mutableData)); } ); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } else if (mutableData.ChildrenCount < MaxScores) { foreach (var child in leaders) { scoreRet = (string)((Dictionary <string, object>)child)["score"]; Debug.Log(scoreRet); } } else if (mutableData.ChildrenCount >= MaxScores) { // If the current list of scores is greater or equal to our maximum allowed number, // we see if the new score should be added and remove the lowest existing score. long minScore = long.MaxValue; object minVal = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } long childScore = (long)((Dictionary <string, object>)child)["score"]; if (childScore < minScore) { minScore = childScore; minVal = child; } } // If the new score is lower than the current minimum, we abort. if (minScore > score) { return(TransactionResult.Abort()); } // Otherwise, we remove the current lowest to be replaced with the new score. leaders.Remove(minVal); } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["score"] = score; newScoreMap["email"] = email; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
private TransactionResult UpdateTopScore(MutableData md) { int newTopScore = 10; md.Value = new Dictionary <string, object>() { { "topscore", newTopScore } }; return(TransactionResult.Success(md)); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. /* * TransactionResult AddScoreTransaction (MutableData mutableData) * { * List<object> leaders = mutableData.Value as List<object>; * * if (leaders == null) { * leaders = new List<object> (); * } else if (mutableData.ChildrenCount >= MaxScores) { * // If the current list of scores is greater or equal to our maximum allowed number, * // we see if the new score should be added and remove the lowest existing score. * long minScore = long.MaxValue; * object minVal = null; * foreach (var child in leaders) { * if (!(child is Dictionary<string, object>)) * continue; * long childScore = (long)((Dictionary<string, object>)child) ["score"]; * if (childScore < minScore) { * minScore = childScore; * minVal = child; * } * } * // If the new score is lower than the current minimum, we abort. * if (minScore > score) { * return TransactionResult.Abort (); * } * // Otherwise, we remove the current lowest to be replaced with the new score. * leaders.Remove (minVal); * } * * // Now we add the new score as a new entry that contains the email address and score. * Dictionary<string, object> newScoreMap = new Dictionary<string, object> (); * newScoreMap ["score"] = score; * newScoreMap ["email"] = email; * leaders.Add (newScoreMap); * * // You must set the Value to indicate data at that location has changed. * mutableData.Value = leaders; * return TransactionResult.Success (mutableData); * } * */ TransactionResult AddNewDb(MutableData mutableData) { List <object> listItem = new List <object>(); Dictionary <string, object> keyValue = new Dictionary <string, object> (); keyValue["description"] = "adsgasd"; listItem.Add(keyValue); mutableData.Value = listItem; return(TransactionResult.Success(mutableData)); }
/// <summary> /// Only suitable for value types and strings /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="updateFunc"></param> /// <returns></returns> public override async Task <TResult> PerformTransaction <TResult>(UpdateFunc <TResult, T> updateFunc) { TResult updateResult = default; var resultData = await _reference.RunTransaction((data) => { updateResult = updateFunc(data.Value, out var newValue); data.Value = newValue; return(TransactionResult.Success(data)); }); return(updateResult); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } nikname = null; childScore = 0; long max_score_base = 0; for (int i = 0; i < leaders.Count; i++) { childScore = (long)((Dictionary <string, object>)leaders[i])["score"]; nikname = (String)((Dictionary <string, object>)leaders[i])["email"]; if (childScore < score && email == nikname) { leaders.RemoveAt(i); } if (max_score_base < childScore) { max_score_base = childScore; } } // Now we add the new score as a new entry that contains the email address and score. if (max_score_base < score) { Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["score"] = score; newScoreMap["email"] = email; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; } return(TransactionResult.Success(mutableData)); }
TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["OpenBan"] = openCount; leaders.Add(newScoreMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
/// <summary> /// 引数に与えられたデバイスのジオフェンス状態を更新します。 /// ステータス判定と更新はジオフェンス状態に基づいて、サーバサイドで行われます。 /// </summary> /// <param name="deviceIdentifier">デバイス識別子</param> /// <param name="dbGeofenceIdentifier">データベースのジオフェンス識別子</param> /// <param name="inTheArea">領域の範囲内かどうか(true: 領域内, false: 領域外)</param> public void UpdateGeofenceStatus(string deviceIdentifier, string dbGeofenceIdentifier, bool inTheArea) { // 更新 var rootRef = Database.DefaultInstance.GetRootReference(); var devRef = rootRef.GetChild("devices"); // 重要! // 在室状況の更新は非同期に行われるためトランザクショナルにやる必要がある devRef.GetChild(deviceIdentifier).GetChild("geofence_status").RunTransaction(mutableData => { mutableData.GetChildData(dbGeofenceIdentifier).SetValue(NSObject.FromObject(inTheArea)); return(TransactionResult.Success(mutableData)); }); }
// A realtime database transaction receives MutableData which can be modified // and returns a TransactionResult which is either TransactionResult.Success(data) with // modified data or TransactionResult.Abort() which stops the transaction with no changes. TransactionResult AddAnchorTransaction(MutableData mutableData) { List <object> Anchors = mutableData.Value as List <object>; if (Anchors == null) { Anchors = new List <object>(); } //else if (mutableData.ChildrenCount >= MaxScores) //{ // // If the current list of scores is greater or equal to our maximum allowed number, // // we see if the new score should be added and remove the lowest existing score. // long minScore = long.MaxValue; // object minVal = null; // foreach (var child in users) // { // if (!(child is Dictionary<string, object>)) // continue; // long childScore = (long)((Dictionary<string, object>)child)["hitCounter"]; // if (childScore < minScore) // { // minScore = childScore; // minVal = child; // } // } // // If the new score is lower than the current minimum, we abort. // if (minScore > hitCounter) // { // return TransactionResult.Abort(); // } // // Otherwise, we remove the current lowest to be replaced with the new score. // users.Remove(minVal); //} // Now we add the new score as a new entry that contains the email address and score. //newNameMap["hitCounter"] =hitCounter; //newNameMap["scale"] = treeScale; newNameMap["Room"] = roomNumber; newNameMap["IP"] = IPAddress; newNameMap["playerName"] = playerName; Anchors.Add(newNameMap); // You must set the Value to indicate data at that location has changed. mutableData.Value = Anchors; return(TransactionResult.Success(mutableData)); }
public void CadastrarPontos(int pontos) { LerPontos(); _counterRef = FirebaseDatabase.DefaultInstance.GetReference("Usuario" + "/" + IdUsuario + "/" + "Pontos"); _counterRef.RunTransaction(data => { data.Value = pontos + pontosTotal; return(TransactionResult.Success(data)); }).ContinueWith(task => { if (task.Exception != null) { Debug.Log(task.Exception.ToString()); } }); }
private void UpdateRankingRecord(GameMode type, long inputScore, string inputEmail) { string gameType; switch (type) { default: gameType = "easy"; break; case GameMode.Hard: gameType = "hard"; break; } _leaderboardRef.Child(gameType).RunTransaction(nodeData => { List <object> recordList = nodeData.Value as List <object>; if (recordList == null) { recordList = new List <object>(); } else if (nodeData.ChildrenCount >= MaxScoreDisplayCount) //기록이 꽉차면 { long minScore = long.MaxValue; object minValue = null; foreach (var record in recordList.Where(x => x is Dictionary <string, object>)) { long score = (long)(record as Dictionary <string, object>)["score"]; if (score < minScore) { minScore = score; minValue = record; } } if (inputScore < minScore) { return(TransactionResult.Abort()); //순위 안에 최소값 보다 못하면 중단 } recordList.Remove(minValue); //기존 최소값 정보 제거 } Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["email"] = inputEmail; //식별자 newScoreMap["score"] = inputScore; //점수 recordList.Add(newScoreMap); // 새로운 점수 기록 nodeData.Value = recordList; return(TransactionResult.Success(nodeData)); }); }
// Uploads the time data to the top time list for a level, as a Firebase Database transaction. private static TransactionResult UploadScoreTransaction( MutableData mutableData, TimeData timeData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } // Only save a certain number of the best times. if (mutableData.ChildrenCount >= 5) { long maxTime = long.MinValue; object maxVal = null; foreach (object child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } string childName = (string)((Dictionary <string, object>)child)["name"]; long childTime = (long)((Dictionary <string, object>)child)["time"]; if (childTime > maxTime) { maxTime = childTime; maxVal = child; } } if (maxTime < timeData.time) { // Don't make any changes to the mutable data, but return it so we can use // the snapshot. return(TransactionResult.Success(mutableData)); } leaders.Remove(maxVal); } Dictionary <string, object> newTimeEntry = new Dictionary <string, object>(); newTimeEntry["name"] = timeData.name; newTimeEntry["time"] = timeData.time; leaders.Add(newTimeEntry); mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
//This Function is call when the Logout of the current user. But is doing somethings really strange so don use it /*public void Logout(){ * if (FirebaseAuth.DefaultInstance.CurrentUser != null){ * Debug.Log("Successfully logged Out"); * SceneManager.LoadScene("MainMenu"); * FirebaseAuth.DefaultInstance.SignOut(); * } * }*/ /* Save a * * Requires the new stats to save as a parameter, which consists of: * - Time taken to complete it * - Completion type (Rejected, Began, Abandoned, Failed, Completed) * - The level's identifier */ public static void SaveMissionStats(MissionStats newStats) { if (user == null) { Debug.LogError("A logged in user is required to save mission data."); return; } reference .Child("statistics") .Child(user.UserId) .RunTransaction( savedStats => { Debug.Log("Running transaction on statistics."); savedStats.Value = /* Update user's stats for: each level's mission statistics, completion type, time. */ CommitMissionStats(savedStats.Value as DocumentStore, newStats); return(TransactionResult.Success(savedStats)); } ).ContinueWith( task => { if (task.IsCanceled) { Debug.Log("Transaction was canceled."); return; } if (task.IsFaulted) { Debug.LogError( "Transaction fault : " + task.Exception.Message ); Debug.LogError(task.Exception); return; } if (!task.IsCompleted) { Debug.LogError("Transaction failed to complete."); return; } Debug.Log("Transaction complete."); } ); }
public void IncrementQttPlayed(string fase, string path = "fases") { List <object> valorAtual; if (!path.Equals("itens")) { database.Child("sample").Child("-LrQ39Kn5629t6fgDYpA").Child("game").Child(path).RunTransaction((mutableData => { Dictionary <string, object> translater = new Dictionary <string, object>(); if (mutableData.Value == null) { valorAtual = new List <object>(); translater[fase] = 1; } else { valorAtual = mutableData.Value as List <object>; int atualValue = System.Convert.ToInt32(mutableData.Child(fase).Value.ToString()); //não funciona se não for assim, sério, tentei 943842 vezes e gastei 434234 minutos por causa disso translater[fase] = atualValue + 1; } mutableData.Value = translater; return(TransactionResult.Success(mutableData)); })); } else { database.Child("relatoriosGlobais").Child("game").Child(path).RunTransaction((mutableData => { Dictionary <string, object> translater = new Dictionary <string, object>(); if (mutableData.Value == null) { valorAtual = new List <object>(); translater[fase] = 1; } else { valorAtual = mutableData.Value as List <object>; int atualValue = System.Convert.ToInt32(mutableData.Child(fase).Value.ToString()); //não funciona se não for assim, sério, tentei 943842 vezes e gastei 434234 minutos por causa disso translater[fase] = atualValue + 1; } mutableData.Value = translater; return(TransactionResult.Success(mutableData)); })); } //database.Child("sample").Child("-LrQ39Kn5629t6fgDYpA").Child("game").Child("fases").Child("Fase Aérea").SetValueAsync(); }
public void InsertDataRoom() //MACHTMAKING { Message.Instance.NewMessage("Buscando oponente"); Dictionary <string, object> info = new Dictionary <string, object>(); ReferenceRoom().RunTransaction(data => { info = data.Value as Dictionary <string, object>; if ((string)info["owner"] == GameManager.Instance.GetUserID()) { return(TransactionResult.Abort()); } if ((string)info["owner"] == "") { info["owner"] = GameManager.Instance.GetUserID().ToString(); buscando_match = false; } else if ((string)info["guest"] == "") { info["guest"] = GameManager.Instance.GetUserID().ToString(); buscando_match = false; } else { return(TransactionResult.Abort()); } data.Value = info; return(TransactionResult.Success(data)); }).ContinueWith(task => { if (task.Exception.Message != string.Empty && (string)info["owner"] != GameManager.Instance.GetUserID()) { print("Hay alguien en guest atascado"); ExtraFunction((string)info["guest"]); } else { print("Todo va bien"); } }); }
public static void SaveProgressStats(ProgressData newdata) { if (user == null) { Debug.LogError("A logged in user is required to save progress data."); return; } reference .Child("progress") .Child(user.UserId) .RunTransaction( savedStats => { Debug.Log("Running transaction on progress."); //DocumentStore userData = new DocumentStore(); savedStats.Value = CommitProgressData(savedStats.Value as DocumentStore, newdata); return(TransactionResult.Success(savedStats)); } ).ContinueWith( task => { if (task.IsCanceled) { Debug.Log("Transaction was canceled."); return; } if (task.IsFaulted) { Debug.LogError( "Transaction fault : " + task.Exception.Message ); Debug.LogError(task.Exception); return; } if (!task.IsCompleted) { Debug.LogError("Transaction failed to complete."); return; } Debug.Log("Transaction complete."); } ); }
TransactionResult AddDataTransaction(MutableData mutableData) { List<object> datas = mutableData.Value as List<object>; if (datas == null) { datas = new List<object>(); } Dictionary<string, object> newData = new Dictionary<string, object>(); newData["Food"] = food; newData["Gold"] = gold; newData["Jewelry"] = jewelry; datas.Add(newData); mutableData.Value = datas; return TransactionResult.Success(mutableData); }
TransactionResult UpdateScore(MutableData nd) { if (nd.Value != null) { Dictionary <string, object> updatedScore = nd.Value as Dictionary <string, object>; topScore = (long)updatedScore["topScore"]; } if (currScore > topScore) { topScore = currScore; nd.Value = new Dictionary <string, object>() { { "topScore", currScore } }; return(TransactionResult.Success(nd)); } return(TransactionResult.Abort()); }
TransactionResult AddScoreTransaction(MutableData mutableData) { List <object> leaders = mutableData.Value as List <object>; if (leaders == null) { leaders = new List <object>(); } else if (mutableData.ChildrenCount >= MaxScores) { long maxTime = 0; object maxVal = null; foreach (var child in leaders) { if (!(child is Dictionary <string, object>)) { continue; } long childTime = (long)((Dictionary <string, object>)child)["time"]; if (childTime > maxTime) { maxTime = childTime; maxVal = child; } } // Not fast enough if (maxTime < finishTime) { return(TransactionResult.Abort()); } // Kick lowest score leaders.Remove(maxVal); } // Insert new player record time Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["time"] = finishTime; newScoreMap["playerName"] = playerName; leaders.Add(newScoreMap); mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
TransactionResult AddPlayerTransaction(MutableData mutableData) { Dictionary <string, object> leaders = mutableData.Value as Dictionary <string, object>; if (leaders == null) { leaders = new Dictionary <string, object>();; } // Now we add the new score as a new entry that contains the email address and score. Dictionary <string, object> newScoreMap = new Dictionary <string, object>(); newScoreMap["color"] = color; newScoreMap["NombreTablero"] = tableroNAme; leaders = newScoreMap; // You must set the Value to indicate data at that location has changed. mutableData.Value = leaders; return(TransactionResult.Success(mutableData)); }
TransactionResult AddTransaction(MutableData mutableData) { int theValue = -1; bool parseResult = int.TryParse(mutableData.Value.ToString(), out theValue); Debug.Log("------ Mutable Data : " + theValue); if (parseResult) { mutableData.Value = theValue + 1; Debug.Log("The Value : " + mutableData.Value); return(TransactionResult.Success(mutableData)); } else { Debug.Log("Failed : " + mutableData.Value.ToString()); return(TransactionResult.Abort()); } }
private TransactionResult UpdateTopScore(MutableData md) { if (md.Value != null) { Dictionary <string, object> updatedScore = md.Value as Dictionary <string, object>; topScore = (long)updatedScore ["topScore"]; } // Compare the cur score to the top score. if (curScore > topScore) // Update topScore, triggers other UpdateTopScores to retry { topScore = curScore; md.Value = new Dictionary <string, object>() { { "topScore", curScore } }; return(TransactionResult.Success(md)); } return(TransactionResult.Abort()); // Aborts the transaction }
// 유져 인덱스 받아오기 public void RegisterUserByFirebase(Action <int> endAction) { RegisterUserProgress = true; mDatabaseRef.Child("UsersCount").RunTransaction(mutableData => { if (mutableData.Value == null) { return(TransactionResult.Success(mutableData)); } int tempCount = Convert.ToInt32(mutableData.Value); mutableData.Value = tempCount + 1; endAction(Convert.ToInt32(mutableData.Value)); RegisterUserProgress = false; return(TransactionResult.Success(mutableData)); }); }
private IEnumerator SalaOcupada(string last_guest_user) { print("Tocaría esperar"); yield return(new WaitForSeconds(1f)); //Esperar a que los usuarios hagan match. buscando_match = true; ReferenceRoom().RunTransaction(data => { Dictionary <string, object> info = data.Value as Dictionary <string, object>; if ((string)info["guest"] == last_guest_user) //Si sigue la misma persona, se ha quedado bugeada. Limpiarla. { info["guest"] = ""; data.Value = info; return(TransactionResult.Success(data)); } else { return(TransactionResult.Abort()); } }); }