• 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
Question by Dani · Apr 10, 2011 at 01:22 PM · gui

Where do I find a serious GUI code?

The current GUI code is wayyyyyyyy over simplified approach..

GUILayout.Button("I'm a button!");

Ok so now when is the mouse over the button?
Some ridiculous solutions I found:

You can check what tooltip is displayed

And what if I have 2 buttons with same tooltip?

Use Rect.Contains()

The button already knows when a mouse is over it - it changes its border, no need to add redundant code.
So how do I know when the mouse is over a button without workarounds, and where is that hidden real OOP gui package?
Yes, there is one. the example for this is the textarea - it remembers where the cursor is without you passing it to it and getting the new position in return.

Comment

People who like this

0 Show 0
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

4 Replies

· Add your reply
  • Sort: 
avatar image

Answer by ckfinite · Apr 10, 2011 at 02:15 PM

Well, there really is not a OOP GUI package for UnityGui, however, underneath, the GUI system uses the old procedural approach to OOP, which is why it looks like it is OOP. Anyway, to answer your question, there is no way to get weather the mouse is over a element without saving the rect and seeing if the mouse is within it. UnityGUI provides much less programmatic customization than other (non-Unity) GUI systems.

Comment
Statement

People who like this

1 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 Fattie · May 07, 2014 at 09:34 AM 0
Share

Sure there is .. eDriven.Gui

avatar image

Answer by Extrakun · Apr 10, 2011 at 03:23 PM

Try GUIX, a plugin developed by Ennanuzus Interactive. It is an OOP layer over the existing Immediate GUI system. It is not free though; do try out the demo and see if you like it.

Comment
Statement

People who like this

1 Show 0 · 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

Answer by Statement · Apr 10, 2011 at 03:44 PM

If you got a little patience, you can make classes (don't derive from MonoBehaviour) for each gui type and expose useful variables such as Rect, GUIContent, GUIStyle and other related variables. That way you can build an OO GUI from an immediate GUI. I used it many times. Tip: Make your classes Serializable and expose them in any script that uses them. The inspector will allow you to make simple changes and you can easily embed a mouse-over system in those classes.


I think sample code easily carry the intention over:

[Serializable] public class GUIButton { public Rect position = new Rect(0, 0, 200, 100); public GUIContent content = GUIContent.none; public string style = "button";

 public bool OnGUI()
 {
      return GUI.Button(position, content, style);
 }
 public bool IsMouseOver()
 {
      // Dunno if you need to convert the position to GUI coordinates
      // using GUIUtility.ScreenToGUIPoint...
      return position.Contains(Input.mousePosition); 
 }

}

See also: GUIUtility.ScreenToGUIPoint.

Comment
Jean-Fabre

People who like this

1 Show 2 · 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 Eric5h5 · Apr 10, 2011 at 07:33 PM 2
Share

GUI code should use Event.current, not Input. i.e., Event.current.mousePosition.

avatar image Statement · Apr 10, 2011 at 07:34 PM 0
Share

Aha, good stuff to know.

avatar image

Answer by dkozar · Jan 09, 2013 at 10:44 AM

You should check out eDriven.Gui.

It's a full blown OOP, event-driven, asynchronous GUI/RIA solution for Unity3d: http://edrivengui.com/

Comment
Fattie

People who like this

1 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

4.6 GUI Button inside a scrolling Text Box 0 Answers

Get GUITexture to follow ScreenPointToRay ray cast 1 Answer

drawing a box with GUI 3 Answers

Why is my GUI pushed over to the right? 0 Answers

Possible to change GUI.Label fontsize without using GUIStyle? 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