Skip to content

Commit 11fb8cf

Browse files
committed
Merge animation logic into PlayEvent
1 parent 522cf24 commit 11fb8cf

File tree

2 files changed

+62
-68
lines changed

2 files changed

+62
-68
lines changed

Assets/_Project/Scripts/Effects/AnimController.cs

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
public class AnimController : MonoBehaviour {
1010

1111
public Animator animator;
12-
public int currentAnimation = 0; // the animation to play
13-
public string animEvent; //
12+
public int animIndex = 0; // the animation to play
13+
public string animName; //
1414

1515

1616

@@ -22,45 +22,31 @@ void Start ()
2222

2323
void Update ()
2424
{
25-
26-
// set currentAnimation based on animEvent - string set from TimelineManager or key
27-
28-
// Swirl_r_sm
29-
if (animEvent == "attack" || Input.GetKey (KeyCode.Alpha1)) {
30-
currentAnimation = 1;
31-
}
32-
// Swirl_r_md
33-
else if (animEvent == "badge" || Input.GetKey (KeyCode.Alpha2)) {
34-
currentAnimation = 2;
35-
}
36-
// Pop_Shake_md
37-
else if (animEvent == "stream" || Input.GetKey (KeyCode.Alpha3)) {
38-
currentAnimation = 3;
39-
}
40-
// Pop_Shake_sm
41-
else if (animEvent == "leaderboard" || Input.GetKey (KeyCode.Alpha4)) {
42-
currentAnimation = 4;
43-
}
44-
// Pop_sm
45-
else if (animEvent == "consumable" || Input.GetKey (KeyCode.Alpha5)) {
46-
currentAnimation = 5;
47-
}
48-
// Rotate_md
49-
else if (animEvent == "tracker" || Input.GetKey (KeyCode.Alpha6)) {
50-
currentAnimation = 6;
51-
}
52-
// Rotate_Pop_sm
53-
else if (animEvent == "disguise" || Input.GetKey (KeyCode.Alpha7)) {
54-
currentAnimation = 7;
25+
// set animIndex based on animName - string set from TimelineManager - or key
26+
27+
if (animName == "Swirl_r_sm" || Input.GetKey (KeyCode.Alpha1)) {
28+
animIndex = 1;
29+
} else if (animName == "Swirl_r_md" || Input.GetKey (KeyCode.Alpha2)) {
30+
animIndex = 2;
31+
} else if (animName == "Pop_Shake_md" || Input.GetKey (KeyCode.Alpha3)) {
32+
animIndex = 3;
33+
} else if (animName == "Pop_Shake_sm" || Input.GetKey (KeyCode.Alpha4)) {
34+
animIndex = 4;
35+
} else if (animName == "Pop_sm" || Input.GetKey (KeyCode.Alpha5)) {
36+
animIndex = 5;
37+
} else if (animName == "Rotate_md" || Input.GetKey (KeyCode.Alpha6)) {
38+
animIndex = 6;
39+
} else if (animName == "Rotate_Pop_sm" || Input.GetKey (KeyCode.Alpha7)) {
40+
animIndex = 7;
5541
}
5642

5743
// play the animation
58-
animator.SetInteger ("state", currentAnimation);
44+
animator.SetInteger ("state", animIndex);
5945

6046
// then reset vars
61-
if (currentAnimation >= 0) {
62-
animEvent = "";
63-
currentAnimation = 0;
47+
if (animIndex >= 0) {
48+
animName = "";
49+
animIndex = 0;
6450
}
6551
}
6652

Assets/_Project/Scripts/Players/PlayerManager.cs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ public void CreateNewPlayer (string username, string avatarPath)
119119

120120
/**
121121
* Play a player event
122+
* - The logic that determines effects.
123+
* - For example, whether a GO with sprite animation or particle effect animation is attached, and what timeline animation (when tally twirls, etc.) is played.
122124
*/
123125
public void PlayEvent (FeedData feed)
124126
{
@@ -139,32 +141,64 @@ public void PlayEvent (FeedData feed)
139141

140142
// BATTLES ARE MORE COMPLEX
141143
if (feed.eventType == "monster") {
142-
StartCoroutine (PlayBattle (feed));
144+
StartCoroutine (PlayBattleEffects (feed));
143145
} else {
144146

145147

148+
149+
146150
// STREAM (CLICK or LIKE)
147151
if (feed.eventType == "stream") {
148152
AttachDetachAnimation (rippleAnim, false, 1f, 2.5f);
153+
// play the timeline animation
154+
currentPlayerScript.animControllerScript.animName = "Pop_Shake_md";
149155
}
156+
150157
// ATTACK
151158
else if (feed.eventType == "attack") {
152159
AttachDetachAnimation (attackSpriteAnim, true, 2.3f, -1);
160+
// play the timeline animation
161+
currentPlayerScript.animControllerScript.animName = "Swirl_r_sm";
153162
}
163+
154164
// BADGE
155165
else if (feed.eventType == "badge") {
156166
// PLACEHOLDER
157167
AttachDetachAnimation (triangleTrailsAnim, false, 1f, 2.5f);
168+
// play the timeline animation
169+
currentPlayerScript.animControllerScript.animName = "Swirl_r_md";
158170
}
171+
159172
// CONSUMABLE
160173
else if (feed.eventType == "consumable") {
161174
// PLACEHOLDER
162175
AttachDetachAnimation (triangleTrailsAnim, false, 1f, 2.5f);
176+
// play the timeline animation
177+
currentPlayerScript.animControllerScript.animName = "Pop_sm";
163178
}
179+
164180
// DISGUISE
165181
else if (feed.eventType == "disguise") {
166182
// PLACEHOLDER
167183
AttachDetachAnimation (triangleTrailsAnim, false, 1f, 2.5f);
184+
// play the timeline animation
185+
currentPlayerScript.animControllerScript.animName = "Rotate_Pop_sm";
186+
}
187+
188+
// TRACKER
189+
else if (feed.eventType == "tracker") {
190+
// PLACEHOLDER
191+
AttachDetachAnimation (triangleTrailsAnim, false, 1f, 2.5f);
192+
// play the timeline animation
193+
currentPlayerScript.animControllerScript.animName = "Rotate_md";
194+
}
195+
196+
// LEADERBOARD - not currently storing / sending with API
197+
else if (feed.eventType == "leaderboard") {
198+
// PLACEHOLDER
199+
AttachDetachAnimation (triangleTrailsAnim, false, 1f, 2.5f);
200+
// play the timeline animation
201+
currentPlayerScript.animControllerScript.animName = "Pop_Shake_sm";
168202
}
169203

170204

@@ -176,8 +210,7 @@ public void PlayEvent (FeedData feed)
176210
// test
177211
//StartCoroutine (PlayBattle (feed));
178212

179-
// play the timeline animation (loops, swirls, pops, etc.)
180-
currentPlayerScript.animControllerScript.animEvent = feed.eventType;
213+
181214
}
182215

183216

@@ -237,46 +270,20 @@ void AttachDetachAnimation (GameObject prefab, bool randomPosition, float scaleM
237270
Debug.Log ("AttachDetachAnimation() prefab.name = " + prefab.name);
238271

239272

240-
// ATTACH GAME OBJECT WITH ANIM
241-
242-
//// default position
243-
//Vector3 instPos = Vector3.zero;
244-
245-
//// or, set slightly random position
246-
//if (randomPosition) instPos = new Vector3 (Random.Range (-2, 2), Random.Range (-2, 2), 0);
247-
248-
249-
250-
251-
252-
273+
// ATTACH THE GAME OBJECT WITH ANIMATION
253274

254275
// instantiate prefab, parent under the Player obj transform, position is local space
255276
GameObject obj = (GameObject)Instantiate (prefab, currentPlayerScript.effects.transform, false);
256277

257-
258-
// MARKED FOR DELETION
259-
260-
// disable so particle effect doesn't start yet
261-
//obj.SetActive (false);
262-
// parent under the player obj
263-
//obj.transform.parent = currentPlayerScript.effects.transform;
264-
265-
266-
267278
// set slightly random position
268279
if (randomPosition) obj.transform.localPosition = new Vector3 (Random.Range (-2, 2), Random.Range (-2, 2), 0);
269280
// or a default position
270281
else obj.transform.localPosition = Vector3.zero;
271282

272-
273283
// set scale
274284
obj.transform.localScale = Vector3.one * scaleMultiplier;
275285

276-
// now that position is set turn it back on
277-
//obj.SetActive (true);
278-
279-
// set state
286+
// set state - not using this yet, but may need it
280287
currentPlayerScript.effectIsPlaying = true;
281288

282289

@@ -286,6 +293,7 @@ void AttachDetachAnimation (GameObject prefab, bool randomPosition, float scaleM
286293
if (destroyDelay < -0.1f) {
287294
// let the animation component destroy the gameobject after the last frame
288295
obj.GetComponent<FrameAnimation> ().playOnceAndDestroy = true;
296+
StartCoroutine (ResetEffectPlayingState (1f));
289297
}
290298
// should this function destroy the gameobject with the animation after n seconds?
291299
else if (destroyDelay > 0.1f) {
@@ -308,7 +316,7 @@ IEnumerator ResetEffectPlayingState (float wait)
308316

309317

310318

311-
IEnumerator PlayBattle (FeedData feed)
319+
IEnumerator PlayBattleEffects (FeedData feed)
312320
{
313321
Debug.Log ("PlayBattle() feed = " + feed.ToString ());
314322

0 commit comments

Comments
 (0)