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 DaiMangouDev · Mar 06, 2015 at 11:12 AM · c#guieditorrect

How do I get (return) all the GUI inside(contained in) a GUI rect ?

Hi,

If we have a large GUI box and then we drag a button into that box, how can we make the box know what the button is within the bounds of the box ?

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

2 Replies

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

Answer by Cherno · Mar 06, 2015 at 03:15 PM

Since OnGUI elements like Box and Button use Rectangles, you can just use

 if(yourRect.Contains(new Vector2(myButton.position.xMin, myButton.position.yMin))
 || yourRect.Contains(new Vector2(myButton.position.xMin, myButton.position.yMax))
 || yourRect.Contains(new Vector2(myButton.position.xMax, myButton.position.yMin))
 || yourRect.Contains(new Vector2(myButton.position.xMax, myButton.position.yMax))) {
      Debug.Log("myButton is completely inside yourRect.");
 }

That would ensure the whole button is inside the Rect. You can of course also just check if the Rect contains your mouseposition if you are dragging the button with the mouse.

Comment
Add comment · Show 1 · 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 DaiMangouDev · Mar 06, 2015 at 03:47 PM 0
Share

thank you , that will work .

avatar image
0

Answer by AdamAz · Mar 06, 2015 at 11:25 AM

Hi

I would try something like this:

When you release the element do a raycast and check if it hits the box (if you want to know it the whole button is in the box you can do 4 raycasts from 4 button corners and check if all of them hit the box). If the button is in the box you can either move it to become a child element of the box and/or add it to a list of contained elements for faster reference.

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 DaiMangouDev · Mar 06, 2015 at 12:00 PM 0
Share

that seems like a rather taxing process . we can actually raycast from inside OnGUI and hit GUI elements ?

avatar image AdamAz · Mar 06, 2015 at 01:58 PM 0
Share

I was under the impression that you are using normal game objects, sorry about that. Not sure if it is possible to do this with OnGUI elements.

avatar image DaiMangouDev · Mar 06, 2015 at 02:10 PM 0
Share

no problem. I think that it is possible , when i find the answer ,ironically; I will post it here myself.

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

Editor Scripting Input Problem OnGUI() 1 Answer

How to hide a rect 1 Answer

How do I prevent value using EditorGUILayout.FloatField to not change as soon as I change the float field value ? 1 Answer

TexturePropertySingleLine in Editor class 0 Answers

How to solve the problem of "You are pushing more GUIClips than you are popping" 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