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 AnaRhisT · Jul 05, 2010 at 11:27 AM · dropdownpopupswitch-case

Dropdown menu(PopupList)

What happends here is that when there's a left click so the showlist is true.(pop ups)

but the problem is that when I check if there's a left click and showlist is true(in the if statement) so it opens and immeaditely closes(it's a matter of milliseconds), if I change Fire1 to Fire2, it does closes it correctly with the RIGHT click, i want to close it with the LEFT click.

using UnityEngine;

public class Popup { public static bool List (Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, GUIContent[] listContent, GUIStyle listStyle) { return List(position, ref showList, ref listEntry, buttonContent, listContent, "button", "box", listStyle); }

 public static bool List (Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, GUIContent[] listContent,
                          GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) {
     bool done = false;
     if(!showList && Input.GetButton("Fire1")){
                 showList = true;
     }
     else if(Input.GetButton("Fire1") && showList)
     {
         done = true;
     }
     GUI.Label(position, buttonContent, buttonStyle);
     if (showList) {
         Rect listRect = new Rect(40, 58, 95, listStyle.CalcHeight(listContent[0], 10.0f)*listContent.Length);
         GUI.Box(listRect, "", boxStyle);
         listEntry = GUI.SelectionGrid(listRect, listEntry, listContent, 1, listStyle);
     }
     if (done) {
         showList = false;
     }
     return done;
 }

}

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
2
Best Answer

Answer by Mike 3 · Jul 05, 2010 at 12:29 PM

It should be else if for the second if (so it doesn't go into it if you toggle it on)

Comment
Add comment · Show 6 · 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 AnaRhisT · Jul 05, 2010 at 12:40 PM 0
Share

Nope, It's still the same, No difference, I updated the code above.

avatar image Mike 3 · Jul 05, 2010 at 12:48 PM 0
Share

Change them both to GetButtonDown and it should work

avatar image AnaRhisT · Jul 05, 2010 at 12:59 PM 0
Share

How did u get to that conclusion? GetButtonDown works only if the button is held. I want to make just one click.

avatar image Mike 3 · Jul 05, 2010 at 01:02 PM 1
Share

Other way around - GetButtonDown returns true only the first frame it's pressed, GetButton returns true while it's down. On the other hand, you really shouldn't be using Input.* in GUI code (I'd use if(Event.current.type == EventType.$$anonymous$$ouseUp && Event.current.button == 0){} )

avatar image AnaRhisT · Jul 05, 2010 at 01:04 PM 0
Share

$$anonymous$$ike, I love you.

Show more comments
avatar image
0

Answer by krskrs · Jul 19, 2012 at 10:29 AM

class what i try to use is Standard Assets/Scripts/Popup.cs Popup list by Eric Haines.

sing UnityEngine; using System.Collections; using System.Collections.Generic;

public class Popup { static int popupListHash = "PopupList".GetHashCode(); // Delegate public delegate void ListCallBack();

 public static bool List (Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, object[] list ,
                          GUIStyle listStyle, ListCallBack callBack) {
     
     
     
     return List(position, ref showList, ref listEntry, buttonContent, list, "button", "box", listStyle, callBack);
 }
   
 public static bool List (Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent,  object[] list,
                          GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle, ListCallBack callBack) {
     

     int controlID = GUIUtility.GetControlID(popupListHash, FocusType.Passive);
     bool done = false;
     switch (Event.current.GetTypeForControl(controlID)) {
         case EventType.mouseDown:
             if (position.Contains(Event.current.mousePosition)) {
                 GUIUtility.hotControl = controlID;
                 showList = true;
             }
             break;
         case EventType.mouseUp:
             if (showList) {
                 done = true;
                  // Call our delegate method
             callBack();
             }
             break;
     }
    
     GUI.Label(position, buttonContent, buttonStyle);
     if (showList) {
         
         // Get our list of strings
         string[] text = new string[list.Length];
         // convert to string
         for (int i =0; i<list.Length; i++)
         {
             text[i] = list[i].ToString();
         }
         
         Rect listRect = new Rect(position.x, position.y, position.width, list.Length * 20);
         GUI.Box(listRect, "", boxStyle);
         listEntry = GUI.SelectionGrid(listRect, listEntry, text, 1, listStyle);
     }
     if (done) {
         showList = false;
     }
     return done;
 }

}

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Popup window - Dropdown menu 1 Answer

GUI Popup problem…! 1 Answer

How could I change the Drop-down List (NGUI UIPopup List) position or its parent? 2 Answers

dropdown menu PopupList c# problem 3 Answers

Custom Editor fields listed below script variables 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