@@ -20,6 +20,16 @@ public class GComboBox : GComponent
2020 /// </summary>
2121 public GComponent dropdown ;
2222
23+ /// <summary>
24+ /// Play sound when button is clicked.
25+ /// </summary>
26+ public NAudioClip sound ;
27+
28+ /// <summary>
29+ /// Volume of the click sound. (0-1)
30+ /// </summary>
31+ public float soundVolumeScale ;
32+
2333 protected GObject _titleObject ;
2434 protected GObject _iconObject ;
2535 protected GList _list ;
@@ -47,6 +57,7 @@ public GComboBox()
4757 _items = new List < string > ( ) ;
4858 _values = new List < string > ( ) ;
4959 _popupDirection = PopupDirection . Auto ;
60+ soundVolumeScale = 1 ;
5061 }
5162
5263 /// <summary>
@@ -440,6 +451,7 @@ override protected void ConstructExtension(ByteBuffer buffer)
440451 displayObject . onRollOut . Add ( __rollout ) ;
441452 displayObject . onTouchBegin . Add ( __touchBegin ) ;
442453 displayObject . onTouchEnd . Add ( __touchEnd ) ;
454+ displayObject . onClick . Add ( __click ) ;
443455 }
444456
445457 override public void Setup_AfterAdd ( ByteBuffer buffer , int beginPos )
@@ -500,6 +512,14 @@ override public void Setup_AfterAdd(ByteBuffer buffer, int beginPos)
500512 iv = buffer . ReadShort ( ) ;
501513 if ( iv >= 0 )
502514 _selectionController = parent . GetControllerAt ( iv ) ;
515+
516+ if ( buffer . version >= 5 )
517+ {
518+ str = buffer . ReadS ( ) ;
519+ if ( str != null )
520+ sound = UIPackage . GetItemAssetByURL ( str ) as NAudioClip ;
521+ soundVolumeScale = buffer . ReadFloat ( ) ;
522+ }
503523 }
504524
505525 public void UpdateDropdownList ( )
@@ -599,5 +619,11 @@ private void __touchEnd(EventContext context)
599619 SetCurrentState ( ) ;
600620 }
601621 }
622+
623+ private void __click ( )
624+ {
625+ if ( sound != null && sound . nativeClip != null )
626+ Stage . inst . PlayOneShotSound ( sound . nativeClip , soundVolumeScale ) ;
627+ }
602628 }
603629}
0 commit comments