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 Jamoy1993 · Aug 15, 2014 at 11:13 PM · loopprocedural

Problems with Custom Tool Tip Generation

I am currently having problems generating custom windows to appear when hovering over an item in my inventory. I am using a self modified version of Brackeys Inventory System.

All works fine, if i hover over the objects the window appears on my cursor as expected. But when i take away my cursor from any icon it still persists.

alt text

The Code for this as follows:

 //Drawing the Inventory window
 function OnGUI()
 {
     GUI.skin = invSkin;
     
     if(itemBeingDragged != null) //If we are dragging an Item, draw the button on top:
     {
         GUI.depth = 3;
         GUI.Button(Rect(draggedItemPosition.x,draggedItemPosition.y,draggedItemSize.x,draggedItemSize.y),itemBeingDragged.itemIcon);
         GUI.depth = 0;
     }
     
     //If the inventory is opened up we create the Inventory window:
     if(DisplayWindow)
     {
         mouse = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
         WepHand.CanUseInventory = false;
         CameraScript.LockCamera();
         CameraUnlocked = false;
         windowRect = GUI.Window (windowID, windowRect, SetUpDisplayWindow, WindowName);    
 
     }
     else
     {
         if(!CameraUnlocked)
         {
             CameraScript.UnlockCamera();
             CameraUnlocked = true;
         }
         
         WepHand.CanUseInventory = true;
     }
     
     GUI.skin = ToolTipSkin;
     if(HoverItem != null)
     {
         ToolTipRectangle = GUI.Window(99, ToolTipRectangle, ToolTipSetup, "");
     }
     
 }
 
 function SetUpDisplayWindow(windowID:int)
 {
     GUI.skin = invSkin; //Use the invSkin
     var MaxSpace : int = InventoryObj.GetComponent(InvStorage).MaxContent;
     var SpaceTaken : int = InventoryObj.GetComponent(InvStorage).Contents.Length;
     GUI.Label(Rect(12, 5,100,100),  (MaxSpace - SpaceTaken) +  " / " +   MaxSpace );
     
     if (canBeDragged == true)
     {
         GUI.DragWindow (Rect (0,0, 10000, 30));  //the window to be able to be dragged
     }
 
     var currentX = 0 + Offset.x; //Where to put the first items.
     var currentY = 18 + Offset.y; //Im setting the start y position to 18 to give room for the title bar on the window.
 
     for(var i:Transform in UpdatedList) //Start a loop for whats in our list.
     {
         //Get the items script
         var item=i.GetComponent(Item);
         //Create a button for this instance
         ButtonRect = new Rect(currentX,currentY,itemIconSize.x,itemIconSize.y);
         
         // if the player clicks this button, add the item to their inventory
         if (GUI.Button(ButtonRect, item.itemIcon))
         {
             if(PlayerInv.Contents.Length < PlayerInv.MaxContent)
             {
                 item.TransferToPlayer(i);
             }
         }
         
         //if hovering over the item, trigger an window to open with info on the object
         if(ButtonRect.Contains(new Vector2(mouse.x - windowRect.x, mouse.y - windowRect.y))) 
         {
             HoverItem = item;
         }
         
         //If its stackable, display the ammount in the stack
         if(item.stackable) //If the item can be stacked:
         {
             GUI.Label(Rect(currentX, currentY, itemIconSize.x, itemIconSize.y), "" + item.stack, "Stacks"); //Showing the number (if stacked).
         }
         
         //Space the items out in the display.
         currentX += itemIconSize.x;
         if(currentX + itemIconSize.x + Offset.x > windowSize.x) //Make new row
         {
             currentX=Offset.x; //Move it back to its startpoint wich is 0 + offsetX.
             currentY+=itemIconSize.y; //Move it down a row.
             if(currentY + itemIconSize.y + Offset.y > windowSize.y) //If there are no more room for rows we exit the loop.
             {
                 return;
             }
         }
         
     }
 
 }
 
 
 function ToolTipSetup(windowID : int)
 {
     ToolTipRectangle.position = mouse;
 
 }
 

Annoying, i thought if i added in an else statement to the ButtonBox.Contains it would fix it, but it only makes things worse. It only shows a tooltip for the final item, but atleast it dissapears.

alt text

         //if hovering over the item, trigger an window to open with info on the object
         if(ButtonRect.Contains(new Vector2(mouse.x - windowRect.x, mouse.y - windowRect.y))) 
         {
             HoverItem = item;
         }
         else
         {
             HoverItem = null;
         }

It appears to me its due to the type of loop that is used in the procedural generation of the inventory icons...

Any ideas on the best way to achieve what i am trying to do?

problem1.png (511.3 kB)
problem2.png (467.2 kB)
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 Jamoy1993 · Aug 16, 2014 at 11:08 AM 0
Share

Come on no one has any thoughts?

avatar image gjf · Aug 16, 2014 at 11:33 AM 0
Share

i've only ever done it using GUI.tooltip

1 Reply

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

Answer by Jamoy1993 · Aug 16, 2014 at 12:31 PM

I fixed it by changing the for loop from an x in y to an incremental loop. Then i made another loop to loop through rects stored in an array and a few lines of code to deter whether or not the player is over an rect.

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

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

Create objects in a selected area 2 Answers

By Code generated Mesh (problems with visibility) 4 Answers

Procedural terrain generation ? 0 Answers

How would i make this code not lag the game 1 Answer

Difference between if statement, while and for loop? 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