Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity firebase update nodes rank value by sorting value

email_arrayList = new ArrayList();

    var currentUser = FirebaseAuth.DefaultInstance.CurrentUser;

    int rank = 0;
     playerId = currentUser.UserId;
     Debug.Log(playerId);

    FirebaseDatabase.DefaultInstance.GetReference("users").ValueChanged += FirebaseSaveLoadScript_ValueChanged;

    FirebaseDatabase.DefaultInstance
      .GetReference("users").OrderByChild("userScore")
      .ValueChanged += (object sender2, ValueChangedEventArgs e2) => {
          if (e2.DatabaseError != null)
          {
              Debug.LogError(e2.DatabaseError.Message);
              return;
          }
          Debug.Log("Received values for Leaders.");
          string title = leaderBoard[0].ToString();
          leaderBoard.Clear();
          leaderBoard.Add(title);
          if (e2.Snapshot != null && e2.Snapshot.ChildrenCount > 0)
          {
              foreach (var childSnapshot in e2.Snapshot.Children)
              {
                  if (childSnapshot.Child("userScore") == null
                || childSnapshot.Child("userScore").Value == null)
                  {
                      Debug.LogError("Bad data in sample.  Did you forget to call SetEditorDatabaseUrl with your project id?");
                      break;
                  }
                  else
                  {
                      Debug.Log("Leaders entry : " +
                    childSnapshot.Child("userEmail").Value.ToString() + " - " +
                    childSnapshot.Child("userScore").Value.ToString());

                      email_arrayList.Add(childSnapshot.Child("userEmail").Value.ToString());

                      leaderBoard.Insert(1, childSnapshot.Child("userScore").Value.ToString()
                    + "  " + childSnapshot.Child("userEmail").Value.ToString());

                      displayScores.text = "";
                      foreach (string item in leaderBoard)
                      {
                          displayScores.text += "
" + item;

                      }
                  }

              }
          }

          email_arrayList.Reverse();
          foreach (string obj in email_arrayList)
          {
              rank++;
              if (obj == currentUser.Email)
              {
                  int rank_final = rank;
                  Debug.Log("I'm number " + rank_final + " in the rankings");
                  userRank.text = "Your Rank is " + rank_final;
                  rank = 0;
                  break;
              }

              Debug.Log(obj);

          }

      };
Comment

PREVIOUS NEXT
Code Example
Csharp :: get one parameter from list in an new list c# 
Csharp :: how to change argument of function in f# 
Csharp :: clear highlight winforms treeview 
Csharp :: custom attribute for auth permission check .net 
Csharp :: ef6 export update 
Csharp :: unity repeat coroutine 
Csharp :: c# pull request 
Csharp :: deploy c# applications on ubuntu 
Csharp :: c# panel to graphics 
Csharp :: wpf stackpanel horizontal 
Csharp :: how to check if data already exists in database in c# mvc 
Csharp :: how to navigate between page in wpf 
Csharp :: c# get error message from cmd command 
Csharp :: generate poco from db efcore 
Csharp :: process method in scala 
Csharp :: how to make dissapear an object in unity 
Csharp :: take out substring from string 
Csharp :: external font family uwp c# 
Csharp :: how to detect a null bool C# 
Csharp :: c# expandoobject indexer 
Csharp :: il c# 
Csharp :: c# check if file is zero bytes 
Csharp :: how to use mongodb search index in c# 
Csharp :: c# zeitverzögerung 
Csharp :: how to make physics in unity 
Csharp :: list of countries in .net mvc 5 
Csharp :: how do make internet 
Csharp :: global variable startup file .net core api 
Csharp :: google script get font color 
Csharp :: get current culture in controller asp.net core 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =