Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by D3m0nE · Jul 28, 2013 at 08:39 AM · arraylistgenericsort

Show Top 10 Of 1 GameType

Hello Everyone i have Game that contain mini-Games and all Games put the Score in 1 list

public List highscore;

         foreach(Scores _score in highscore)
         {
             GUILayout.BeginHorizontal();
             GUILayout.Label(_score.name, "NameStyle");
             GUILayout.Label(""+_score.score, "ScoreStyle");
             GUILayout.Label(""+_score.GameType, "ScoreStyle");
             GUILayout.EndHorizontal();
         }


how i can Only Show the highscore depending on the "GameType" for Example : Puzzle

Only Show The Puzzle Score . dont show other game like Tennis,

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lovrenc · Jul 28, 2013 at 08:53 AM 0
Share

Just go trough your collection and search for gametype you want. Filer out your first 10 matches and display them.

avatar image D3m0nE · Jul 28, 2013 at 08:56 AM 0
Share

can u give me simple code? how to filter ?

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by gregzo · Jul 28, 2013 at 09:32 AM

Hi, It seems your Scores class ( or struct? ) already contains a GameType member. So why don't you just check the GameType, and display only if it matches your predicate? I don't know what type your Scores.GameType member is, I'll assume it's a string :

 void DisplayScoresOfType ( string type, int maxDisplayedScores )
 {
     int counter = 0;
     foreach(Scores _score in highscore)
     {
         GUILayout.BeginHorizontal();
         if ( _score.GameType == type )
         {
               counter++;
               GUILayout.Label(_score.name, "NameStyle");
               GUILayout.Label(""+_score.score, "ScoreStyle");
               GUILayout.Label(""+_score.GameType, "ScoreStyle");
         }
         GUILayout.EndHorizontal();
         if ( counter == maxDisplayedScores )
         {
              break;
         }
     }
 }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lovrenc · Jul 28, 2013 at 09:38 AM 0
Share

Ofcourse, if you have more than 10 elements of each type, you want to end the loop.

avatar image gregzo · Jul 28, 2013 at 09:39 AM 0
Share

yep, add a counter and break when it reaches 10.

avatar image D3m0nE · Jul 28, 2013 at 10:13 AM 0
Share

Thanks. but it didnt work and No Erros

i use this Code to Get the HighScore i Putted in Start Function

 highscore = HighScore$$anonymous$$anager._instance.GetHighScore();    


i should put that in the button?

                 if(GUILayout.Button("Tennis")){
             highscore = HighScore$$anonymous$$anager._instance.GetHighScore();    
             DisplayScoresOfType("Tennis",10);
         }
         if(GUILayout.Button("Soccer")){
             highscore = HighScore$$anonymous$$anager._instance.GetHighScore();    
             DisplayScoresOfType("Soccer",10);
         }
         
avatar image D3m0nE · Jul 28, 2013 at 10:20 AM 0
Share

Edit 3

works. thank you but i have other problem i wonder if u can help me

that i have a HighScore Background + GUI.Label when the window Size Change, everything change his position , how i can make it static position or just realizable in good way ? sry for my bad english

avatar image gregzo · Jul 28, 2013 at 10:39 AM 0
Share

Please post as a seperate question!

avatar image
0

Answer by dan19 · Jul 28, 2013 at 11:07 AM

You can also use Linq. For instance, to show the Top 10 scores for game type "tennis", just replace this line:

 foreach(Scores _score in highscore)
 {
     //...

with this:

 foreach(Scores _score in highscore.Where((arg) => arg.GameType == "Tennis")
                                   .OrderBy((arg) => -arg.score)
                                   .Take(10))
 {
     //...

and also add "``using System.Linq;``" in the beginning of your script.

Of course, I assumed that GameType fields are strings. And score fields are ints. Adjust appropriately if they aren't.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

A node in a childnode? 1 Answer

List.Sort with IComparer 2 Answers

Remove and Add to List By Name aad 1 Answer

How to sort a list of gameobjects by their name? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges