// Create friend buttons public async Task Read() { for (int i = 0; i < itemParent.transform.childCount; i++) { Destroy(itemParent.transform.GetChild(i).gameObject); } FriendDatabaseQAHandler.GetFriends(friends => { foreach (var friend in friends) { Debug.Log($"{friend.Key} {friend.Value.userName}"); if (friend.Value.userName == userName) { GameObject tmp_btn = Instantiate(item, itemParent.transform); tmp_btn.name = friend.Key; Debug.Log("item name: " + tmp_btn.name); tmp_btn.transform.GetChild(1).GetComponent <Text>().text = friend.Key; } } }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Read elapsed milliseconds: {0}" + sec); }
// Creating friend in database public async Task PostingFriend(Friend friend, string friendName) { FriendDatabaseQAHandler.PostFriend(friend, friendName, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Creating friend Elapsed milliseconds: {0}" + sec); }
// Check if the friend already exist public async Task <bool> CheckFriendExist(string friendName) { FriendDatabaseQAHandler.GetFriend(friendName, friend => { chk = true; Debug.Log("chFriendExist1" + chk); }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(500).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("check friend exist elapsed milliseconds: {0}" + sec); return(chk); }
//Delete friend in database public async void DeleteFriend() { loader.SetActive(true); Debug.Log("DELETE name: " + friendKey); FriendDatabaseQAHandler.DeleteFriend(friendKey, () => { }); Stopwatch sw = Stopwatch.StartNew(); var delay = Task.Delay(1000).ContinueWith(_ => { sw.Stop(); return(sw.ElapsedMilliseconds); }); await delay; int sec = (int)delay.Result; Debug.Log("Delete elapsed milliseconds: {0}" + sec); await Read(); loader.SetActive(false); messageBox.SetActive(true); messageBox.transform.GetChild(1).GetComponent <Text>().text = friendKey + " deleted successfully."; friendKey = null; }