Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Suyuanhan · Aug 03, 2011 at 02:06 AM · guibuttonoverlap

GUI Button overlap problem

Two buttons position overlap in some area,when the Mouse over this area, The over effection will happen in the same time. But I want that when I over the Button,the "MouseOver Event" only happen in the foucus window or the top depth( even I set different depth ,it happen the same). So,How can I change that thing? Thx.....

here the image:alt text

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 Waz · Aug 03, 2011 at 03:08 AM 0
Share

When you say "focus window", are you using Unity Windows?

If so, I may have something lying around in a test project.

avatar image Suyuanhan · Aug 03, 2011 at 03:29 AM 0
Share

Yeah,I test in window,but even without window,It happen the same, you can try(C#): GUI.Button(new Rect(10,10,100,100),"A"); GUI.Button(new Rect(20,20,100,100),"B");

And two buttons' over Effection will happen when your mouse over their share area.

1 Reply

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

Answer by Waz · Aug 03, 2011 at 04:06 AM

Below is a complete working example of windowing with control over window focusing.

 #pragma strict
 
 var windowRect0 : Rect = Rect (20, 20, 120, 150);
 var windowRect1 : Rect = Rect (20, 100, 120, 150);
 
 var focusedWindow = 0; // Initially focused window.
 var show= [true,true]; // Initially shown windows.
 var clickOnUnfocused = false; // What style of windowing do you want?
 
 private var closeWindow = -1;
 private var toDraw = 0;
 private var neverFocused = true;
 
 function OnGUI()
 {
     // Need to know how many we draw to work out which is on top.
     toDraw = 0;
     if (show[0]) { toDraw++; windowRect0 = GUILayout.Window (0, windowRect0, DoMyWindow, "Window 0"); }
     if (show[1]) { toDraw++; windowRect1 = GUILayout.Window (1, windowRect1, DoMyWindow, "Window 1"); }
     
     if (neverFocused) {
         // Set initial focus (default is none!!)
         neverFocused = false;
         GUI.FocusWindow(focusedWindow);
     }
     
     if (closeWindow >= 0) {
         // Close if instructed to in DoMyWindow.
         show[closeWindow] = false;
         closeWindow = -1;
     }
 }
 
 function DoMyWindow(windowID : int)
 {
     if (Event.current.type == EventType.Repaint) {
         // Are we the last (top) window, and so the focused one?
         toDraw--;
         if (toDraw == 0)
             focusedWindow = windowID;
     }
     
     // Unfocused windows drawn disabled, and unless clickOnUnfocused also actually disabled.
     if (focusedWindow != windowID && (Event.current.type == EventType.Repaint || !clickOnUnfocused))
         GUI.enabled = false;
     
     if (GUILayout.Button("Close")) {
         // Just register the close, actually do it back in OnGUI, otherwise
         // window closes mid-way through event processing, muddling toDraw.
         Debug.Log("Close "+windowID);
         closeWindow = windowID;
     }
     
     if (GUILayout.Button("Hello")) {
         Debug.Log("Clicked "+windowID);
     }
     
     // Window-specific controls, here just a toggle for clickOnUnfocused.
     if (windowID == 0)
         clickOnUnfocused = GUILayout.Toggle(clickOnUnfocused,"Click On Unfocused");
         
     // Always allow dragging.
     GUI.enabled = true;
     GUI.DragWindow (Rect (0,0,10000,10000));
 }

I guess Unity doesn't enforce any policies like this so that you can implement any style you like. It would be nice though if the API at least had GUI.focusedWindow (as inferred in the code above), since the GUI code clearly knows it, given the visualization.

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 Suyuanhan · Aug 03, 2011 at 04:43 AM 0
Share

Thanks,it gives me a lot help

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Overlapping GUI buttons 1 Answer

button drawn last not triggered 0 Answers

Overlapping GUITexture UI Buttons 2 Answers

Overlapping buttons? 0 Answers

How to WaitforSeconds a GuiButton ? 0 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