From 327ce306a67874148fb10c374dc17fa59eca09de Mon Sep 17 00:00:00 2001 From: Mateus Pires Date: Fri, 22 Jan 2016 19:08:26 -0200 Subject: [PATCH] RandomAnimations incompleto --- Assets/Bundles/APURAR | Bin 0 -> 3253026 bytes Assets/Bundles/AQUILO | Bin 0 -> 3255035 bytes Assets/Scenes/Scene.unity | 12 ++++++------ Assets/Scripts/Player Manager/GenericPlayerManager.cs | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------- Assets/Scripts/Player Manager/RandomAnimations.cs | 62 ++++++++++++++++++++++++++++++++++++++++---------------------- Assets/Scripts/Player Manager/getenough.py | 5 +++++ Assets/Scripts/Player Manager/getenough.py.meta | 8 ++++++++ Assets/Scripts/PlayerManager.cs | 5 +++-- 8 files changed, 150 insertions(+), 67 deletions(-) create mode 100644 Assets/Bundles/APURAR create mode 100644 Assets/Bundles/AQUILO create mode 100644 Assets/Scripts/Player Manager/getenough.py create mode 100644 Assets/Scripts/Player Manager/getenough.py.meta diff --git a/Assets/Bundles/APURAR b/Assets/Bundles/APURAR new file mode 100644 index 0000000..c8a9022 Binary files /dev/null and b/Assets/Bundles/APURAR differ diff --git a/Assets/Bundles/AQUILO b/Assets/Bundles/AQUILO new file mode 100644 index 0000000..d4b3ae0 Binary files /dev/null and b/Assets/Bundles/AQUILO differ diff --git a/Assets/Scenes/Scene.unity b/Assets/Scenes/Scene.unity index 1b9acd5..b5fc52f 100644 --- a/Assets/Scenes/Scene.unity +++ b/Assets/Scenes/Scene.unity @@ -425,7 +425,7 @@ Prefab: objectReference: {fileID: 2100000, guid: 3e98fe09c9ac4ae4dbe731872ff7687a, type: 2} - target: {fileID: 11474732, guid: 00197fc9877daa14c963e5917de36124, type: 2} propertyPath: m_Enabled - value: 0 + value: 1 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: 00197fc9877daa14c963e5917de36124, type: 2} @@ -1398,23 +1398,23 @@ Prefab: objectReference: {fileID: 138791195} - target: {fileID: 22412692, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} propertyPath: m_AnchorMax.x - value: 0 + value: .444444448 objectReference: {fileID: 0} - target: {fileID: 22412692, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} propertyPath: m_AnchorMax.y - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} propertyPath: m_AnchorMin.x - value: 0 + value: .444444448 objectReference: {fileID: 0} - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} propertyPath: m_AnchorMax.x - value: 0 + value: .444444448 objectReference: {fileID: 0} - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} propertyPath: m_AnchorMax.y - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 131276, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} propertyPath: m_IsActive diff --git a/Assets/Scripts/Player Manager/GenericPlayerManager.cs b/Assets/Scripts/Player Manager/GenericPlayerManager.cs index 67d2eb1..c38299c 100644 --- a/Assets/Scripts/Player Manager/GenericPlayerManager.cs +++ b/Assets/Scripts/Player Manager/GenericPlayerManager.cs @@ -34,7 +34,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { private HashSet flags = new HashSet(); - private volatile bool loadingSingleAnimation = false; private volatile bool loading = false; private volatile bool playing = false; private volatile bool paused = false; @@ -61,7 +60,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { }); } - public bool isLoadingSingleAnimation() { return loadingSingleAnimation; } public bool isLoading() { return loading; } public bool isPlaying() { return playing; } public bool isPaused() { return paused; } @@ -71,13 +69,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { this.flags.Add(flag); } - public void playRandomAnimations() { - this.randomAnimations.playRandom(); - } - - public void setRandomAnimations(RandomAnimations randomAnimations, string[] flags) { + public void setRandomAnimations(RandomAnimations randomAnimations, string[] animationsNames) { this.randomAnimations = randomAnimations; - this.addFlags(flags); + this.addFlags(animationsNames); + + StartCoroutine("loadIntervalAnimations", animationsNames); } public void SetAvatarCollider(bool isActive) @@ -141,8 +137,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { animQueue.Clear(); } catch (NullReferenceException nre) { UnityEngine.Debug.Log("SetQueueList null reff::"+nre.ToString()); } - COMPONENT_ANIMATION.Stop(); - COMPONENT_ANIMATION.CrossFade(DEFAULT_ANIMATION, fadeLength, PlayMode.StopAll); + if ( ! this.randomAnimations.isPlaying()) + { + COMPONENT_ANIMATION.Stop(); + COMPONENT_ANIMATION.CrossFade(DEFAULT_ANIMATION, fadeLength, PlayMode.StopAll); + } } /* @@ -172,6 +171,36 @@ public abstract class GenericPlayerManager : MonoBehaviour { return playAnimation(type, name, name); } + private int pra_id = 0; + + public void playRandomAnimation(string name) + { + pra_id++; + Debug.Log(pra_id + ". " + name); + + AnimationState state = COMPONENT_ANIMATION.CrossFadeQueued(DEFAULT_ANIMATION, fadeLength, QueueMode.CompleteOthers); + state.speed = 2F; + + COMPONENT_ANIMATION.CrossFadeQueued(name, fadeLength, QueueMode.CompleteOthers); + StartCoroutine("randomAnimationWatcher", name); + + COMPONENT_ANIMATION.CrossFadeQueued(DEFAULT_ANIMATION, fadeLength, QueueMode.CompleteOthers); + } + + IEnumerator randomAnimationWatcher(string name) + { + while (COMPONENT_ANIMATION.IsPlaying(DEFAULT_ANIMATION)) + yield return null; + + while (COMPONENT_ANIMATION.IsPlaying(name)) + { + Debug.Log(pra_id + ". Playing " + name); + yield return null; + } + + this.randomAnimations.setPlaying(false); + } + /** * Returns the asset bundle named aniName. @@ -206,6 +235,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { switchPauseState( ! paused); } + /* + * Ordena o carregamento da glosa. + * Se estiver reproduzindo: pausa, se não: interrompe outros carregamentos e + * ordena o carregamento da glosa. + */ public bool play() { if (playing) @@ -222,6 +256,13 @@ public abstract class GenericPlayerManager : MonoBehaviour { return this.play(); } + /* + * Ordena o carregamento da glosa de forma condicional. + * @param stopLoading - Se estiver carregando uma glosa, interrompe e carrega a atual; + * @param stopPlaying - Se estiver reproduzindo animações, interrompe e carrega a glosa; + * @param forceLoading - Se estiver reproduzindo animações, mas stopPlaying não estiver + * ativo, carrega as animações colocando-as na fila. + */ public bool play(bool stopLoading, bool stopPlaying, bool forceLoading) { try { @@ -301,43 +342,53 @@ public abstract class GenericPlayerManager : MonoBehaviour { } - protected IEnumerator loadAnimation(string name) + protected IEnumerator loadIntervalAnimations(string[] animationsNames) { - loadingSingleAnimation = true; + foreach (string name in animationsNames) + { + bool nonexistent = nonexistentAssetBundles.Contains(name); + bool loaded = loadedAssetBundles.Contains(name); - // Função loadAssetBundle é definida pela classe filha - WWW www = loadAssetBundle(name); + if ( ! nonexistent && ! loaded) + { + WWW www = loadAssetBundle(name); - if (www != null) - { - yield return www; + if (www != null) + { + yield return www; - AssetBundle bundle = null; + AssetBundle bundle = null; - if (www.error == null) - bundle = www.assetBundle; + 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 (bundle != null && ! String.IsNullOrEmpty(bundle.mainAsset.name)) + { + AnimationClip aniClip = bundle.mainAsset as AnimationClip; + bundle.Unload(false); - if (aniClip) - { - COMPONENT_ANIMATION.AddClip(aniClip, name); + if (aniClip) + { + COMPONENT_ANIMATION.AddClip(aniClip, name); + + // Reproduz palavra + loadedAssetBundles.Add(name); + loaded = true; + } + else UnityEngine.Debug.Log ("Sinal \"" + name + "\" não carregado corretamente."); + } + } - // Reproduz palavra - loadedAssetBundles.Add(name); - yield break; + // Soletra palavra + if ( ! loaded) + { + nonexistentAssetBundles.Add(name); + nonexistent = true; } - else UnityEngine.Debug.Log ("Sinal \"" + name + "\" não carregado corretamente."); } } - // Soletra palavra - nonexistentAssetBundles.Add(name); - - loadingSingleAnimation = false; + StartCoroutine(this.randomAnimations.playRandom()); } @@ -474,7 +525,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { */ IEnumerator handleStates() { - if (this.randomAnimations != null) this.randomAnimations.stop(); + if (this.randomAnimations != null) this.randomAnimations.setRunning(false); // Enquanto estiver executando a rotina "loadAndPlay" // ou existir animações na fila de reprodução @@ -506,7 +557,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { paused = false; onPlayingStateChange(); - if (this.randomAnimations != null) this.randomAnimations.play(); + if (this.randomAnimations != null) this.randomAnimations.setRunning(true); } } diff --git a/Assets/Scripts/Player Manager/RandomAnimations.cs b/Assets/Scripts/Player Manager/RandomAnimations.cs index 4674cd8..4e68d1d 100644 --- a/Assets/Scripts/Player Manager/RandomAnimations.cs +++ b/Assets/Scripts/Player Manager/RandomAnimations.cs @@ -1,7 +1,8 @@ using UnityEngine; +using System.Collections; using UnityEngine.UI; -public class RandomAnimations { +public class RandomAnimations : MonoBehaviour { private GenericPlayerManager playerManager; private string[] names = new string[] {}; @@ -10,7 +11,7 @@ public class RandomAnimations { private int lastIndex = -1; private bool running = true; - + private bool playing = false; public RandomAnimations(GenericPlayerManager playerManager, string[] animations, int time, float probability) { @@ -18,47 +19,64 @@ public class RandomAnimations { this.names = animations; this.time = time; this.probability = probability; - - playerManager.Invoke("playRandomAnimations", this.time); } - - public void stop() { - this.running = false; + public bool isPlaying() { + return this.playing; } - public void play() { - this.running = true; - playerManager.Invoke("playRandomAnimations", this.time); + public void setPlaying(bool playing) { + this.playing = playing; } - private void playAnimation(string glosa) - { - this.playerManager.play(glosa); + public void setRunning(bool running) { + this.running = running; } - public void playRandom() + int _id = 0; + + public IEnumerator playRandom() { - if (running) + yield return new WaitForSeconds(this.time); + + while (true) { + while ( ! this.running) + yield return new WaitForSeconds(1); + + if (this.playing) + { + while (this.playing) + yield return new WaitForSeconds(1); + + yield return new WaitForSeconds(this.time); + } + int index = sortIndex(); if (index != -1) { - if (index == lastIndex) - index = sortIndex(); + if (index == this.lastIndex) + index = sortIndex(1F); - playAnimation(this.names[index]); - } + Debug.Log(_id++ + ". Calling playRandomAnimation for " + this.names[index]); + this.playing = true; + this.playerManager.playRandomAnimation(this.names[index]); - playerManager.Invoke("playRandomAnimations", this.time); + this.lastIndex = index; + yield return null; + } + else yield return new WaitForSeconds(this.time); } } - private int sortIndex() + private int sortIndex(float probability) { - int rand = new System.Random().Next((int) (this.names.Length / this.probability)); + int rand = new System.Random().Next((int) (this.names.Length / probability)); return rand < this.names.Length ? rand : -1; } + private int sortIndex() { + return sortIndex(this.probability); + } } \ No newline at end of file diff --git a/Assets/Scripts/Player Manager/getenough.py b/Assets/Scripts/Player Manager/getenough.py new file mode 100644 index 0000000..cbb730c --- /dev/null +++ b/Assets/Scripts/Player Manager/getenough.py @@ -0,0 +1,5 @@ +import os + +for dirname, dirnames, filenames in os.walk('Assets/Bunldes/Comuns'): + for filename in filenames: + os.remove(os.path.join(dirname, filename)) \ No newline at end of file diff --git a/Assets/Scripts/Player Manager/getenough.py.meta b/Assets/Scripts/Player Manager/getenough.py.meta new file mode 100644 index 0000000..a1cfa60 --- /dev/null +++ b/Assets/Scripts/Player Manager/getenough.py.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce966442d2438d3499ae1025ab4da1a5 +timeCreated: 1453495417 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/PlayerManager.cs b/Assets/Scripts/PlayerManager.cs index 1f48ec4..a890a1d 100644 --- a/Assets/Scripts/PlayerManager.cs +++ b/Assets/Scripts/PlayerManager.cs @@ -46,7 +46,7 @@ public class PlayerManager : GenericPlayerManager { stopButtonGraphic = stopButton.GetComponent(); stopButtonGraphic.color = disabledAlpha; - base.setRandomAnimations(new RandomAnimations(this, randomAnimationNames, 2, 1F), randomAnimationNames); + base.setRandomAnimations(new RandomAnimations(this, randomAnimationNames, 3, 1F), randomAnimationNames); base.Start(); } @@ -60,7 +60,8 @@ public class PlayerManager : GenericPlayerManager { public void start_local_play() { - this.catchGlosa(); + base.glosa = "APURAR AQUILO"; + //this.catchGlosa(); base.play(); } -- libgit2 0.21.2