• 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

  • 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

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta on June 13. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to add texture in onGUI() 0 Answers

GameObject ontop of GUI 2 Answers

GUI.DragWindow not working 1 Answer

Temperature Script? 3 Answers

Health bar 2 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