public async Task <bool> SetPlayerProperty(Player player, KeyValExpPair kvePair) { var pk = new PlayerKey(player, kvePair.key); while (ppInProgress.ContainsKey(pk)) { Debug.Log($"SetPlayerProperty {pk.ToString()} InProgress"); await Task.Delay(1500); } Debug.Log($"SetPlayerProperty {kvePair.ToString()} for " + player.ToStringFull()); //TrySet Room Properties toChange.Clear(); exptected.Clear(); kvePair.InsertInto(ref toChange, ref exptected); var kvrp = new KeyValResultPair(kvePair.key, kvePair.value, kvePair.exp); ppInProgress.Add(pk, kvrp); if (player.SetCustomProperties(toChange, exptected)) { await Task.WhenAny(Task.Delay(10000), kvrp.setPropResult.Task); if (!kvrp.setPropResult.Task.IsCompleted) { kvrp.setPropResult?.TrySetResult(false); } } else { Debug.LogWarning($"{scriptName} SetPlayerProperty Immedidate fail"); kvrp.setPropResult?.TrySetResult(false); } // var result = kvrp.setPropResult.Task.Result; Debug.Log($"{result}] {kvrp.ToString()}"); ppInProgress.Remove(pk); return(result); }
public async Task <bool> SetRoomProperty(KeyValExpPair kvePair) { while (rpInProgress.ContainsKey(kvePair.key)) { Debug.Log($"SetRoomProperties {kvePair.key} InProgress"); await Task.Delay(1500); } Debug.Log($"SetRoomProperties {kvePair.ToString()}"); //TrySet Room Properties toChange.Clear(); exptected.Clear(); kvePair.InsertInto(ref toChange, ref exptected); var kvrp = new KeyValResultPair(kvePair.key, kvePair.value, kvePair.exp); rpInProgress.Add(kvePair.key, kvrp); if (PhotonNetwork.CurrentRoom.SetCustomProperties(toChange, exptected)) { //Debug.Log($"{scriptName} SetCustomProperties Waiting"); await Task.WhenAny(Task.Delay(10000), kvrp.setPropResult.Task); if (!kvrp.setPropResult.Task.IsCompleted) { kvrp.setPropResult?.TrySetResult(false); } } else { Debug.LogWarning($"{scriptName} SetCustomProperties Immedidate fail"); kvrp.setPropResult?.TrySetResult(false); } var result = kvrp.setPropResult.Task.Result; Debug.Log($"{result}] {kvrp.ToString()}"); rpInProgress.Remove(kvePair.key); return(result); }