Commit 9597262ebb93529fbb248da4286663bf9fa40058
1 parent
b5772880
Exists in
master
and in
6 other branches
Correção na sincronização da legenda quando é pausado durante a soletração no mo…
…mento em que se está reproduzindo animações curtas.
Showing
5 changed files
with
90 additions
and
13 deletions
Show diff stats
Assets/Scripts/Player Manager/GenericPlayerManager.cs
@@ -61,6 +61,8 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -61,6 +61,8 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
61 | // Gerenciados de legendas | 61 | // Gerenciados de legendas |
62 | private Subtitle subtitles = null; | 62 | private Subtitle subtitles = null; |
63 | 63 | ||
64 | + private bool[] lastLetterAnimations = new bool[256]; | ||
65 | + | ||
64 | public virtual void Start() | 66 | public virtual void Start() |
65 | { | 67 | { |
66 | // Configuração de velocidade das animações | 68 | // Configuração de velocidade das animações |
@@ -256,7 +258,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -256,7 +258,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
256 | 258 | ||
257 | lock (this.animQueue) | 259 | lock (this.animQueue) |
258 | { | 260 | { |
259 | - if (this.animationPlaying.state != null) | 261 | + if (this.animationPlaying != null && this.animationPlaying.state != null) |
260 | this.animationPlaying.state.speed = paused ? 0F : getSpeedByType(this.animationPlaying.type); | 262 | this.animationPlaying.state.speed = paused ? 0F : getSpeedByType(this.animationPlaying.type); |
261 | 263 | ||
262 | foreach (AnimationReference reference in this.animQueue) | 264 | foreach (AnimationReference reference in this.animQueue) |
@@ -328,6 +330,14 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -328,6 +330,14 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
328 | return true; | 330 | return true; |
329 | } | 331 | } |
330 | 332 | ||
333 | + private string nextLetterAnimation(char letter) | ||
334 | + { | ||
335 | + string animation = (this.lastLetterAnimations[letter] ? "" : "d_") + letter.ToString(); | ||
336 | + this.lastLetterAnimations[letter] = ! this.lastLetterAnimations[letter]; | ||
337 | + | ||
338 | + return animation; | ||
339 | + } | ||
340 | + | ||
331 | /* Enfileira soletração de palavra */ | 341 | /* Enfileira soletração de palavra */ |
332 | private string spellWord(Queue<ToPlay> toPlayQueue, string word) | 342 | private string spellWord(Queue<ToPlay> toPlayQueue, string word) |
333 | { | 343 | { |
@@ -342,9 +352,8 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -342,9 +352,8 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
342 | for (int i = 0; i < word.Length; i++) | 352 | for (int i = 0; i < word.Length; i++) |
343 | { | 353 | { |
344 | lastAnimationSubtitle = Subtitle.highlight(word, i); | 354 | lastAnimationSubtitle = Subtitle.highlight(word, i); |
345 | - | ||
346 | - string anim = word[i].ToString(); | ||
347 | - lastAnim = anim.Equals(lastAnim) ? "d_" + anim : anim; | 355 | + lastAnim = nextLetterAnimation(word[i]); |
356 | + //anim.Equals(lastAnim) ? "d_" + anim : anim; | ||
348 | 357 | ||
349 | short type; | 358 | short type; |
350 | 359 | ||
@@ -555,19 +564,26 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -555,19 +564,26 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
555 | bool isNotEmpty; | 564 | bool isNotEmpty; |
556 | lock (this.animQueue) { isNotEmpty = this.animQueue.Count > 0; } | 565 | lock (this.animQueue) { isNotEmpty = this.animQueue.Count > 0; } |
557 | 566 | ||
558 | - // Enquanto estiver executando a rotina "loadAndPlay" | 567 | + // Animação anterior a atual |
568 | + AnimationReference endedAnimation = null; | ||
569 | + | ||
570 | + // Enquanto estiver executando a corotina "loadAndPlay" | ||
559 | // ou existir animações na fila de reprodução | 571 | // ou existir animações na fila de reprodução |
560 | while (loading || isNotEmpty) | 572 | while (loading || isNotEmpty) |
561 | { | 573 | { |
574 | + // Se não houver animações na fila, espera | ||
562 | if (isNotEmpty) | 575 | if (isNotEmpty) |
563 | { | 576 | { |
577 | + // Pega primeira animação | ||
564 | AnimationReference reference; | 578 | AnimationReference reference; |
565 | lock (this.animQueue) { reference = this.animQueue.Peek(); } | 579 | lock (this.animQueue) { reference = this.animQueue.Peek(); } |
566 | 580 | ||
567 | - this.subtitles.setText(reference.subtitle); | ||
568 | - | 581 | + // Se estiver sendo reproduzida |
569 | if (COMPONENT_ANIMATION.IsPlaying(reference.name)) | 582 | if (COMPONENT_ANIMATION.IsPlaying(reference.name)) |
570 | { | 583 | { |
584 | + this.subtitles.setText(reference.subtitle); | ||
585 | + | ||
586 | + // Animação seguinte | ||
571 | AnimationReference next = null; | 587 | AnimationReference next = null; |
572 | lock (this.animQueue) | 588 | lock (this.animQueue) |
573 | { | 589 | { |
@@ -579,21 +595,36 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -579,21 +595,36 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
579 | 595 | ||
580 | while (true) | 596 | while (true) |
581 | { | 597 | { |
598 | + // Se a próxima animação estiver sendo reproduzida (no fade) | ||
582 | if (next != null && COMPONENT_ANIMATION.IsPlaying(next.name)) | 599 | if (next != null && COMPONENT_ANIMATION.IsPlaying(next.name)) |
583 | { | 600 | { |
601 | + // Se a animação anterior a atual não tiver acabado, | ||
602 | + // espera acabar e só então conta o tempo | ||
603 | + if (endedAnimation != null) | ||
604 | + while (COMPONENT_ANIMATION.IsPlaying(endedAnimation.name)) | ||
605 | + yield return null; | ||
606 | + | ||
607 | + // Tempo para pular para a legenda da próxima animação | ||
584 | yield return new WaitForSeconds(0.4F); | 608 | yield return new WaitForSeconds(0.4F); |
609 | + | ||
610 | + // Deprecated | ||
611 | + // yield return WaitForContinuousMillis.Wait(this, 300); | ||
612 | + | ||
613 | + endedAnimation = reference; | ||
585 | break; | 614 | break; |
586 | } | 615 | } |
616 | + | ||
587 | else if (COMPONENT_ANIMATION.IsPlaying(reference.name)) | 617 | else if (COMPONENT_ANIMATION.IsPlaying(reference.name)) |
588 | - { | ||
589 | yield return null; | 618 | yield return null; |
590 | - } | 619 | + |
591 | else break; | 620 | else break; |
592 | } | 621 | } |
593 | 622 | ||
594 | reference = null; | 623 | reference = null; |
595 | } | 624 | } |
596 | 625 | ||
626 | + // Se a animação não tiver sido liberada e seu AnimationState for nulo, | ||
627 | + // a animação será liberada | ||
597 | if (reference != null && reference.state == null) | 628 | if (reference != null && reference.state == null) |
598 | lock (this.animQueue) { this.animQueue.Dequeue(); } | 629 | lock (this.animQueue) { this.animQueue.Dequeue(); } |
599 | else | 630 | else |
@@ -601,11 +632,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -601,11 +632,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
601 | } | 632 | } |
602 | else yield return null; | 633 | else yield return null; |
603 | 634 | ||
604 | - this.subtitles.setText(""); | ||
605 | - | ||
606 | lock (this.animQueue) { isNotEmpty = this.animQueue.Count > 0; } | 635 | lock (this.animQueue) { isNotEmpty = this.animQueue.Count > 0; } |
607 | } | 636 | } |
608 | 637 | ||
638 | + this.subtitles.setText(""); | ||
639 | + | ||
609 | resetStates(); | 640 | resetStates(); |
610 | this.randomAnimations.unlockFor("handleStates"); | 641 | this.randomAnimations.unlockFor("handleStates"); |
611 | } | 642 | } |
Assets/Scripts/UI/ScreenManager.cs
@@ -164,8 +164,8 @@ public class ScreenManager : MonoBehaviour { | @@ -164,8 +164,8 @@ public class ScreenManager : MonoBehaviour { | ||
164 | 164 | ||
165 | public void setPauseMenuState(bool active) | 165 | public void setPauseMenuState(bool active) |
166 | { | 166 | { |
167 | - if (this.pauseMenu.activeSelf != active) | ||
168 | - this.pauseMenu.SetActive(active); | 167 | + this.pauseMenu.SetActive(active); |
168 | + setAvatarColliderState( ! active); | ||
169 | } | 169 | } |
170 | 170 | ||
171 | public void setLoadingSnippetState(bool active) | 171 | public void setLoadingSnippetState(bool active) |
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +using UnityEngine; | ||
2 | +using System.Collections; | ||
3 | +using System.Diagnostics; | ||
4 | + | ||
5 | +public class WaitForContinuousMillis { | ||
6 | + | ||
7 | + /* Corotina que espera millis milésimos, mas que conta o tempo apenas | ||
8 | + * quando as animações sendo reproduzidas não estão pausadas. | ||
9 | + */ | ||
10 | + public static IEnumerator Wait(GenericPlayerManager context, long millis) | ||
11 | + { | ||
12 | + Stopwatch watch = new Stopwatch(); | ||
13 | + watch.Start(); | ||
14 | + | ||
15 | + while (true) | ||
16 | + { | ||
17 | + if (watch.ElapsedMilliseconds < millis) | ||
18 | + { | ||
19 | + UnityEngine.Debug.Log(millis); | ||
20 | + | ||
21 | + if (context.isPaused()) { | ||
22 | + if (watch.IsRunning) | ||
23 | + watch.Stop(); | ||
24 | + } | ||
25 | + else if ( ! watch.IsRunning) | ||
26 | + watch.Start(); | ||
27 | + | ||
28 | + yield return null; | ||
29 | + } | ||
30 | + else break; | ||
31 | + } | ||
32 | + } | ||
33 | + | ||
34 | +} |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +fileFormatVersion: 2 | ||
2 | +guid: 3d8662a14b9d0bd4a8625f41ae18ba5a | ||
3 | +timeCreated: 1458595282 | ||
4 | +licenseType: Pro | ||
5 | +MonoImporter: | ||
6 | + serializedVersion: 2 | ||
7 | + defaultReferences: [] | ||
8 | + executionOrder: 0 | ||
9 | + icon: {instanceID: 0} | ||
10 | + userData: | ||
11 | + assetBundleName: | ||
12 | + assetBundleVariant: |
No preview for this file type