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 jashan · Jan 31, 2017 at 04:40 PM · guiaudioeventsdropdown

Trigger Sounds when opening/closing Dropdown

We're currently adding audio to various UI events. The easy ones are those where there is an interface we can implement, like IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler. For having different sounds for checking/unchecking a Toggle, we use what I find a bit of a hack: We have a method OnValueChanged(bool) that we register with the Toggle component in OnEnable, de-register in OnDisable and play the different sounds in the method.

Dropdowns have one rather obvious event that needs a sound (and actually also animation) but I'm not quite sure how to handle this one. One possibility might be writing our own Dropdown that inherits from the Unity dropdown, where we override CreateDropDownList() and DestroyDropDownList(). Basically, this should work by calling base.Create/DestroyDropDownList() and then triggering our sounds.

But that, IMHO, is definitely quite a hack ... so I was wondering: Is there a better way?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KanraLovesU · Sep 30, 2017 at 04:05 PM

When you create a new Dropdown it comes preloaded with a lot of children UI elements that make up the actual Dropdown menu portion. OnValueChanged for the initial Dropdown only activates when you select a new value but these children UI elements have a little bit more going on with them:

  • Dropdown > Template > OnValueChanged triggers whenever you scroll the scrollbar.

  • Dropdown > Template > Viewport > Content > Item > OnValueChanged triggers whenever you open the dropdown, but for some reason it will trigger twice most of the time and as far as I can tell its random whether it does so.

  • Dropdown > Template > Scrollbar > OnValueChanged triggers whenever you open the dropdown OR scroll the scrollbar.

  • I couldn't find a single OnValueChanged which triggers when you exit the dropdown either by selecting the same option or just pressing the initial button again.

The sound I'm working with works for both the scrollbar and the dropdown open but if you need them to be different I'm afraid there isn't a good answer. I'm using Unity 5.6.0f3 so maybe what I can only assume is a bug with the Item OnValueChanges is fixed in the future. I'm not the most experienced Unity developer myself so I'm not entirely sure why these interactions work as they do. I merely experimented and wanted to give a weak answer so that a more seasoned Unity veteran could fill in the gaps.

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

112 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

EditorGUI.ObjectField placed right below EditorGUI.Foldout? 1 Answer

Gui Playing Audio Trouble 1 Answer

Scrollbar value of 0 resets to 1 1 Answer

Vertical Slider - Using different art? 1 Answer

Easier Way To Add Sound Via GUI? 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