@@ -150,6 +150,26 @@ public class JCS_SpriteTimer
150150 private bool mMinusMinute = false ;
151151 private bool mMinusHour = false ;
152152
153+
154+ [ Header ( "- Sound (JCS_SpriteTimer)" ) ]
155+
156+ [ Tooltip ( "Sound played when hours get reduced." ) ]
157+ [ SerializeField ]
158+ private AudioClip mHourSound = null ;
159+
160+ [ Tooltip ( "Sound played when minutes get reduced." ) ]
161+ [ SerializeField ]
162+ private AudioClip mMinuteSound = null ;
163+
164+ [ Tooltip ( "Sound played when seconds get reduced." ) ]
165+ [ SerializeField ]
166+ private AudioClip mSecondSound = null ;
167+
168+ // Track the second changes, so we are able to play the
169+ // second sound.
170+ private int mTrackSecond = 0 ;
171+
172+
153173 //----------------------
154174 // Protected Variables
155175
@@ -159,6 +179,10 @@ public class JCS_SpriteTimer
159179 public bool Active { get { return this . mActive ; } set { this . mActive = value ; } }
160180 public bool RoundUp { get { return this . mRoundUp ; } set { this . mRoundUp = value ; } }
161181
182+ public AudioClip HourSound { get { return this . mHourSound ; } set { this . mHourSound = value ; } }
183+ public AudioClip MinuteSound { get { return this . mMinuteSound ; } set { this . mMinuteSound = value ; } }
184+ public AudioClip SecondSound { get { return this . mSecondSound ; } set { this . mSecondSound = value ; } }
185+
162186 //========================================
163187 // Unity's function
164188 //------------------------------
@@ -250,8 +274,7 @@ public void UpdateHourInterval()
250274 {
251275 if ( mDigitHour1 == null || mDigitHour2 == null )
252276 {
253- JCS_Debug . LogError (
254- "Digit slot cannot be null references..." ) ;
277+ JCS_Debug . LogError ( "Digit slot cannot be null references..." ) ;
255278 return ;
256279 }
257280
@@ -276,8 +299,7 @@ public void UpdateMinuteInterval()
276299 {
277300 if ( mDigitMinute1 == null || mDigitMinute2 == null )
278301 {
279- JCS_Debug . LogError (
280- "Digit slot cannot be null references..." ) ;
302+ JCS_Debug . LogError ( "Digit slot cannot be null references..." ) ;
281303 return ;
282304 }
283305
@@ -302,8 +324,7 @@ public void UpdateSecondInterval()
302324 {
303325 if ( mDigitSecond1 == null || mDigitSecond2 == null )
304326 {
305- JCS_Debug . LogError (
306- "Digit slot cannot be null references..." ) ;
327+ JCS_Debug . LogError ( "Digit slot cannot be null references..." ) ;
307328 return ;
308329 }
309330
@@ -474,6 +495,13 @@ private void DoTimer()
474495
475496 mCurrentSeconds -= Time . deltaTime ;
476497
498+ int currentSecond = ( int ) mCurrentSeconds ;
499+ if ( mTrackSecond != currentSecond )
500+ {
501+ PlayTimerSound ( mSecondSound ) ;
502+ mTrackSecond = currentSecond ;
503+ }
504+
477505 if ( mCurrentSeconds < MIN_SECOND_TIME )
478506 {
479507 // 檢查上面是否還有剩.
@@ -498,6 +526,7 @@ private void DoTimer()
498526
499527 if ( mMinusMinute )
500528 {
529+ PlayTimerSound ( mMinuteSound ) ;
501530 -- mCurrentMinutes ;
502531
503532 if ( mCurrentMinutes < MIN_MINUTE_TIME )
@@ -522,6 +551,7 @@ private void DoTimer()
522551
523552 if ( mMinusHour )
524553 {
554+ PlayTimerSound ( mHourSound ) ;
525555 -- mCurrentHours ;
526556
527557 if ( mCurrentHours <= MIN_HOUR_TIME )
@@ -551,5 +581,21 @@ private void DoTimeIsUpCallback()
551581 if ( timeIsUpCallback != null )
552582 timeIsUpCallback . Invoke ( ) ;
553583 }
584+
585+ /// <summary>
586+ /// Play the tick sound.
587+ /// </summary>
588+ /// <param name="clip"></param>
589+ private void PlayTimerSound ( AudioClip clip )
590+ {
591+ if ( clip == null )
592+ return ;
593+
594+ OM_SoundManager sm = OM_SoundManager . instance ;
595+ sm . GetGlobalSoundPlayer ( ) . PlayOneShot ( clip ) ;
596+
597+ //JCS_SoundPlayer sm = JCS_SoundPlayer.instance;
598+ //sm.GetGlobalSoundPlayer().PlayOneShot(clip);
599+ }
554600 }
555601}
0 commit comments