Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 VSuper · Jul 13, 2014 at 10:12 AM · liststringinventoryguilayoutselectiongrid

Help with Lists and SelectionGrid

Hello, I have two questions to ask about the Lists because I am making an inventory. 1) I use GUILayout.SelectionGrid, who show a string List. In these List there are my items, like Axe or Sword. So in my list I have "Axe" and "Sword" and the selectionGrid show it very well. But, I also want to translate my game, so Axe and Sword will change if the game is in Italian or French per example. The problem is I can't directly do it in the list because the string will change, it is possible to, if in the list the item is "Axe", in the inventory grid it would be item.axe (per example)?

2) I also want to add the number of an item, it would be perfect if I can do like that: item.axe + "(" + axeNumber.ToString() + ")".

Cordialy.

My code:

 public List<string> InventoryItemName = new List<string>();

in OnGUI ():

 customerGridNames = new string[InventoryItemName.Count];
                     for(int cnt = 0; cnt < InventoryItemName.Count; cnt++) {
                         customerGridNames[cnt] = InventoryItemName[cnt];
                     }
 
 scrollPos = GUILayout.BeginScrollView (scrollPos);
 selectedGrid = GUILayout.SelectionGrid(selectedGrid, customerGridNames, 1);
                 if (selectedGrid == item.axeID) mainID = item.axeID;
                 if (selectedGrid == item.swordID) mainID = item.swordID;
 GUILayout.EndScrollView ();


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MrAkroMenToS · Jul 13, 2014 at 10:23 AM

I recommend you to store an ID for each item in the list instead of store their names, because the name is not the identifier but a property. Make a mini database (an array an other list a txt file) to store an item's properties.

For example:

0;Axe;30;0;5

It means:

Id - 0

Name - Axe

Attack damage - 30

Magic damage - 0

Attack speed - 5

Store only the ID, here the "0" in the grid and if you want to rename the thing you can do it easily.

For your second question, I recommend you to make a list to store the "currentItems". It can be something like that: 0;3;1 -- the item with ID 0 count of 3 on the 1th pleace... Figure it out.

I hope it helped let me know if you have any more problems!

Comment
Add comment · Show 3 · 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 VSuper · Jul 13, 2014 at 10:36 AM 0
Share

In the Item.cs, I have all my item, per example for the Axe it's: axeID = 1; item_axe = "Axe"; axeIDnumber = x (number of axe in the inventory); So your way seem too hard for me :/ (I'm not very good :p). It's not possible to, if in the SelectionGrid if the selected ID is 1, the name of the Button is "Axe ("+number+")"?

EDIT: ok I understand (after 30 $$anonymous$$utes...). I will try to do two list, one whith the ID and another with the name who will can change.

avatar image MrAkroMenToS · Jul 13, 2014 at 11:04 AM 0
Share

Please send me a picture where i can see the in-game inverntory, and a we lines where i can see the item.cs class's code. And please edit the image so i can see what do you want to do exactly!

----------------------------------------------------------- After i saw your EDIT--- EDIT: here is an example:

 List<string[]> items = new List<string[]>();
 items.Add(new string[]{"0", "Axe", "30", "0", "5"});
 items.Add(new string[]{"0", "Sword", "20", "0", "10"});


the items[0] will be the axes propery the items[1] is the sword You can get the ID of the axe : items[0][0] You can get the attack speed of the sword: items[1][4]

avatar image VSuper · Jul 13, 2014 at 12:11 PM 0
Share

Ok so it's not really working... The name and the ID are not the seem, it's totally bugged :/ I will retry another day for this, whith the string list and etc...

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

22 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Method is called, but GUI doesn't show up 1 Answer

A node in a childnode? 1 Answer

Scroll List Problem 1 Answer

[SOLVED] First array slot blocking second array slot 1 Answer

C# ArrayList match to string? 1 Answer


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