From 7b8cdd87995abd72ff8f8b45e3e6c9ecd1ccf1e1 Mon Sep 17 00:00:00 2001 From: Mateus Pires Date: Tue, 1 Mar 2016 16:57:23 -0300 Subject: [PATCH] Remake quase completo --- Assets/Scripts/Player Manager/AnimationReference.cs | 6 ++++-- Assets/Scripts/Player Manager/GenericPlayerManager.cs | 384 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Assets/Scripts/Player Manager/Gloss.cs | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------ Assets/Scripts/Player Manager/RandomAnimations.cs | 21 ++++++++++++++++++++- Assets/Scripts/Player Manager/Subtitle.cs | 11 +++++++++++ Assets/Scripts/PlayerManager.cs | 36 ++++++++++++++++++++---------------- Assets/Scripts/UI/ScreenManager.cs | 6 +++--- 7 files changed, 338 insertions(+), 365 deletions(-) diff --git a/Assets/Scripts/Player Manager/AnimationReference.cs b/Assets/Scripts/Player Manager/AnimationReference.cs index 7ae7faa..1e9f094 100644 --- a/Assets/Scripts/Player Manager/AnimationReference.cs +++ b/Assets/Scripts/Player Manager/AnimationReference.cs @@ -21,13 +21,15 @@ public class AnimationReference { public AnimationReference(string name, string subtitle, short type) : this(name, subtitle, type, 0F) { - this.speed = context.getSpeedByType(Subtitle.TYPE_WORD); + this.speed = context.subtitles.getSpeedByType(Subtitle.TYPE_WORD); } - public void play() + public AnimationReference play() { this.state = context.COMPONENT_ANIMATION.CrossFadeQueued(this.name, context.fadeLength, QueueMode.CompleteOthers); this.state.speed = this.speed; + + return this; } } \ No newline at end of file diff --git a/Assets/Scripts/Player Manager/GenericPlayerManager.cs b/Assets/Scripts/Player Manager/GenericPlayerManager.cs index ab2f6ae..5222e58 100644 --- a/Assets/Scripts/Player Manager/GenericPlayerManager.cs +++ b/Assets/Scripts/Player Manager/GenericPlayerManager.cs @@ -10,15 +10,17 @@ using UnityEngine.UI; public abstract class GenericPlayerManager : MonoBehaviour { - public static GenericPlayerManager context; + private System.Object LOCKER_PLAY = new System.Object(); + private System.Object LOCKER_LOAD = new System.Object(); + private System.Object LOCKER_PARALLEL_LOAD = new System.Object(); - private const string DEFAULT_ANIMATION = "_default"; + private string RA_LOCKER_LOADANDPLAY = "LoadAndPlay"; + private string RA_LOCKER_PLAY = "Play"; - public float fadeLength = 0.6F; - public string gloss = ""; + public static GenericPlayerManager context; - // Vetor usado para quebrar a glosa - private static String[] stringPos = { DEFAULT_ANIMATION }; + public string DEFAULT_ANIMATION = "_default"; + public float fadeLength = 0.6F; // Referencia para o avatar private GameObject AVATAR; @@ -32,27 +34,26 @@ public abstract class GenericPlayerManager : MonoBehaviour { public HashSet nonexistentAssetBundles = new HashSet(); private Queue glossQueue = new Queue(); + private Gloss lastGloss = null; // Sinais de intervalo de animações: não sinaliza reprodução na UI - private HashSet intervalAnimations = new HashSet(); + public HashSet intervalAnimations = new HashSet(); // Sinais ignorados na apresentação de legenda - private HashSet flags = new HashSet(); + public HashSet flags = new HashSet(); - // True quando está reproduzindo alguma animação de intervalo - private volatile bool playingIntervalAnimation = false; // True quando está na função LoadAndPlay - private volatile bool loading = false; + public volatile bool loading = false; // True quando está reproduzindo qualquer animação - private volatile bool playing = false; + public volatile bool playing = false; // True quando é chamada a função de pausa - private volatile bool paused = false; + public volatile bool paused = false; // True quando é possível repetir - private volatile bool repeatable = false; + public volatile bool repeatable = false; // Gerenciador de animações de intervalo public RandomAnimations randomAnimations; // Gerenciados de legendas - private Subtitle subtitles = null; + public Subtitle subtitles = null; public virtual void Start() { @@ -81,11 +82,10 @@ public abstract class GenericPlayerManager : MonoBehaviour { this.intervalAnimations.Add(DEFAULT_ANIMATION); } - public bool isPlayingIntervalAnimation() { return playingIntervalAnimation; } - public bool isLoading() { return loading; } - public bool isPlaying() { return playing; } - public bool isPaused() { return paused; } - public bool isRepeatable() { return ! String.IsNullOrEmpty(gloss); } + public bool isLoading() { return this.loading; } + public bool isPlaying() { return this.playing; } + public bool isPaused() { return this.paused; } + public bool isRepeatable() { return this.lastGloss != null; } /* Configura as animações de intervalo */ public void setRandomAnimations(string[] intervalAnimations) @@ -102,67 +102,46 @@ public abstract class GenericPlayerManager : MonoBehaviour { // Define a velocidade das animacões com base no slider da GUI public void setSlider(float sliderPosition) { - subtitles.SliderPosition = sliderPosition; - subtitles.updateWordSpeed(); - subtitles.updateLetterSpeed(); - subtitles.updateNumberSpeed(); + this.subtitles.SliderPosition = sliderPosition; + this.subtitles.updateWordSpeed(); + this.subtitles.updateLetterSpeed(); + this.subtitles.updateNumberSpeed(); - if ( ! paused) lock (animQueue) - { - foreach (AnimationReference reference in animQueue) - if (reference.type != Subtitle.TYPE_NONE && reference.state != null) - reference.state.speed = getSpeedByType(reference.type); - } - } - - public float getSpeedByType(short type) - { - switch (type) + if ( ! this.paused) lock (this.glossQueue) { - case Subtitle.TYPE_WORD: return subtitles.WordSpeed; - case Subtitle.TYPE_LETTER: return subtitles.LetterSpeed; - case Subtitle.TYPE_NUMBER: return subtitles.NumberSpeed; + this.glossQueue.Peek().updateSpeed(); } - - return 2F; } - - public void stopAll() + public void stop() { - foreach (Gloss gloss in this.glossQueue) gloss.destroy(); - gloss.Clear(); - - //StopCoroutine("loadAndPlay"); - this.randomAnimations.unlockFor("loadAndPlay"); - loading = false; - - stopAnimations(); - } - - public void stopAnimations() - { - StopCoroutine("handleStates"); - this.randomAnimations.unlockFor("handleStates"); - + StopCoroutine("LoadAndPlay"); + this.randomAnimations.unlockFor(RA_LOCKER_LOADANDPLAY); + this.randomAnimations.unlockFor(RA_LOCKER_PLAY); this.subtitles.setText(""); - lock (animQueue) { animQueue.Clear(); } - - COMPONENT_ANIMATION.Stop(); - COMPONENT_ANIMATION.CrossFade(DEFAULT_ANIMATION, fadeLength, PlayMode.StopAll); + foreach (Gloss gloss in this.glossQueue) gloss.destroy(); + this.glossQueue.Clear(); - playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, "", 2F); + this.COMPONENT_ANIMATION.Stop(); + this.COMPONENT_ANIMATION.CrossFade(DEFAULT_ANIMATION, fadeLength, PlayMode.StopAll); + //this.COMPONENT_ANIMATION.CrossFadeQueued(DEFAULT_ANIMATION, context.fadeLength, QueueMode.CompleteOthers); - playing = false; - paused = false; + this.playing = false; + this.paused = false; + this.loading = false; onPlayingStateChange(); } public void repeat() { - stopAll(); - play(this.gloss, true, true, true); + stop(); + playLast(); + } + + public void playLast() { + StopCoroutine("Play"); + StartCoroutine("LoadAndPlay"); } @@ -174,26 +153,20 @@ public abstract class GenericPlayerManager : MonoBehaviour { */ public abstract WWW loadAssetBundle(string aniName); - /** * Listen to changes in the playing status. */ - protected abstract void onPlayingStateChange(); + public abstract void onPlayingStateChange(); + public void setPauseState(bool paused) { if (this.paused != paused) { this.paused = paused; - - lock (animQueue) - { - foreach (AnimationReference reference in animQueue) - if (reference.state != null) - reference.state.speed = paused ? 0F : getSpeedByType(reference.type); - } - onPlayingStateChange(); + + this.lastGloss.setPlayingState( ! paused); } } @@ -201,263 +174,84 @@ public abstract class GenericPlayerManager : MonoBehaviour { setPauseState( ! this.paused); } - public bool play() - { - if (playing) - setPauseState( ! paused); - else - return play(this.gloss, true, true, true); - - return true; - } - - public bool play(string gloss) - { - this.gloss = gloss; - return this.play(); - } - - public bool playNext(string gloss) { - this.gloss = gloss; - return play(gloss, true, false, true); - } - - private System.Object playLocker = new System.Object(); - public bool play(string gloss, bool stopLoading, bool stopPlaying, bool forceLoading) { - lock (this.playLocker) + System.Threading.Thread.Sleep(2000); + + lock (LOCKER_PLAY) { if (this.loading) { if (stopLoading) - stopAll(); + stop(); else return false; } else if (this.playing) { if (stopPlaying) - stopAnimations(); + stop(); else if ( ! forceLoading) return false; } + + lock (this.glossQueue) { this.glossQueue.Enqueue(new Gloss(gloss)); Debug.Log("Added (" + glossQueue.Count + ")"); } + StartCoroutine("LoadAndPlay"); } - StartCoroutine("loadAndPlay", gloss) return true; } - private System.Object loadingLocker = new System.Object(); - - private IEnumerator loadAndPlay(string glossText) + private IEnumerator LoadAndPlay() { - lock (this.loadingLocker) + lock (LOCKER_LOAD) { - Gloss gloss = new Gloss(glossText); - this.glossQueue.Add(gloss); - - if ( ! gloss.loaded) - yield return gloss.load(); - - yield return gloss.handle(); - + Debug.Log("LoadAndPlay"); - - - - - - this.randomAnimations.lockFor("loadAndPlay"); + this.randomAnimations.lockFor(RA_LOCKER_LOADANDPLAY); this.loading = true; - // onPlayingStateChange(); - - string lastAnimationSubtitle = ""; - bool spelled = false; + onPlayingStateChange(); - // Default - playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, "", 2F); + lock (this.glossQueue) { this.lastGloss = this.glossQueue.Dequeue(); } - if ( ! this.playing) - StartCoroutine("handleStates"); + Debug.Log(this.lastGloss.text); - stringPos = gloss.Split(' '); - - foreach (string aniName in stringPos) - { - try { - if (String.IsNullOrEmpty(aniName)) continue; - } catch (Exception e) { - UnityEngine.Debug.Log(e + " :: NotNullNotEmpty"); - } - - bool nonexistent = nonexistentAssetBundles.Contains(aniName); - bool loaded = loadedAssetBundles.Contains(aniName); - - if ( ! nonexistent && ! loaded) - { - // Função loadAssetBundle é definida pela classe filha - WWW www = loadAssetBundle(aniName); - - if (www != null) - { - yield return www; - - 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); - - if (aniClip) - { - COMPONENT_ANIMATION.AddClip(aniClip, aniName); - - loadedAssetBundles.Add(aniName); - loaded = true; - } - else UnityEngine.Debug.Log ("Sinal \"" + aniName + "\" não carregado corretamente."); - } - } - } - - // Reproduz palavra - if (loaded) - { - if (spelled) - { - // Default - playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, lastAnimationSubtitle); - spelled = false; - } - - if (this.flags.Contains(aniName) || this.intervalAnimations.Contains(aniName)) - { - lastAnimationSubtitle = ""; - playAnimation(Subtitle.TYPE_WORD, aniName, ""); - } - else - { - lastAnimationSubtitle = aniName; - playAnimation(Subtitle.TYPE_WORD, aniName); - } - } - - // Soletra palavra - else - { - // Se a animação não foi carregada e nem está marcada como não existente, - // adiciona ao set de animações não existentes - if ( ! nonexistent) - nonexistentAssetBundles.Add(aniName); - - UnityEngine.Debug.Log("~~ To spell: " + aniName); - - if (this.flags.Contains(aniName) || this.intervalAnimations.Contains(aniName)) - { - playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, "", 1.6F); - continue; - } - - // Se já houve o soletramento de alguma palavra, reproduz animação default - if (spelled) - playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, lastAnimationSubtitle, 1.6F); - else - spelled = true; - - lastAnimationSubtitle = spellWord(aniName); - } - } - - // Default - playAnimation(Subtitle.TYPE_NONE, DEFAULT_ANIMATION, ""); + if ( ! this.lastGloss.isDone() && ! this.lastGloss.isLoading()) + yield return this.lastGloss.Load(true); + else + yield return this.lastGloss.Play(); this.loading = false; - // onPlayingStateChange(); - this.randomAnimations.unlockFor("loadAndPlay"); + onPlayingStateChange(); + this.randomAnimations.unlockFor(RA_LOCKER_LOADANDPLAY); } } - private System.Object playingLocker = new System.Object(); - - /* Sincroniza as legendas com as animações. */ - IEnumerator handleStates() + private IEnumerator Play() { - lock (this.playingLocker) - { - this.randomAnimations.lockFor("handleStates"); - - // this.playing = true; - - bool isNotEmpty; + this.randomAnimations.lockFor(RA_LOCKER_PLAY); + yield return this.lastGloss.Play(); + this.randomAnimations.unlockFor(RA_LOCKER_PLAY); + } - lock (animQueue) { isNotEmpty = animQueue.Count > 0; } + public void loadIsDone() { + StartCoroutine("ParallelLoad"); + } - // Enquanto estiver executando a rotina "loadAndPlay" - // ou existir animações na fila de reprodução - while (loading || isNotEmpty) - { - if (isNotEmpty) - { - AnimationReference reference; - lock (animQueue) { reference = animQueue.Peek(); } - - this.subtitles.setText(reference.subtitle); - - if (COMPONENT_ANIMATION.IsPlaying(reference.name)) - { - bool changing = false; - - if ( ! this.playing) - { - this.playing = true; - changing = true; - } - - if (this.intervalAnimations.Contains(reference.name)) - { - if ( ! this.playingIntervalAnimation) - { - this.playingIntervalAnimation = true; - changing = true; - } - } - else if (this.playingIntervalAnimation) - { - this.playingIntervalAnimation = false; - changing = true; - } - - if (changing) onPlayingStateChange(); - - // reference.playing = true; - do { yield return null; } - while (COMPONENT_ANIMATION.IsPlaying(reference.name)); - } - - if (reference.state == null) - lock (animQueue) { animQueue.Dequeue(); } - else - yield return null; - } - else yield return null; - - this.subtitles.setText(""); - - lock (animQueue) { isNotEmpty = animQueue.Count > 0; } - } + public IEnumerator ParallelLoad() + { + lock (LOCKER_PARALLEL_LOAD) + { + this.randomAnimations.lockFor("parallelLoading"); + this.loading = true; - this.playing = false; - this.paused = false; - this.playingIntervalAnimation = false; - onPlayingStateChange(); + foreach (Gloss gloss in this.glossQueue) + if ( ! gloss.isDone() && ! gloss.isLoading()) + yield return gloss.Load(false); - this.randomAnimations.unlockFor("handleStates"); + this.loading = true; + this.randomAnimations.unlockFor("parallelLoading"); } } diff --git a/Assets/Scripts/Player Manager/Gloss.cs b/Assets/Scripts/Player Manager/Gloss.cs index 577deed..a3d652d 100644 --- a/Assets/Scripts/Player Manager/Gloss.cs +++ b/Assets/Scripts/Player Manager/Gloss.cs @@ -6,34 +6,79 @@ using System.Threading; public class Gloss { + // Começa a reproduzir as animações quando ao menos START_INDEX animações forem carregadas + // Se o numero de animações for menor que START_INDEX, então inicia quando carregar todas + private const int START_INDEX = 4; + private static System.Object LOCKER_PLAY = new System.Object(); + private GenericPlayerManager context = GenericPlayerManager.context; - private string gloss; + // Glosa em texto + public string text; + // Glosa partida em palavras private string[] tokens; + // Número de animações carregadas + // -1 : carregamento não foi iniciado + // tokens.Length : carregamento foi concluído + // * : carregando + public int loaded = -1; + // Fila de espera para fila de reprodução private Queue animations = new Queue(); + // Fila de reprodução + private Queue playing = new Queue(); - public bool loaded = false; + // Referencias para corotinas + private IEnumerator playCoroutine; + private IEnumerator handleCoroutine; - public Gloss(string gloss) + public Gloss(string text) { - this.gloss = gloss; - this.tokens = gloss.Split(' '); + this.text = text; + this.tokens = text.Split(' '); + } + + public bool isLoading() { + return this.loaded >= 0 && this.loaded < this.tokens.Length; + } + public bool isDone() { + return this.loaded == this.tokens.Length; } + /* Adiciona animação default na fila de espera */ private void addDefault() { - this.animations.Add(new AnimationReference(context.DEFAULT_ANIMATION, "", Subtitle.TYPE_NONE, 2F)); + lock (this.animations) { + this.animations.Enqueue(new AnimationReference(context.DEFAULT_ANIMATION, "", Subtitle.TYPE_NONE, 2F)); + } } - public IEnumerator load() + /* Carrega e adiciona animações (tokens) na fila de espera */ + public IEnumerator Load(bool play) { - loaded = true; + if (this.loaded >= 0) { + if (play) + { + this.playCoroutine = Play(); + context.StartCoroutine(this.playCoroutine); + } + else yield break; + } + + this.loaded = 0; addDefault(); bool spelled = false; foreach (string token in this.tokens) { + Debug.Log("loading " + token); + + if (play && this.loaded == START_INDEX) + { + this.playCoroutine = Play(); + context.StartCoroutine(this.playCoroutine); + } + if (String.IsNullOrEmpty(token) || context.nonexistentAssetBundles.Contains(token) || context.loadedAssetBundles.Contains(token)) @@ -70,7 +115,9 @@ public class Gloss { string subtitle = context.flags.Contains(token) ? token : ""; - this.animations.Add(new AnimationReference(token, subtitle, Subtitle.TYPE_WORD)); + lock (this.animations) { + this.animations.Enqueue(new AnimationReference(token, subtitle, Subtitle.TYPE_WORD)); + } } else error = "Error at Gloss.load(): clip from AssetBundle of " + token + " wasn't found"; } @@ -85,7 +132,7 @@ public class Gloss { Debug.Log(error); context.nonexistentAssetBundles.Add(token); - if (this.flags.Contains(aniName)) + if (context.flags.Contains(token)) { addDefault(); continue; @@ -99,11 +146,23 @@ public class Gloss { spellWord(token); } + + this.loaded++; } addDefault(); + + if (play) { + if (this.loaded <= START_INDEX) + { + this.playCoroutine = Play(); + context.StartCoroutine(this.playCoroutine); + } + context.loadIsDone(); + } } + /* Adiciona palavra de forma soletrada na fila de espera */ private void spellWord(string word) { // A reprodução da primeira letra deve ser longa para não ser cortada no fade @@ -121,61 +180,145 @@ public class Gloss { last = letter; - // Se for uma letra - if (letter >= 65 && letter <= 90) - this.animations.Add(new AnimationReference( - animationName, - subtitle, - Subtitle.TYPE_LETTER - )); - - // Se for um número - else if (letter >= 48 && letter <= 57) - this.animations.Add(new AnimationReference( - animationName, - subtitle, - Subtitle.TYPE_NUMBER - )); - - // Se for uma vírgula - else if (letter == 44) - this.animations.Add(new AnimationReference( - animationName, - subtitle, - Subtitle.TYPE_WORD - )); + lock (this.animations) + { + // Se for uma letra + if (letter >= 65 && letter <= 90) + this.animations.Enqueue(new AnimationReference( + animationName, + subtitle, + Subtitle.TYPE_LETTER + )); + + // Se for um número + else if (letter >= 48 && letter <= 57) + this.animations.Enqueue(new AnimationReference( + animationName, + subtitle, + Subtitle.TYPE_NUMBER + )); + + // Se for uma vírgula + else if (letter == 44) + this.animations.Enqueue(new AnimationReference( + animationName, + subtitle, + Subtitle.TYPE_WORD + )); + } context.subtitles.updateLetterSpeed(); } } - private IEnumerator play() - { - foreach (AnimationReference animation in this.animations) - animation.play(); + /* Verifica se há animações na fila de espera */ + private bool hasAnimations() { + lock (this.animations) { return this.animations.Count > 0; } + } - while (this.animations.Count > 0) + /* Verifica se há animações na fila de reprodução */ + private bool hasPlaying() { + lock (this.playing) { return this.playing.Count > 0; } + } + + /* Transfere animações da fila de espera para a fila de reprodução */ + public IEnumerator Play() + { + lock (LOCKER_PLAY) { - AnimationReference reference = this.animations.Peek(); + while (this.loaded < START_INDEX && this.loaded < this.tokens.Length) + yield return null; - this.subtitles.setText(reference.subtitle); + this.handleCoroutine = Handle(); + context.StartCoroutine(this.handleCoroutine); - while (COMPONENT_ANIMATION.IsPlaying(reference.name)) - yield return null; + context.playing = true; + context.onPlayingStateChange(); + + bool isPlaying = hasAnimations(); - if (reference.state == null) - this.animations.Dequeue(); - else + while (isPlaying || this.loaded < this.tokens.Length) + { + if (isPlaying) + { + AnimationReference reference; + lock (this.animations) { reference = this.animations.Dequeue(); } + + reference.play(); + lock (this.playing) { this.playing.Enqueue(reference); } + } + + isPlaying = hasAnimations(); yield return null; + } + + context.playing = false; + context.onPlayingStateChange(); + } + } + + /** Observa animações sendo reproduzidas + * Atualiza legenda e retira da fila de reprodução */ + private IEnumerator Handle() + { + bool notify = true; + bool isPlaying = hasPlaying(); + + while (isPlaying || hasAnimations() || isLoading()) { + if (isPlaying) + { + if (notify) + { + notify = false; + context.playing = true; + context.onPlayingStateChange(); + } + + AnimationReference reference = this.playing.Peek(); + + context.subtitles.setText(reference.subtitle); + + while (context.COMPONENT_ANIMATION.IsPlaying(reference.name)) + yield return null; + + if (reference.state == null) + lock (this.animations) { this.animations.Dequeue(); } + else + yield return null; + } + + isPlaying = hasPlaying(); } - this.subtitles.setText(""); + context.subtitles.setText(""); + + context.playing = true; + context.onPlayingStateChange(); + } + + /* Para animações (false) ou atualiza velocidade (true) */ + public void setPlayingState(bool active) + { + lock (this.animations) { + lock (this.playing) + { + foreach (AnimationReference reference in this.animations) + if (reference.type != Subtitle.TYPE_NONE && reference.state != null) + reference.state.speed = active ? context.subtitles.getSpeedByType(reference.type) : 0F; + } + } + } + + /* Atualiza velocidade */ + public void updateSpeed() { + setPlayingState(true); } + /* Termina glosa */ public void destroy() { - context.StopCoroutine("load"); - context.StopCoroutine("handle"); + context.StopCoroutine(this.playCoroutine); + context.StopCoroutine(this.handleCoroutine); } } diff --git a/Assets/Scripts/Player Manager/RandomAnimations.cs b/Assets/Scripts/Player Manager/RandomAnimations.cs index 9ecd303..5097ed7 100644 --- a/Assets/Scripts/Player Manager/RandomAnimations.cs +++ b/Assets/Scripts/Player Manager/RandomAnimations.cs @@ -67,6 +67,7 @@ public class RandomAnimations : MonoBehaviour { if (isNotBlocked) { + Debug.Log("wait: " + this.time); yield return new WaitForSeconds(this.time); lock (this.blockingObjects) { @@ -81,7 +82,25 @@ public class RandomAnimations : MonoBehaviour { if (index == this.lastIndex) index = sortIndex(); - this.playerManager.play(this.names[index], true, false, true); + this.playerManager.COMPONENT_ANIMATION.CrossFadeQueued( + this.playerManager.DEFAULT_ANIMATION, + this.playerManager.fadeLength, + QueueMode.CompleteOthers + ); + this.playerManager.COMPONENT_ANIMATION.CrossFadeQueued( + this.names[index], + this.playerManager.fadeLength, + QueueMode.CompleteOthers + ); + this.playerManager.COMPONENT_ANIMATION.CrossFadeQueued( + this.playerManager.DEFAULT_ANIMATION, + this.playerManager.fadeLength, + QueueMode.CompleteOthers + ); + + Debug.Log("wait: " + 4); + yield return new WaitForSeconds(4); + //this.playerManager.play(this.names[index], true, false, true); } } diff --git a/Assets/Scripts/Player Manager/Subtitle.cs b/Assets/Scripts/Player Manager/Subtitle.cs index 81b6773..6e1f26f 100644 --- a/Assets/Scripts/Player Manager/Subtitle.cs +++ b/Assets/Scripts/Player Manager/Subtitle.cs @@ -114,6 +114,17 @@ public class Subtitle { this.NumberSpeed = this.DefaultNumberSpeed.getProportional(this.SliderPosition); } + public float getSpeedByType(short type) + { + switch (type) + { + case TYPE_WORD: return this.wordSpeed; + case TYPE_LETTER: return this.letterSpeed; + case TYPE_NUMBER: return this.numberSpeed; + } + + return 2F; + } /* Destaca caractere de uma string. */ public static string highlight(string word, int index) diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index cd7e216..f075720 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -53,15 +53,11 @@ public class PlayerManager : GenericPlayerManager { TouchScreenKeyboard.hideInput = true; } - public void start_play() { - base.play(); - } - // Stop loading, if loading // Don't stop animations, if playing // Load glosa, enqueue animations - public void forcePlayFromCache() { - base.play(base.gloss, true, false, true); + public void forcePlay(string gloss) { + base.play(gloss, true, false, true); } public void start_play(string gloss) @@ -69,13 +65,13 @@ public class PlayerManager : GenericPlayerManager { if (gloss == null || String.IsNullOrEmpty(gloss.Trim())) return; - base.gloss = gloss; - forcePlayFromCache(); + forcePlay(gloss); } public void playDict(string word) { - base.gloss = word; + Debug.Log(word); + base.play(word, true, true, true); this.screenManager.hideScreen(); @@ -96,6 +92,11 @@ public class PlayerManager : GenericPlayerManager { this.randomAnimations.unlockFor("translate"); } + string gloss; + public void translationErrorPlay() { + start_play(gloss); + } + public Text debugText; public override WWW loadAssetBundle(string aniName) { @@ -117,13 +118,11 @@ public class PlayerManager : GenericPlayerManager { private System.Object stateLocker = new System.Object(); - protected override void onPlayingStateChange() + public override void onPlayingStateChange() { lock (this.stateLocker) { - //this.screenManager.setRepeatLayerState(base.isRepeatable() && ! base.isPlaying()); - - if (base.isPlaying() && ! base.isPlayingIntervalAnimation()) + if (base.isPlaying()) { setPlayingState(true); @@ -138,7 +137,12 @@ public class PlayerManager : GenericPlayerManager { this.screenManager.setPauseMenuState(false); } } - else setPlayingState(false); + else + { + setPlayingState(false); + + // TODO repeat button + } } } @@ -177,7 +181,7 @@ public class PlayerManager : GenericPlayerManager { { Debug.Log("Server answer: " + glossRequest.text); - base.playNext(glossRequest.text); + forcePlay(glossRequest.text); this.screenManager.setLoadingSnippetState(false); base.randomAnimations.unlockFor("translate"); @@ -189,7 +193,7 @@ public class PlayerManager : GenericPlayerManager { } else Debug.Log ("Error at PlayerManager.translate: (WWW) glosaRequest is NULL."); - base.gloss = gloss.ToUpper(); + this.gloss = gloss.ToUpper(); this.screenManager.setLoadingSnippetState(false); this.screenManager.showConnectionErrorDialog(); diff --git a/Assets/Scripts/UI/ScreenManager.cs b/Assets/Scripts/UI/ScreenManager.cs index df2225d..8eeb47d 100644 --- a/Assets/Scripts/UI/ScreenManager.cs +++ b/Assets/Scripts/UI/ScreenManager.cs @@ -112,10 +112,10 @@ public class ScreenManager : MonoBehaviour { screen.SetActive(true); - if (playerManager.isPlayingIntervalAnimation()) - playerManager.stopAll(); + //if (playerManager.isPlayingIntervalAnimation()) + // playerManager.stopAll(); - else if (playerManager.isPlaying()) + if (playerManager.isPlaying()) { playerManager.setPauseState(true); setPauseMenuState(true); -- libgit2 0.21.2