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 /
This question was closed Dec 19, 2012 at 07:03 PM by KiraSensei for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KiraSensei · Dec 19, 2012 at 02:50 PM · onguilayoutrepaint

2 dialogs not displayable at the same time.

Hello !

It took me some time to understand that there are two calls on OnGUI method by frame and what to do to avoid weird problems. But it seems like I didn't quite understand all of it ...

My script handling the chat is like :

 function OnGUI() {
     if (Event.current.type == EventType.Layout) windowChat = GUI.Window (0, windowChat, GlobalChatWindow, "Chat");
 }

 function GlobalChatWindow (id : int) {
     scrollPosition = GUILayout.BeginScrollView (scrollPosition);
 
     for (var entry : ChatEntry in entries)
     {
         GUILayout.BeginHorizontal();
         GUILayout.Label(entry.text);
         GUILayout.FlexibleSpace ();
         
         GUILayout.EndHorizontal();
         GUILayout.Space(3);
         
     }
     // End the scrollview we began above.
     GUILayout.EndScrollView ();
     
     if (Event.current.type == EventType.keyDown && Event.current.character == "\n" && inputField.Length > 0)
     {
         inputField = myNickname + ": " + inputField;
         ApplyGlobalChatText(inputField, 1);
         networkView.RPC("ApplyGlobalChatText", RPCMode.Others, inputField, 0);
         inputField = "";
     }
     GUI.SetNextControlName("Chat input field");
     inputField = GUILayout.TextField(inputField);
 }

And my script handling my score dialog is like :

 function OnGUI() {
     if (enableScoreDlg)
     {
         scoresDlg = GUI.Window(0, Rect (0.1*Screen.width, 0.1*Screen.height, 0.8*Screen.width, 0.8*Screen.height), ScoreWindow, "", scoreSkin.window);
     }
 }

with enableScoreDlg true only when the user uses the "tab" key. My problem now is that there is never both the windows together. If the user presses "tab", the chat window disappears and my score dialog appears, when he releases it, my score dialog disappears and the chat reappears... What is wrong with my code ? I think this has to do with the 2 calls of OnGUI method every frame, and since the two dialogs are in different scripts there is a problem :(

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

  • Sort: 
avatar image
1
Best Answer

Answer by PAEvenson · Dec 19, 2012 at 03:20 PM

My first guess would be when you are hitting the Tab button your Event.current.Type is getting changed, turning off your chat window.

OnGUI will be called on all ENABLED scripts on ACTIVE gameobjects each frame, if not multiple times per frame.

The 2nd thing I would check is after you hit the Tab button, pause the game and make sure the gameobjects and scripts and enabled/active.

Comment
Add comment · Show 10 · 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 KiraSensei · Dec 19, 2012 at 05:13 PM 0
Share

The game object attaching the script is active and the script is enabled when I press the "tab" button.

avatar image PAEvenson · Dec 19, 2012 at 05:19 PM 1
Share

and Event.current.type == EventType.Layout when you hit tab?

avatar image PAEvenson · Dec 19, 2012 at 05:21 PM 0
Share

I am betting Event.current.type == EventType.keyDown

avatar image KiraSensei · Dec 19, 2012 at 05:24 PM 0
Share

What do you suggest ? that I add this condition for the chat dialog?

avatar image PAEvenson · Dec 19, 2012 at 05:39 PM 3
Share

aha! I found it! Both your windows have the same window ID. change one of the windows to ID 1

Show more comments
avatar image
0

Answer by criptoonita · Dec 19, 2012 at 07:54 PM

I didn't see when you put true the enableScoreDlg, but maybe this idea would help.

In one of the two scripts when able to show dialog put this variable in a static class and static public bool. And then the other script read this static bool.

Comment
Add comment · Show 4 · 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 KiraSensei · Dec 19, 2012 at 08:11 PM 0
Share

I'm sorry, I validated an answer but didn't close the question in case of someone had any clue for my last question.

$$anonymous$$y boolean variable is set in my Update() method when the user pushes the "tab" button. This was implicit with the intels I gave, but not obvious :). Thanks anyway for trying to help !

avatar image Dave-Carlile · Dec 19, 2012 at 08:45 PM 0
Share

@$$anonymous$$iraSensei, you don't want to close the question after it's answered. Closing is generally reserved for duplicate or off topic questions.

avatar image KiraSensei · Dec 19, 2012 at 08:53 PM 0
Share

Ah, when we close a question, there are multiple choices, and one of them is : the question has been answered and right answer was accepted. So I assumed that was the thing to do when I consider nothing interesting can be added.

avatar image Dave-Carlile · Dec 19, 2012 at 09:02 PM 0
Share

Not sure why that is an option when closing. But accepting one of the answers is usually the last thing to do - that leaves it open for others to search for and find an answer if they have a similar problem. Closing it for when there's some sort of problem with the question itself.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

How to force Unity to Repaint an EditorWindow? 1 Answer

Work around for, "Getting control 0's position in a group with only 0 controls when doing repaint?" (Trouble Spot Spotted) 0 Answers

How completly remove GUI.Repaint() calls ? 1 Answer

Optimizing OnGUI - Too many gui elements? 2 Answers

iPhone Touch Screen? 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