Skip to content

Commit c22784b

Browse files
committed
Merged from remote.
2 parents a87d360 + b29a122 commit c22784b

File tree

6 files changed

+250
-12
lines changed

6 files changed

+250
-12
lines changed

Assets/JCSUnity/Scripts/GUI/JCS_TextDeltaNumber.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ public void UpdateNumber(float targetNumber, bool anime = true)
171171
if (anime)
172172
mActive = true;
173173
else
174+
{
175+
mActive = false; // To ensure, just deactive it.
174176
this.mCurrentNumber = targetNumber;
177+
}
175178
}
176179

177180
/// <summary>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/**
2+
* $File: JCS_TextAnimation.cs $
3+
* $Date: 2019-07-18 14:34:29 $
4+
* $Revision: $
5+
* $Creator: Jen-Chieh Shen $
6+
* $Notice: See LICENSE.txt for modification and distribution information
7+
* Copyright © 2019 by Shen, Jen-Chieh $
8+
*/
9+
10+
/* NOTE: If you are using `TextMesh Pro` uncomment this line.
11+
*/
12+
#define TMP_PRO
13+
14+
using System.Collections;
15+
using System.Collections.Generic;
16+
using UnityEngine;
17+
using UnityEngine.UI;
18+
19+
#if TMP_PRO
20+
using TMPro;
21+
#endif
22+
23+
namespace JCSUnity
24+
{
25+
/// <summary>
26+
/// Text animation that will display text accordingly.
27+
/// </summary>
28+
public class JCS_TextAnimation
29+
: MonoBehaviour
30+
{
31+
/* Variables */
32+
33+
[Header("** Chec Variables (JCS_TextAnimation) **")]
34+
35+
[Tooltip("Frame this animation is currently displayed.")]
36+
[SerializeField]
37+
private int mCurrentFrame = 0;
38+
39+
40+
[Header("** Initialize Variables (JCS_TextAnimation) **")]
41+
42+
[Tooltip("Target text renderer.")]
43+
[SerializeField]
44+
private Text mTextContainer = null;
45+
46+
#if TMP_PRO
47+
[Tooltip("Target text renderer.")]
48+
[SerializeField]
49+
private TextMeshPro mTextMesh = null;
50+
#endif
51+
52+
53+
[Header("** Runtime Variables (JCS_TextAnimation) **")]
54+
55+
[Tooltip("Animation active or not active.")]
56+
[SerializeField]
57+
private bool mActive = true;
58+
59+
[Tooltip("Hold all text animation's frame.")]
60+
[TextArea]
61+
public List<string> textFrame = null;
62+
63+
[Tooltip("Seconds per frame.")]
64+
[SerializeField] [Range(0.0f, 30.0f)]
65+
private float mSPF = 0.5f;
66+
67+
// Base timer to display frame.
68+
private float mFrameTimer = 0.0f;
69+
70+
71+
/* Setter/Getter */
72+
73+
public bool Active { get { return this.mActive; } set { this.mActive = value; } }
74+
public Text TextContainer { get { return this.mTextContainer; } set { this.mTextContainer = value; } }
75+
#if TMP_PRO
76+
public TextMeshPro TextMesh { get { return this.mTextMesh; } set { this.mTextMesh = value; } }
77+
#endif
78+
public int CurrentFrame { get { return this.mCurrentFrame; } }
79+
public float SPF { get { return this.mSPF; } set { this.mSPF = value; } }
80+
81+
82+
/* Functions */
83+
84+
private void Awake()
85+
{
86+
// Initialize the first frame.
87+
UpdateTextFrame();
88+
}
89+
90+
private void Update()
91+
{
92+
if (!mActive)
93+
return;
94+
95+
DoTextAnimation();
96+
}
97+
98+
/// <summary>
99+
/// Update the frame text.
100+
/// </summary>
101+
public void UpdateTextFrame()
102+
{
103+
UpdateTextFrame(this.mCurrentFrame);
104+
}
105+
106+
/// <summary>
107+
/// Update the frame text.
108+
/// </summary>
109+
/// <param name="frameIndex"> Frame index to displayed. </param>
110+
public void UpdateTextFrame(int frameIndex)
111+
{
112+
this.mCurrentFrame = frameIndex;
113+
114+
/* Ensure in display range. */
115+
if (this.mCurrentFrame >= textFrame.Count)
116+
this.mCurrentFrame = textFrame.Count - 1;
117+
else if (this.mCurrentFrame < 0)
118+
this.mCurrentFrame = 0;
119+
120+
if (mTextContainer)
121+
mTextContainer.text = textFrame[this.mCurrentFrame];
122+
if (mTextMesh)
123+
mTextMesh.text = textFrame[this.mCurrentFrame];
124+
}
125+
126+
/// <summary>
127+
/// Do the actual text animation here.
128+
/// </summary>
129+
private void DoTextAnimation()
130+
{
131+
mFrameTimer += Time.deltaTime;
132+
133+
if (mFrameTimer < mSPF)
134+
return;
135+
136+
++this.mCurrentFrame;
137+
138+
if (this.mCurrentFrame >= textFrame.Count)
139+
this.mCurrentFrame = 0;
140+
141+
UpdateTextFrame();
142+
143+
mFrameTimer = 0.0f; // Reset timer.
144+
}
145+
}
146+
}

Assets/JCSUnity/Scripts/GUI/Timer/JCS_SpriteTimer.cs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

Assets/JCSUnity/Scripts/GUI/JCS_TextTimer.cs renamed to Assets/JCSUnity/Scripts/GUI/Timer/JCS_TextTimer.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/* NOTE: If you are using `TextMesh Pro` uncomment this line.
1111
*/
12-
//#define TMP_PRO
12+
#define TMP_PRO
1313

1414
using System.Collections;
1515
using System.Collections.Generic;
@@ -107,6 +107,25 @@ public class JCS_TextTimer
107107
private bool mMinusHour = false;
108108

109109

110+
[Header("- Sound (JCS_TextTimer)")]
111+
112+
[Tooltip("Sound played when hours get reduced.")]
113+
[SerializeField]
114+
private AudioClip mHourSound = null;
115+
116+
[Tooltip("Sound played when minutes get reduced.")]
117+
[SerializeField]
118+
private AudioClip mMinuteSound = null;
119+
120+
[Tooltip("Sound played when seconds get reduced.")]
121+
[SerializeField]
122+
private AudioClip mSecondSound = null;
123+
124+
// Track the second changes, so we are able to play the
125+
// second sound.
126+
private int mTrackSecond = 0;
127+
128+
110129
/* Setter/Getter */
111130
public bool Active { get { return this.mActive; } set { this.mActive = value; } }
112131
public bool RoundUp { get { return this.mRoundUp; } set { this.mRoundUp = value; } }
@@ -117,6 +136,10 @@ public class JCS_TextTimer
117136
#endif
118137
public string DelimiterText { get { return this.mDelimiterText; } set { this.mDelimiterText = value; } }
119138

139+
public AudioClip HourSound { get { return this.mHourSound; } set { this.mHourSound = value; } }
140+
public AudioClip MinuteSound { get { return this.mMinuteSound; } set { this.mMinuteSound = value; } }
141+
public AudioClip SecondSound { get { return this.mSecondSound; } set { this.mSecondSound = value; } }
142+
120143
/* Functions */
121144

122145
private void Start()
@@ -299,6 +322,13 @@ private void DoTimer()
299322

300323
mCurrentSeconds -= Time.deltaTime;
301324

325+
int currentSecond = (int)mCurrentSeconds;
326+
if (mTrackSecond != currentSecond)
327+
{
328+
PlayTimerSound(mSecondSound);
329+
mTrackSecond = currentSecond;
330+
}
331+
302332
if (mCurrentSeconds < MIN_SECOND_TIME)
303333
{
304334
// 檢查上面是否還有剩.
@@ -321,6 +351,7 @@ private void DoTimer()
321351

322352
if (mMinusMinute)
323353
{
354+
PlayTimerSound(mMinuteSound);
324355
--mCurrentMinutes;
325356

326357
if (mCurrentMinutes < MIN_MINUTE_TIME)
@@ -343,6 +374,7 @@ private void DoTimer()
343374

344375
if (mMinusHour)
345376
{
377+
PlayTimerSound(mHourSound);
346378
--mCurrentHours;
347379

348380
if (mCurrentHours <= MIN_HOUR_TIME)
@@ -371,5 +403,21 @@ private void DoTimeIsUpCallback()
371403
if (timeIsUpCallback != null)
372404
timeIsUpCallback.Invoke();
373405
}
406+
407+
/// <summary>
408+
/// Play the tick sound.
409+
/// </summary>
410+
/// <param name="clip"></param>
411+
private void PlayTimerSound(AudioClip clip)
412+
{
413+
if (clip == null)
414+
return;
415+
416+
OM_SoundManager sm = OM_SoundManager.instance;
417+
sm.GetGlobalSoundPlayer().PlayOneShot(clip);
418+
419+
//JCS_SoundPlayer sm = JCS_SoundPlayer.instance;
420+
//sm.GetGlobalSoundPlayer().PlayOneShot(clip);
421+
}
374422
}
375423
}
File renamed without changes.

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ the assets into that project. Then you can start all of the tools
3232
in the JCSUnity framework. <br/>
3333

3434

35-
## Current Version Status
36-
* *JCSUnity Version* : `1.9.1`
37-
* *Unity Version* : `2019.1.7f1 (64-bit)`
38-
39-
4035
## Features
4136
So, what does this framework does? Check out the
4237
[features](https://github.com/jcs090218/JCSUnity/tree/master/features)

0 commit comments

Comments
 (0)