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 $$anonymous$$ · Jan 21, 2015 at 01:59 AM · guiinventoryinventory system

GUI focus control - inventory system issue

Hello everyone, I'm trying to build a game with only keyboard controllers so I wanna create an inventory where you can use arrow keys to "jump" from a box to another. After I created the base for my inventory, it looks like this (without appropriated graphic, ofc ahaha) alt text

The problem is I don't have any idea how to assign a decent GUI.SetNextControlName, because (for what I understood by debug) I can't use it in a for loop.

So, I have these

 private Rect invRect;
 private string[] invBoxes;
 private int boxIndex;

That's the OnGUI part

 void OnGUI(){
         GUI.skin=skin;
 
         if(showInventory){
             invRect=GUI.Window(0,invRect,DrawInventory,"");
             GUI.FocusControl(invBoxes[boxIndex]);
             if(Input.GetKey(KeyCode.Escape))
                showInventory=false;
             InventoryInput();
             Debug.Log (GUI.GetNameOfFocusedControl());
         }
     }


And, finally, this is the DrawInventory method

 void DrawInventory(int windowID){
 
 
         //[...]things not related to the problem
 
         int i=0;
         int BoxIndex=0;
 
         GUIStyle invBox="BaseBox";
         invBox.fixedHeight=invRect.height/18;
         invBox.fixedWidth=invRect.width/2.05f;
         for(int x=0;x<slotsX;x++){
             GUILayout.BeginHorizontal();
 
 
             for(int y=0;y<slotsY;y++){
                 GUILayout.BeginVertical();
                 GUILayout.Box(inventory[i].ItemIcon, invBox);
                 GUI.SetNextControlName("Box"+(BoxIndex));
                 GUI.Box(GUILayoutUtility.GetLastRect(), inventory[i].ItemIcon, invBox);
                 invBoxes.SetValue("Box"+BoxIndex,BoxIndex);
 
                 GUIStyle textGUI="ObjectName";
                 textGUI.fontSize=(int)(invRect.height/22);
                 GUI.Box(GUILayoutUtility.GetLastRect(), "   "+inventory[i].Name,"ObjectName");
 
                 if(inventory[i].IsStackable&&inventory[i].ItemCounter>1){
                     GUIStyle quantityGUI="ItemCounter";
                     quantityGUI.padding.right=(int)(invRect.width/50);
                     quantityGUI.fontSize=(int)(invRect.height/22);
                     GUI.Box(GUILayoutUtility.GetLastRect(), "x"+inventory[i].ItemCounter.ToString(),"ItemCounter");}
                 BoxIndex++;
                 GUILayout.EndVertical();
                 i++;
 
             }
             GUILayout.EndHorizontal();
 
         }
         GUIStyle DescrBox="DescriptionBox";
         DescrBox.fontSize=(int)(invRect.height/22);
         GUILayout.Box("-Select an item-","DescriptionBox");
     }


I've started to develop in unity 2 weeks ago, so if the code is messy, pardon ahaha I've also used a couple of tutorials to understand better some aspects. Btw, I've created a GUILayout.Box and after that a GUI.Box because (I think) that the GUI.SetNextecc. method doesn't consider the first option, so I just used it for the coords.. And all seems to work, BoxIndex increments itself properly, but

 GUI.SetNextControlName("Box"+(BoxIndex));

always remains "Box0". I've tried to edit my boxIndex (with the lowerCase) but it returns an empty string and not "Box1", so it's pointing to nothing.

Am I getting wrong something? Does another method exist to achieve this issue?

Thank you :)

immagine.png (4.4 kB)
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 $$anonymous$$ · Jan 21, 2015 at 11:40 AM

I solved it switching GUI.Box to GUI.Button. GUI.SetNextControlName doesn't work on Boxes ^^

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

1 Person is following this question.

avatar image

Related Questions

Which is better for an inventory system, Array or List? 0 Answers

scroll bar inventory with slot count for equip items 0 Answers

How to go around creating inventory with new GUI (4.6 Beta)? 1 Answer

How to start an inventory system? 2 Answers

GUI Button with both texture and text? 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