Skip to content

Commit ff6c239

Browse files
committed
feat: simplify shake
1 parent 0549810 commit ff6c239

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

Assets/JCSUnity/Scripts/Effects/3D/JCS_3DShakeEffect.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class JCS_3DShakeEffect : JCS_UnityObject
2727

2828
[Tooltip("Do wave effect key.")]
2929
[SerializeField]
30-
private KeyCode mDoShakeEffectKey = KeyCode.Y;
30+
private KeyCode mDoEffectKey = KeyCode.Y;
3131
#endif
3232

3333
[Separator("Check Variables (JCS_3DShakeEffect)")]
@@ -55,18 +55,18 @@ public class JCS_3DShakeEffect : JCS_UnityObject
5555
[Tooltip("How long it shakes.")]
5656
[SerializeField]
5757
[Range(0.001f, 360.0f)]
58-
private float mShakeTime = 1.0f;
58+
private float mTime = 1.0f;
5959

6060
[Tooltip("How intense it shakes.")]
6161
[SerializeField]
62-
private float mShakeMargin = 3.0f;
62+
private float mMargin = 3.0f;
6363

6464
[Tooltip("Shake for each steps.")]
6565
[SerializeField]
66-
private float mShakeSteps = 5.0f;
66+
private float mSteps = 5.0f;
6767

6868
// Support
69-
private float mShakeTimer = 0.0f;
69+
private float mTimer = 0.0f;
7070

7171
[Tooltip("Type of the delta time.")]
7272
[SerializeField]
@@ -76,15 +76,15 @@ public class JCS_3DShakeEffect : JCS_UnityObject
7676

7777
[Tooltip("Do shake on z axis.")]
7878
[SerializeField]
79-
private bool mShakeOnX = true;
79+
private bool mOnX = true;
8080

8181
[Tooltip("Do shake on y axis.")]
8282
[SerializeField]
83-
private bool mShakeOnY = true;
83+
private bool mOnY = true;
8484

8585
[Tooltip("Do shake on z axis.")]
8686
[SerializeField]
87-
private bool mShakeOnZ = true;
87+
private bool mOnZ = true;
8888

8989
[Header("- Sound")]
9090

@@ -94,26 +94,26 @@ public class JCS_3DShakeEffect : JCS_UnityObject
9494

9595
[Tooltip("Sound played when effect occurs.")]
9696
[SerializeField]
97-
private AudioClip mShakeSound = null;
97+
private AudioClip mClip = null;
9898

9999
/* Setter & Getter */
100100

101101
public bool Effect { get { return this.mEffect; } set { this.mEffect = value; } }
102102

103103
public JCS_TransformType TransformType { get { return this.mTransformType; } set { this.mTransformType = value; } }
104104
public bool Force { get { return this.mForce; } set { this.mForce = value; } }
105-
public float ShakeTime { get { return this.mShakeTime; } set { this.mShakeTime = value; } }
106-
public float ShakeMargin { get { return this.mShakeMargin; } }
107-
public float ShakeSteps { get { return this.mShakeSteps; } set { this.mShakeSteps = value; } }
105+
public float Time { get { return this.mTime; } set { this.mTime = value; } }
106+
public float Margin { get { return this.mMargin; } set { this.mMargin = value; } }
107+
public float Steps { get { return this.mSteps; } set { this.mSteps = value; } }
108108

109109
public JCS_TimeType DeltaTimeType { get { return this.mTimeType; } set { this.mTimeType = value; } }
110110

111-
public bool ShakeOnX { get { return this.mShakeOnX; } set { this.mShakeOnX = value; } }
112-
public bool ShakeOnY { get { return this.mShakeOnY; } set { this.mShakeOnY = value; } }
113-
public bool ShakeOnZ { get { return this.mShakeOnZ; } set { this.mShakeOnZ = value; } }
111+
public bool OnX { get { return this.mOnX; } set { this.mOnX = value; } }
112+
public bool OnY { get { return this.mOnY; } set { this.mOnY = value; } }
113+
public bool OnZ { get { return this.mOnZ; } set { this.mOnZ = value; } }
114114

115115
public JCS_SoundPlayer SoundPlayer { get { return this.mSoundPlayer; } set { this.mSoundPlayer = value; } }
116-
public AudioClip ShakeSound { get { return this.mShakeSound; } set { this.mShakeSound = value; } }
116+
public AudioClip Clip { get { return this.mClip; } set { this.mClip = value; } }
117117

118118
/* Functions */
119119

@@ -132,7 +132,7 @@ private void Test()
132132
if (!mTestWithKey)
133133
return;
134134

135-
if (JCS_Input.GetKeyDown(mDoShakeEffectKey))
135+
if (JCS_Input.GetKeyDown(mDoEffectKey))
136136
{
137137
DoShake();
138138
}
@@ -146,7 +146,7 @@ private void Test()
146146
/// <param name="margin"> margin to do the shake. </param>
147147
public void DoShake()
148148
{
149-
DoShake(mShakeTime, mShakeMargin, mForce);
149+
DoShake(mTime, mMargin, mForce);
150150
}
151151
public void DoShake(float time, float margin, bool force)
152152
{
@@ -160,9 +160,9 @@ public void DoShake(float time, float margin, bool force)
160160
}
161161
}
162162

163-
this.mShakeTime = time;
164-
this.mShakeTimer = 0;
165-
this.mShakeMargin = margin;
163+
this.mTime = time;
164+
this.mTimer = 0.0f;
165+
this.mMargin = margin;
166166

167167
mShakeDelta = Vector3.zero;
168168

@@ -193,23 +193,23 @@ private void DoEffect()
193193
return;
194194
}
195195

196-
mShakeTimer += dt;
196+
mTimer += dt;
197197

198-
if (mShakeTimer < mShakeTime)
198+
if (mTimer < mTime)
199199
{
200200
// shake randomly
201-
if (mShakeOnX)
202-
mShakeDelta.x = (JCS_Random.RangeInclude(-1.0f, 1.0f)) * mShakeMargin * (mShakeTime / mShakeTimer) / mShakeSteps;
203-
if (mShakeOnY)
204-
mShakeDelta.y = (JCS_Random.RangeInclude(-1.0f, 1.0f)) * mShakeMargin * (mShakeTime / mShakeTimer) / mShakeSteps;
205-
if (mShakeOnZ)
206-
mShakeDelta.z = (JCS_Random.RangeInclude(-1.0f, 1.0f)) * mShakeMargin * (mShakeTime / mShakeTimer) / mShakeSteps;
201+
if (mOnX)
202+
mShakeDelta.x = (JCS_Random.RangeInclude(-1.0f, 1.0f)) * mMargin * (mTime / mTimer) / mSteps;
203+
if (mOnY)
204+
mShakeDelta.y = (JCS_Random.RangeInclude(-1.0f, 1.0f)) * mMargin * (mTime / mTimer) / mSteps;
205+
if (mOnZ)
206+
mShakeDelta.z = (JCS_Random.RangeInclude(-1.0f, 1.0f)) * mMargin * (mTime / mTimer) / mSteps;
207207

208208
ApplyShakeByTransformType(mShakeDelta);
209209
}
210210
else
211211
{
212-
mShakeTimer = 0.0f;
212+
mTimer = 0.0f;
213213
mEffect = false;
214214
}
215215
}
@@ -219,10 +219,10 @@ private void DoEffect()
219219
/// </summary>
220220
private void PlayeSound()
221221
{
222-
if (mShakeSound == null)
222+
if (mClip == null)
223223
return;
224224

225-
JCS_SoundPlayer.PlayByAttachment(mSoundPlayer, mShakeSound);
225+
JCS_SoundPlayer.PlayByAttachment(mSoundPlayer, mClip);
226226
}
227227

228228
/// <summary>

0 commit comments

Comments
 (0)