public void Display(IToplistProvider provider, IToplistIdentifier identifier)
    {
        var transformCache = transform;

        provider.Get(identifier, (entries) => {
            for (int i = 0; i < entries.Count; i++)
            {
                var entry = entries[i];
                Instantiate(toplistEntryPrefab, transformCache).GetComponent <ToplistEntry>().Setup(entry.Username, entry.Score, i + 1);
            }
        });
    }
Beispiel #2
0
 override public bool Get(IToplistIdentifier identifier, Action <IList <IToplistEntry> > callback, int maxEntries = 10)
 {
     if (localLists.ContainsKey(identifier.LevelIndex))
     {
         localLists[identifier.LevelIndex].Get(identifier, callback, maxEntries);
     }
     else
     {
         return(false);
     }
     return(true);
 }
Beispiel #3
0
 /**
  * Publishes a result to the toplist. If the user already has an equal or better score, this will be a no-op.
  *
  * @return False if an error occured.
  */
 public bool ReportResult(IToplistIdentifier identifier, int score)
 {
     if (entries.Exists(e => e.Username == localUsername))
     {
         ToplistEntry existingEntry = (ToplistEntry)entries.Find(e => e.Username == localUsername);
         if (existingEntry.Score >= score)
         {
             return(true);
         }
         entries.Remove(existingEntry);
     }
     entries.Add(new ToplistEntry(localUsername, score));
     return(true);
 }
Beispiel #4
0
 override public bool ReportResult(IToplistIdentifier identifier, int score)
 {
     try
     {
         if (!localLists.ContainsKey(identifier.LevelIndex))
         {
             localLists[identifier.LevelIndex] = new LocalToplist();
         }
         localLists[identifier.LevelIndex].SetLocalUsername(localUserName);
         localLists[identifier.LevelIndex].ReportResult(identifier, score);
         return(true);
     }
     catch (Exception e)
     {
         Console.Write("Error in MultiTopList.RportResult:" + e);
         return(false);
     }
 }
Beispiel #5
0
    public void Display(IToplistProvider provider, IToplistIdentifier identifier)
    {
        var transformCache = transform;

        if (lastLevel != identifier.LevelIndex)
        {
            //A more efficient approach is probably to make a pool of ToplistEntry object and enable or disable them as needed.
            //But, for quick and dirty, just deleting and recreating them also works.
            foreach (ToplistEntry item in entryList)
            {
                item.Delete();
            }
            entryList.Clear();
        }
        string inType = provider.GetType().ToString();

        Debug.Log(inType);
        provider.Get(identifier, (entries) =>
        {
            for (int i = 0; i < entries.Count; i++)
            {
                var entry  = entries[i];
                bool found = false;
                foreach (ToplistEntry item in entryList)
                {
                    if (item.username.text == entry.Username)
                    {
                        item.score.text = entry.Score.ToString();
                        found           = true;
                        break;
                    }
                }
                if (!found)
                {
                    ToplistEntry t = Instantiate(toplistEntryPrefab, transformCache).GetComponent <ToplistEntry>();
                    t.Setup(entry.Username, entry.Score, i + 1);
                    entryList.Add(t);
                }
            }
        });

        lastLevel = identifier.LevelIndex;
    }
Beispiel #6
0
 /**
  * Publishes a result to the toplist. If the user already has an equal or better score, this will be a no-op.
  *
  * @return False if an error occured.
  */
 virtual public bool ReportResult(IToplistIdentifier identifier, int score)
 {
     try
     {
         if (entries.Exists(e => e.Username == localUsername))
         {
             ToplistEntry existingEntry = (ToplistEntry)entries.Find(e => e.Username == localUsername);
             if (existingEntry.Score >= score)
             {
                 return(true);
             }
             entries.Remove(existingEntry);
         }
         entries.Add(new ToplistEntry(localUsername, score));
         return(true);
     }
     catch (Exception e)
     {
         Console.Write("Error in LocalTopList.ReportResult" + e);
         return(false);
     }
 }
Beispiel #7
0
 public bool Get(IToplistIdentifier identifier, Action <IList <IToplistEntry> > callback, int maxEntries = 10)
 {
     callback(entries);
     return(true);
 }
Beispiel #8
0
 virtual public bool Get(IToplistIdentifier identifier, Action <IList <IToplistEntry> > callback, int maxEntries = 10)
 {
     //Here is where maxEntries does its magic.
     callback(entries.GetRange(0, (entries.Count >= maxEntries ?maxEntries:entries.Count)));
     return(true);
 }