@@ -20,7 +20,6 @@ namespace JCSUnity
2020 ///
2121 /// Please use this class with Unity's "Event Trigger (Script)"!!!
2222 /// </summary>
23- [ RequireComponent ( typeof ( JCS_SoundPlayer ) ) ]
2423 [ RequireComponent ( typeof ( RectTransform ) ) ]
2524 [ RequireComponent ( typeof ( EventTrigger ) ) ]
2625 public class JCS_ButtonSoundEffect
@@ -32,10 +31,18 @@ public class JCS_ButtonSoundEffect
3231
3332 //----------------------
3433 // Private Variables
35- private JCS_SoundPlayer mSoundPlayer = null ;
3634 private RectTransform mRectTransform = null ;
3735 private EventTrigger mEventTrigger = null ;
3836
37+
38+ [ Header ( "** Optional Variables (JCS_ButtonSoundEffect) **" ) ]
39+
40+ [ Tooltip ( @"Sound Player for this button, if this transform dose not
41+ have the 'JCS_Soundplayer' then it will grab the global sound player." ) ]
42+ [ SerializeField ]
43+ private JCS_SoundPlayer mSoundPlayer = null ;
44+
45+
3946 [ Header ( "Auto add to Unity's \" Event Trigger(Script)\" or not?" ) ]
4047 [ Tooltip ( "is true u dont have to add manully!" ) ]
4148 [ SerializeField ]
@@ -148,7 +155,8 @@ public class JCS_ButtonSoundEffect
148155 //------------------------------
149156 private void Awake ( )
150157 {
151- mSoundPlayer = this . GetComponent < JCS_SoundPlayer > ( ) ;
158+ if ( mSoundPlayer == null )
159+ mSoundPlayer = this . GetComponent < JCS_SoundPlayer > ( ) ;
152160 mRectTransform = this . GetComponent < RectTransform > ( ) ;
153161 mEventTrigger = this . GetComponent < EventTrigger > ( ) ;
154162
@@ -158,6 +166,14 @@ private void Awake()
158166
159167 private void Start ( )
160168 {
169+ /*
170+ * NOTE(jenchieh): First get the sound player from its own
171+ * transform, if it still missing then grab the global sound
172+ * player.
173+ */
174+ if ( mSoundPlayer == null )
175+ mSoundPlayer = JCS_SoundManager . instance . GetGlobalSoundPlayer ( ) ;
176+
161177 if ( mAutoAddEvent )
162178 {
163179 JCS_Utility . AddEventTriggerEvent ( mEventTrigger , EventTriggerType . PointerEnter , JCS_OnMouseOver ) ;
0 commit comments