diff --git a/Assets/Resources/sinais.txt b/Assets/Resources/sinais.txt index ee76a0c..22a779f 100644 --- a/Assets/Resources/sinais.txt +++ b/Assets/Resources/sinais.txt @@ -1,5 +1,3 @@ - -% , 0 1 @@ -2351,16 +2349,6 @@ CUSTEAR CUSTOSO CUTANEO CUTUCAR -Cotovelo -Cozinheira -Cpf -Crer -Crianca -Cueca -Cuidadoso -Cumprimentos -Cunhada -Curitiba DÓLAR D DA @@ -2848,7 +2836,7 @@ DIGITADOR DIGITAL DIGITALIZADA DIGITALIZADO -DIGITAR 23-Sep-2015 17:56 61K +DIGITAR DIGITO DIGNIDADE DIGNO @@ -3054,18 +3042,18 @@ DURO DUVIDA DUVIDOSO DVD -Dama -Decidir -Dedo -Default Take -Descer -Diminuir -Diretor -Disputar -Distrito-federal -Dividir -Divorciar -Domino +DAMA +DECIDIR +DEDO +DEFAULT TAKE +DESCER +DIMINUIR +DIRETOR +DISPUTAR +DISTRITO-FEDERAL +DIVIDIR +DIVORCIAR +DOMINO E EBRIO ECOLOGIA @@ -5249,7 +5237,7 @@ LACRIMEJANTE LACRIMEJAR LACTEO LACTOSE -LADO24-Sep-2015 09:59 19K +LADO LADRAR LADRILHO LAGARTA diff --git a/Assets/Scripts/Animation List/ListManager.cs b/Assets/Scripts/Animation List/ListManager.cs index a4f28d0..96af546 100644 --- a/Assets/Scripts/Animation List/ListManager.cs +++ b/Assets/Scripts/Animation List/ListManager.cs @@ -48,7 +48,7 @@ public class ListManager : MonoBehaviour { public IEnumerator Load() { - string[] lines; + /*string[] lines; WWW www = new WWW("http://150.165.205.9/anims/sinais.txt"); yield return www; @@ -60,7 +60,19 @@ public class ListManager : MonoBehaviour { else { lines = www.text.Split("\n"[0]); - } + }*/ + + WWW www = new WWW("file:///" + Application.dataPath + "/Resources/sinais.txt"); + yield return www; + + Debug.Log(Application.dataPath); + + string[] lines = new string[0]; + + if (string.IsNullOrEmpty(www.error)) + lines = System.Text.Encoding.UTF8.GetString(www.bytes, 0, www.bytes.Length).Split('\n'); + else + Debug.Log(www.error); this.trie = new TrieST(); @@ -96,6 +108,7 @@ public class ListManager : MonoBehaviour { Destroy(go); populateList(); + this.scrollView.verticalNormalizedPosition = 1F; } private void populateList() diff --git a/Assets/Scripts/Animation List/TrieST.cs b/Assets/Scripts/Animation List/TrieST.cs index cdc3b46..ad353b7 100644 --- a/Assets/Scripts/Animation List/TrieST.cs +++ b/Assets/Scripts/Animation List/TrieST.cs @@ -47,12 +47,12 @@ public class TrieST public void put(String key, String val) { - root = put(root, key, val, 0); + if ( ! String.IsNullOrEmpty(key) && ! String.IsNullOrEmpty(val)) + root = put(root, key, val, 0); } private Node put(Node x, String key, String val, int d) { - if (x == null) x = new Node(); if (d == key.Length) { @@ -60,10 +60,16 @@ public class TrieST x.val = val; return x; } - int c = indexes[key[d]]; - x.next[c] = put(x.next[c], key, val, d + 1); - return x; + try { + int c = indexes[key[d]]; + x.next[c] = put(x.next[c], key, val, d + 1); + } + catch (IndexOutOfRangeException) { + Debug.Log("Error at TrieST.put: { key: " + key + "; index: " + d + "; value: " + ((int) key[d]) + " }" + key); + } + + return x; } public Queue keys() diff --git a/Assets/Scripts/Player Manager/GenericPlayerManager.cs b/Assets/Scripts/Player Manager/GenericPlayerManager.cs index 51adc9a..513a556 100644 --- a/Assets/Scripts/Player Manager/GenericPlayerManager.cs +++ b/Assets/Scripts/Player Manager/GenericPlayerManager.cs @@ -1,8 +1,12 @@ /** Gerenciador genérico e principal dos players. * - * Versão: 2.1 + * Versão 2.1 * - Acompanhamento da legenda - * Corrigido problema na soletração quando a velocidade ultrapassava ~1 + * Corrigido problema na soletração quando a velocidade ultrapassava ~1. + * + * Versão 2.2 + * - Acompanhamento da legenda + * Corrigido problema na soletração quando o estado muda para pausado. */ //Log Dir http://docs.unity3d.com/Manual/LogFiles.html @@ -53,12 +57,16 @@ public abstract class GenericPlayerManager : MonoBehaviour { // Se diferente de null, não está reproduzindo animação de intervalo private AnimationState intervalAnimationState = null; + // Usado para pausar quando comandado + private AnimationReference animationPlaying = null; // Gerenciador de animações de intervalo public RandomAnimations randomAnimations; // Gerenciados de legendas private Subtitle subtitles = null; + private bool[] lastLetterAnimations = new bool[256]; + public virtual void Start() { // Configuração de velocidade das animações @@ -80,20 +88,21 @@ public abstract class GenericPlayerManager : MonoBehaviour { foreach (string flag in flags) this.flags.Add(flag); - // Duplica sinais para diferenciar quando há repetidos - string[] toDuplicate = new string[] { + string[] preloadedAnims = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", - "," + "," }; - foreach (string anim in toDuplicate) + + // Duplica sinais para diferenciar quando há repetidos + foreach (string anim in preloadedAnims) COMPONENT_ANIMATION.AddClip(COMPONENT_ANIMATION[anim].clip, "d_" + anim); - // Sinal default é tratado como animação de intervalo: não sinaliza reprodução na UI - //this.intervalAnimations.Add(DEFAULT_ANIMATION); + foreach (string anim in preloadedAnims) + this.loadedAssetBundles.Add(anim); // Cria novo _default chamado _default_middle para pausas dentro de uma glosa // Impede que a animação default seja confundida com não-reprodução na UI @@ -131,9 +140,9 @@ public abstract class GenericPlayerManager : MonoBehaviour { subtitles.updateNumberSpeed(); // Altera a velocidade de todas as animações em reprodução - if ( ! paused) lock (animQueue) + if ( ! paused) lock (this.animQueue) { - foreach (AnimationReference reference in animQueue) + foreach (AnimationReference reference in this.animQueue) if (reference.type != Subtitle.TYPE_NONE && reference.state != null) reference.state.speed = getSpeedByType(reference.type); } @@ -169,12 +178,10 @@ public abstract class GenericPlayerManager : MonoBehaviour { this.randomAnimations.unlockFor("handleStates"); this.subtitles.setText(""); - lock (animQueue) { animQueue.Clear(); } + lock (this.animQueue) { this.animQueue.Clear(); } COMPONENT_ANIMATION.CrossFadeQueued(DEFAULT_ANIMATION, fadeLength, QueueMode.PlayNow); - playing = false; - paused = false; - onPlayingStateChange(); + resetStates(); } /* Repete animações */ @@ -198,7 +205,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { state.speed = speed; lock (this.animQueue) { - animQueue.Enqueue(new AnimationReference(name, subtitle, state, type)); + this.animQueue.Enqueue(new AnimationReference(name, subtitle, state, type)); } return state; @@ -235,12 +242,17 @@ public abstract class GenericPlayerManager : MonoBehaviour { */ protected abstract WWW loadAssetBundle(string aniName); + /** + * Listen to changes in the playing status. + */ + protected abstract void onConnectionError(string gloss, string word); /** * Listen to changes in the playing status. */ protected abstract void onPlayingStateChange(); + /* Pause or continue animations */ public void setPauseState(bool paused) { @@ -248,15 +260,22 @@ public abstract class GenericPlayerManager : MonoBehaviour { { this.paused = paused; - lock (animQueue) + lock (this.animQueue) { - foreach (AnimationReference reference in animQueue) + if (this.animationPlaying != null && this.animationPlaying.state != null) + this.animationPlaying.state.speed = paused ? 0F : getSpeedByType(this.animationPlaying.type); + + foreach (AnimationReference reference in this.animQueue) if (reference.state != null) reference.state.speed = paused ? 0F : getSpeedByType(reference.type); } - - onPlayingStateChange(); } + + onPlayingStateChange(); + } + + public void setAnimationEnabled(bool enabled) { + COMPONENT_ANIMATION.enabled = enabled; } /* Pause or continue animations */ @@ -315,6 +334,14 @@ public abstract class GenericPlayerManager : MonoBehaviour { return true; } + private string nextLetterAnimation(char letter) + { + string animation = (this.lastLetterAnimations[letter] ? "" : "d_") + letter.ToString(); + this.lastLetterAnimations[letter] = ! this.lastLetterAnimations[letter]; + + return animation; + } + /* Enfileira soletração de palavra */ private string spellWord(Queue toPlayQueue, string word) { @@ -329,9 +356,8 @@ public abstract class GenericPlayerManager : MonoBehaviour { for (int i = 0; i < word.Length; i++) { lastAnimationSubtitle = Subtitle.highlight(word, i); - - string anim = word[i].ToString(); - lastAnim = anim.Equals(lastAnim) ? "d_" + anim : anim; + lastAnim = nextLetterAnimation(word[i]); + //anim.Equals(lastAnim) ? "d_" + anim : anim; short type; @@ -443,23 +469,29 @@ public abstract class GenericPlayerManager : MonoBehaviour { AssetBundle bundle = null; if (www.error == null) - bundle = www.assetBundle; - - if (bundle != null && ! String.IsNullOrEmpty(bundle.mainAsset.name)) { - AnimationClip aniClip = bundle.mainAsset as AnimationClip; - bundle.Unload(false); + bundle = www.assetBundle; - if (aniClip) + if (bundle != null && ! String.IsNullOrEmpty(bundle.mainAsset.name)) { - COMPONENT_ANIMATION.AddClip(aniClip, aniName); + AnimationClip aniClip = bundle.mainAsset as AnimationClip; + bundle.Unload(false); + + if (aniClip) + { + COMPONENT_ANIMATION.AddClip(aniClip, aniName); + + loadedAssetBundles.Add(aniName); + loaded = true; - loadedAssetBundles.Add(aniName); - loaded = true; + Debug.Log("Bundle \"" + aniName + "\" loaded!"); + } + else UnityEngine.Debug.Log ("Sinal \"" + aniName + "\" foi não carregado corretamente."); } - else UnityEngine.Debug.Log ("Sinal \"" + aniName + "\" não carregado corretamente."); } + else onConnectionError(gloss, aniName); } + else onConnectionError(gloss, aniName); } // Reproduz palavra @@ -496,18 +528,19 @@ public abstract class GenericPlayerManager : MonoBehaviour { if (this.flags.Contains(aniName) || this.intervalAnimations.Contains(aniName)) { - //playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, "", 1.6F); toPlayQueue.Enqueue(new ToPlay(Subtitle.TYPE_NONE, DEFAULT_ANIMATION_MIDDLE, "", 1.6F)); - continue; + spelled = false; } - - // Se já houve o soletramento de alguma palavra, reproduz animação default - if (spelled) - toPlayQueue.Enqueue(new ToPlay(Subtitle.TYPE_NONE, DEFAULT_ANIMATION_MIDDLE, lastAnimationSubtitle, 1.6F)); else - spelled = true; + { + // Se já houve o soletramento de alguma palavra, reproduz animação default + if (spelled) + toPlayQueue.Enqueue(new ToPlay(Subtitle.TYPE_NONE, DEFAULT_ANIMATION_MIDDLE, "", 1.6F)); + else + spelled = true; - lastAnimationSubtitle = spellWord(toPlayQueue, aniName); + lastAnimationSubtitle = spellWord(toPlayQueue, aniName); + } } if (toPlayQueue.Count > 4 || wordsCount == stringPos.Length) @@ -536,65 +569,93 @@ public abstract class GenericPlayerManager : MonoBehaviour { onPlayingStateChange(); bool isNotEmpty; - lock (animQueue) { isNotEmpty = animQueue.Count > 0; } + lock (this.animQueue) { isNotEmpty = this.animQueue.Count > 0; } + + // Animação anterior a atual + AnimationReference endedAnimation = null; - // Enquanto estiver executando a rotina "loadAndPlay" + // Enquanto estiver executando a corotina "loadAndPlay" // ou existir animações na fila de reprodução while (loading || isNotEmpty) { + // Se não houver animações na fila, espera if (isNotEmpty) { + // Pega primeira animação AnimationReference reference; - lock (animQueue) { reference = animQueue.Peek(); } - - this.subtitles.setText(reference.subtitle); + lock (this.animQueue) { reference = this.animQueue.Peek(); } + // Se estiver sendo reproduzida if (COMPONENT_ANIMATION.IsPlaying(reference.name)) { + this.subtitles.setText(reference.subtitle); + + // Animação seguinte AnimationReference next = null; - lock (animQueue) + lock (this.animQueue) { - animQueue.Dequeue(); + this.animationPlaying = this.animQueue.Dequeue(); - if (animQueue.Count > 0) - next = animQueue.Peek(); + if (this.animQueue.Count > 0) + next = this.animQueue.Peek(); } while (true) { + // Se a próxima animação estiver sendo reproduzida (no fade) if (next != null && COMPONENT_ANIMATION.IsPlaying(next.name)) { + // Se a animação anterior a atual não tiver acabado, + // espera acabar e só então conta o tempo + if (endedAnimation != null) + while (COMPONENT_ANIMATION.IsPlaying(endedAnimation.name)) + yield return null; + + // Tempo para pular para a legenda da próxima animação yield return new WaitForSeconds(0.4F); + + // Deprecated + // yield return WaitForContinuousMillis.Wait(this, 300); + + endedAnimation = reference; break; } + else if (COMPONENT_ANIMATION.IsPlaying(reference.name)) - { yield return null; - } + else break; } reference = null; } + // Se a animação não tiver sido liberada e seu AnimationState for nulo, + // a animação será liberada if (reference != null && reference.state == null) - lock (animQueue) { animQueue.Dequeue(); } + lock (this.animQueue) { this.animQueue.Dequeue(); } else yield return null; } else yield return null; - this.subtitles.setText(""); - - lock (animQueue) { isNotEmpty = animQueue.Count > 0; } + lock (this.animQueue) { isNotEmpty = this.animQueue.Count > 0; } } - this.playing = false; - this.paused = false; - onPlayingStateChange(); + this.subtitles.setText(""); + resetStates(); this.randomAnimations.unlockFor("handleStates"); } } + public void resetStates() + { + this.animationPlaying = null; + this.playing = false; + this.paused = false; + + onPlayingStateChange(); + } + } diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index 54226cf..9d0149c 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -74,6 +74,8 @@ public class PlayerManager : GenericPlayerManager { return null; } + protected override void onConnectionError(string gloss, string word) { } + void OnApplicationQuit() { try { diff --git a/Assets/Scripts/UI/FadeFX.cs b/Assets/Scripts/UI/FadeFX.cs index b994d14..4f89cc1 100644 --- a/Assets/Scripts/UI/FadeFX.cs +++ b/Assets/Scripts/UI/FadeFX.cs @@ -39,7 +39,7 @@ public class FadeFX : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { private void Activate() { this.active = true; - this.screenManager.setAvatarColliderState(false); + //this.screenManager.setAvatarColliderState(false); foreach (CanvasRenderer renderer in this.renderers) renderer.SetAlpha(1F); @@ -61,7 +61,7 @@ public class FadeFX : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { if ( ! SwitchResolution.showbox && ! update_box.activeSelf) { this.active = false; - this.screenManager.setAvatarColliderState(true); + //this.screenManager.setAvatarColliderState(true); foreach (CanvasRenderer renderer in this.renderers) renderer.SetAlpha(0.2F); -- libgit2 0.21.2