Commit 327ce306a67874148fb10c374dc17fa59eca09de
1 parent
e6b2f819
Exists in
dev
RandomAnimations incompleto
Showing
8 changed files
with
150 additions
and
67 deletions
Show diff stats
No preview for this file type
No preview for this file type
Assets/Scenes/Scene.unity
| @@ -425,7 +425,7 @@ Prefab: | @@ -425,7 +425,7 @@ Prefab: | ||
| 425 | objectReference: {fileID: 2100000, guid: 3e98fe09c9ac4ae4dbe731872ff7687a, type: 2} | 425 | objectReference: {fileID: 2100000, guid: 3e98fe09c9ac4ae4dbe731872ff7687a, type: 2} |
| 426 | - target: {fileID: 11474732, guid: 00197fc9877daa14c963e5917de36124, type: 2} | 426 | - target: {fileID: 11474732, guid: 00197fc9877daa14c963e5917de36124, type: 2} |
| 427 | propertyPath: m_Enabled | 427 | propertyPath: m_Enabled |
| 428 | - value: 0 | 428 | + value: 1 |
| 429 | objectReference: {fileID: 0} | 429 | objectReference: {fileID: 0} |
| 430 | m_RemovedComponents: [] | 430 | m_RemovedComponents: [] |
| 431 | m_ParentPrefab: {fileID: 100100000, guid: 00197fc9877daa14c963e5917de36124, type: 2} | 431 | m_ParentPrefab: {fileID: 100100000, guid: 00197fc9877daa14c963e5917de36124, type: 2} |
| @@ -1398,23 +1398,23 @@ Prefab: | @@ -1398,23 +1398,23 @@ Prefab: | ||
| 1398 | objectReference: {fileID: 138791195} | 1398 | objectReference: {fileID: 138791195} |
| 1399 | - target: {fileID: 22412692, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} | 1399 | - target: {fileID: 22412692, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} |
| 1400 | propertyPath: m_AnchorMax.x | 1400 | propertyPath: m_AnchorMax.x |
| 1401 | - value: 0 | 1401 | + value: .444444448 |
| 1402 | objectReference: {fileID: 0} | 1402 | objectReference: {fileID: 0} |
| 1403 | - target: {fileID: 22412692, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} | 1403 | - target: {fileID: 22412692, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} |
| 1404 | propertyPath: m_AnchorMax.y | 1404 | propertyPath: m_AnchorMax.y |
| 1405 | - value: 0 | 1405 | + value: 1 |
| 1406 | objectReference: {fileID: 0} | 1406 | objectReference: {fileID: 0} |
| 1407 | - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} | 1407 | - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} |
| 1408 | propertyPath: m_AnchorMin.x | 1408 | propertyPath: m_AnchorMin.x |
| 1409 | - value: 0 | 1409 | + value: .444444448 |
| 1410 | objectReference: {fileID: 0} | 1410 | objectReference: {fileID: 0} |
| 1411 | - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} | 1411 | - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} |
| 1412 | propertyPath: m_AnchorMax.x | 1412 | propertyPath: m_AnchorMax.x |
| 1413 | - value: 0 | 1413 | + value: .444444448 |
| 1414 | objectReference: {fileID: 0} | 1414 | objectReference: {fileID: 0} |
| 1415 | - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} | 1415 | - target: {fileID: 22452678, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} |
| 1416 | propertyPath: m_AnchorMax.y | 1416 | propertyPath: m_AnchorMax.y |
| 1417 | - value: 0 | 1417 | + value: 1 |
| 1418 | objectReference: {fileID: 0} | 1418 | objectReference: {fileID: 0} |
| 1419 | - target: {fileID: 131276, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} | 1419 | - target: {fileID: 131276, guid: 12db97f21fb2a7d4cb537ec5395de1b9, type: 2} |
| 1420 | propertyPath: m_IsActive | 1420 | propertyPath: m_IsActive |
Assets/Scripts/Player Manager/GenericPlayerManager.cs
| @@ -34,7 +34,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -34,7 +34,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 34 | 34 | ||
| 35 | private HashSet<string> flags = new HashSet<string>(); | 35 | private HashSet<string> flags = new HashSet<string>(); |
| 36 | 36 | ||
| 37 | - private volatile bool loadingSingleAnimation = false; | ||
| 38 | private volatile bool loading = false; | 37 | private volatile bool loading = false; |
| 39 | private volatile bool playing = false; | 38 | private volatile bool playing = false; |
| 40 | private volatile bool paused = false; | 39 | private volatile bool paused = false; |
| @@ -61,7 +60,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -61,7 +60,6 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 61 | }); | 60 | }); |
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | - public bool isLoadingSingleAnimation() { return loadingSingleAnimation; } | ||
| 65 | public bool isLoading() { return loading; } | 63 | public bool isLoading() { return loading; } |
| 66 | public bool isPlaying() { return playing; } | 64 | public bool isPlaying() { return playing; } |
| 67 | public bool isPaused() { return paused; } | 65 | public bool isPaused() { return paused; } |
| @@ -71,13 +69,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -71,13 +69,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 71 | this.flags.Add(flag); | 69 | this.flags.Add(flag); |
| 72 | } | 70 | } |
| 73 | 71 | ||
| 74 | - public void playRandomAnimations() { | ||
| 75 | - this.randomAnimations.playRandom(); | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - public void setRandomAnimations(RandomAnimations randomAnimations, string[] flags) { | 72 | + public void setRandomAnimations(RandomAnimations randomAnimations, string[] animationsNames) { |
| 79 | this.randomAnimations = randomAnimations; | 73 | this.randomAnimations = randomAnimations; |
| 80 | - this.addFlags(flags); | 74 | + this.addFlags(animationsNames); |
| 75 | + | ||
| 76 | + StartCoroutine("loadIntervalAnimations", animationsNames); | ||
| 81 | } | 77 | } |
| 82 | 78 | ||
| 83 | public void SetAvatarCollider(bool isActive) | 79 | public void SetAvatarCollider(bool isActive) |
| @@ -141,8 +137,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -141,8 +137,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 141 | animQueue.Clear(); | 137 | animQueue.Clear(); |
| 142 | } catch (NullReferenceException nre) { UnityEngine.Debug.Log("SetQueueList null reff::"+nre.ToString()); } | 138 | } catch (NullReferenceException nre) { UnityEngine.Debug.Log("SetQueueList null reff::"+nre.ToString()); } |
| 143 | 139 | ||
| 144 | - COMPONENT_ANIMATION.Stop(); | ||
| 145 | - COMPONENT_ANIMATION.CrossFade(DEFAULT_ANIMATION, fadeLength, PlayMode.StopAll); | 140 | + if ( ! this.randomAnimations.isPlaying()) |
| 141 | + { | ||
| 142 | + COMPONENT_ANIMATION.Stop(); | ||
| 143 | + COMPONENT_ANIMATION.CrossFade(DEFAULT_ANIMATION, fadeLength, PlayMode.StopAll); | ||
| 144 | + } | ||
| 146 | } | 145 | } |
| 147 | 146 | ||
| 148 | /* | 147 | /* |
| @@ -172,6 +171,36 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -172,6 +171,36 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 172 | return playAnimation(type, name, name); | 171 | return playAnimation(type, name, name); |
| 173 | } | 172 | } |
| 174 | 173 | ||
| 174 | + private int pra_id = 0; | ||
| 175 | + | ||
| 176 | + public void playRandomAnimation(string name) | ||
| 177 | + { | ||
| 178 | + pra_id++; | ||
| 179 | + Debug.Log(pra_id + ". " + name); | ||
| 180 | + | ||
| 181 | + AnimationState state = COMPONENT_ANIMATION.CrossFadeQueued(DEFAULT_ANIMATION, fadeLength, QueueMode.CompleteOthers); | ||
| 182 | + state.speed = 2F; | ||
| 183 | + | ||
| 184 | + COMPONENT_ANIMATION.CrossFadeQueued(name, fadeLength, QueueMode.CompleteOthers); | ||
| 185 | + StartCoroutine("randomAnimationWatcher", name); | ||
| 186 | + | ||
| 187 | + COMPONENT_ANIMATION.CrossFadeQueued(DEFAULT_ANIMATION, fadeLength, QueueMode.CompleteOthers); | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + IEnumerator randomAnimationWatcher(string name) | ||
| 191 | + { | ||
| 192 | + while (COMPONENT_ANIMATION.IsPlaying(DEFAULT_ANIMATION)) | ||
| 193 | + yield return null; | ||
| 194 | + | ||
| 195 | + while (COMPONENT_ANIMATION.IsPlaying(name)) | ||
| 196 | + { | ||
| 197 | + Debug.Log(pra_id + ". Playing " + name); | ||
| 198 | + yield return null; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + this.randomAnimations.setPlaying(false); | ||
| 202 | + } | ||
| 203 | + | ||
| 175 | 204 | ||
| 176 | /** | 205 | /** |
| 177 | * Returns the asset bundle named aniName. | 206 | * Returns the asset bundle named aniName. |
| @@ -206,6 +235,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -206,6 +235,11 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 206 | switchPauseState( ! paused); | 235 | switchPauseState( ! paused); |
| 207 | } | 236 | } |
| 208 | 237 | ||
| 238 | + /* | ||
| 239 | + * Ordena o carregamento da glosa. | ||
| 240 | + * Se estiver reproduzindo: pausa, se não: interrompe outros carregamentos e | ||
| 241 | + * ordena o carregamento da glosa. | ||
| 242 | + */ | ||
| 209 | public bool play() | 243 | public bool play() |
| 210 | { | 244 | { |
| 211 | if (playing) | 245 | if (playing) |
| @@ -222,6 +256,13 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -222,6 +256,13 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 222 | return this.play(); | 256 | return this.play(); |
| 223 | } | 257 | } |
| 224 | 258 | ||
| 259 | + /* | ||
| 260 | + * Ordena o carregamento da glosa de forma condicional. | ||
| 261 | + * @param stopLoading - Se estiver carregando uma glosa, interrompe e carrega a atual; | ||
| 262 | + * @param stopPlaying - Se estiver reproduzindo animações, interrompe e carrega a glosa; | ||
| 263 | + * @param forceLoading - Se estiver reproduzindo animações, mas stopPlaying não estiver | ||
| 264 | + * ativo, carrega as animações colocando-as na fila. | ||
| 265 | + */ | ||
| 225 | public bool play(bool stopLoading, bool stopPlaying, bool forceLoading) | 266 | public bool play(bool stopLoading, bool stopPlaying, bool forceLoading) |
| 226 | { | 267 | { |
| 227 | try { | 268 | try { |
| @@ -301,43 +342,53 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -301,43 +342,53 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 301 | } | 342 | } |
| 302 | 343 | ||
| 303 | 344 | ||
| 304 | - protected IEnumerator loadAnimation(string name) | 345 | + protected IEnumerator loadIntervalAnimations(string[] animationsNames) |
| 305 | { | 346 | { |
| 306 | - loadingSingleAnimation = true; | 347 | + foreach (string name in animationsNames) |
| 348 | + { | ||
| 349 | + bool nonexistent = nonexistentAssetBundles.Contains(name); | ||
| 350 | + bool loaded = loadedAssetBundles.Contains(name); | ||
| 307 | 351 | ||
| 308 | - // Função loadAssetBundle é definida pela classe filha | ||
| 309 | - WWW www = loadAssetBundle(name); | 352 | + if ( ! nonexistent && ! loaded) |
| 353 | + { | ||
| 354 | + WWW www = loadAssetBundle(name); | ||
| 310 | 355 | ||
| 311 | - if (www != null) | ||
| 312 | - { | ||
| 313 | - yield return www; | 356 | + if (www != null) |
| 357 | + { | ||
| 358 | + yield return www; | ||
| 314 | 359 | ||
| 315 | - AssetBundle bundle = null; | 360 | + AssetBundle bundle = null; |
| 316 | 361 | ||
| 317 | - if (www.error == null) | ||
| 318 | - bundle = www.assetBundle; | 362 | + if (www.error == null) |
| 363 | + bundle = www.assetBundle; | ||
| 319 | 364 | ||
| 320 | - if (bundle != null && ! String.IsNullOrEmpty(bundle.mainAsset.name)) | ||
| 321 | - { | ||
| 322 | - AnimationClip aniClip = bundle.mainAsset as AnimationClip; | ||
| 323 | - bundle.Unload(false); | 365 | + if (bundle != null && ! String.IsNullOrEmpty(bundle.mainAsset.name)) |
| 366 | + { | ||
| 367 | + AnimationClip aniClip = bundle.mainAsset as AnimationClip; | ||
| 368 | + bundle.Unload(false); | ||
| 324 | 369 | ||
| 325 | - if (aniClip) | ||
| 326 | - { | ||
| 327 | - COMPONENT_ANIMATION.AddClip(aniClip, name); | 370 | + if (aniClip) |
| 371 | + { | ||
| 372 | + COMPONENT_ANIMATION.AddClip(aniClip, name); | ||
| 373 | + | ||
| 374 | + // Reproduz palavra | ||
| 375 | + loadedAssetBundles.Add(name); | ||
| 376 | + loaded = true; | ||
| 377 | + } | ||
| 378 | + else UnityEngine.Debug.Log ("Sinal \"" + name + "\" não carregado corretamente."); | ||
| 379 | + } | ||
| 380 | + } | ||
| 328 | 381 | ||
| 329 | - // Reproduz palavra | ||
| 330 | - loadedAssetBundles.Add(name); | ||
| 331 | - yield break; | 382 | + // Soletra palavra |
| 383 | + if ( ! loaded) | ||
| 384 | + { | ||
| 385 | + nonexistentAssetBundles.Add(name); | ||
| 386 | + nonexistent = true; | ||
| 332 | } | 387 | } |
| 333 | - else UnityEngine.Debug.Log ("Sinal \"" + name + "\" não carregado corretamente."); | ||
| 334 | } | 388 | } |
| 335 | } | 389 | } |
| 336 | 390 | ||
| 337 | - // Soletra palavra | ||
| 338 | - nonexistentAssetBundles.Add(name); | ||
| 339 | - | ||
| 340 | - loadingSingleAnimation = false; | 391 | + StartCoroutine(this.randomAnimations.playRandom()); |
| 341 | } | 392 | } |
| 342 | 393 | ||
| 343 | 394 | ||
| @@ -474,7 +525,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -474,7 +525,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 474 | */ | 525 | */ |
| 475 | IEnumerator handleStates() | 526 | IEnumerator handleStates() |
| 476 | { | 527 | { |
| 477 | - if (this.randomAnimations != null) this.randomAnimations.stop(); | 528 | + if (this.randomAnimations != null) this.randomAnimations.setRunning(false); |
| 478 | 529 | ||
| 479 | // Enquanto estiver executando a rotina "loadAndPlay" | 530 | // Enquanto estiver executando a rotina "loadAndPlay" |
| 480 | // ou existir animações na fila de reprodução | 531 | // ou existir animações na fila de reprodução |
| @@ -506,7 +557,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { | @@ -506,7 +557,7 @@ public abstract class GenericPlayerManager : MonoBehaviour { | ||
| 506 | paused = false; | 557 | paused = false; |
| 507 | onPlayingStateChange(); | 558 | onPlayingStateChange(); |
| 508 | 559 | ||
| 509 | - if (this.randomAnimations != null) this.randomAnimations.play(); | 560 | + if (this.randomAnimations != null) this.randomAnimations.setRunning(true); |
| 510 | } | 561 | } |
| 511 | 562 | ||
| 512 | } | 563 | } |
Assets/Scripts/Player Manager/RandomAnimations.cs
| 1 | using UnityEngine; | 1 | using UnityEngine; |
| 2 | +using System.Collections; | ||
| 2 | using UnityEngine.UI; | 3 | using UnityEngine.UI; |
| 3 | 4 | ||
| 4 | -public class RandomAnimations { | 5 | +public class RandomAnimations : MonoBehaviour { |
| 5 | 6 | ||
| 6 | private GenericPlayerManager playerManager; | 7 | private GenericPlayerManager playerManager; |
| 7 | private string[] names = new string[] {}; | 8 | private string[] names = new string[] {}; |
| @@ -10,7 +11,7 @@ public class RandomAnimations { | @@ -10,7 +11,7 @@ public class RandomAnimations { | ||
| 10 | 11 | ||
| 11 | private int lastIndex = -1; | 12 | private int lastIndex = -1; |
| 12 | private bool running = true; | 13 | private bool running = true; |
| 13 | - | 14 | + private bool playing = false; |
| 14 | 15 | ||
| 15 | public RandomAnimations(GenericPlayerManager playerManager, string[] animations, int time, float probability) | 16 | public RandomAnimations(GenericPlayerManager playerManager, string[] animations, int time, float probability) |
| 16 | { | 17 | { |
| @@ -18,47 +19,64 @@ public class RandomAnimations { | @@ -18,47 +19,64 @@ public class RandomAnimations { | ||
| 18 | this.names = animations; | 19 | this.names = animations; |
| 19 | this.time = time; | 20 | this.time = time; |
| 20 | this.probability = probability; | 21 | this.probability = probability; |
| 21 | - | ||
| 22 | - playerManager.Invoke("playRandomAnimations", this.time); | ||
| 23 | } | 22 | } |
| 24 | 23 | ||
| 25 | - | ||
| 26 | - public void stop() { | ||
| 27 | - this.running = false; | 24 | + public bool isPlaying() { |
| 25 | + return this.playing; | ||
| 28 | } | 26 | } |
| 29 | 27 | ||
| 30 | - public void play() { | ||
| 31 | - this.running = true; | ||
| 32 | - playerManager.Invoke("playRandomAnimations", this.time); | 28 | + public void setPlaying(bool playing) { |
| 29 | + this.playing = playing; | ||
| 33 | } | 30 | } |
| 34 | 31 | ||
| 35 | - private void playAnimation(string glosa) | ||
| 36 | - { | ||
| 37 | - this.playerManager.play(glosa); | 32 | + public void setRunning(bool running) { |
| 33 | + this.running = running; | ||
| 38 | } | 34 | } |
| 39 | 35 | ||
| 40 | - public void playRandom() | 36 | + int _id = 0; |
| 37 | + | ||
| 38 | + public IEnumerator playRandom() | ||
| 41 | { | 39 | { |
| 42 | - if (running) | 40 | + yield return new WaitForSeconds(this.time); |
| 41 | + | ||
| 42 | + while (true) | ||
| 43 | { | 43 | { |
| 44 | + while ( ! this.running) | ||
| 45 | + yield return new WaitForSeconds(1); | ||
| 46 | + | ||
| 47 | + if (this.playing) | ||
| 48 | + { | ||
| 49 | + while (this.playing) | ||
| 50 | + yield return new WaitForSeconds(1); | ||
| 51 | + | ||
| 52 | + yield return new WaitForSeconds(this.time); | ||
| 53 | + } | ||
| 54 | + | ||
| 44 | int index = sortIndex(); | 55 | int index = sortIndex(); |
| 45 | 56 | ||
| 46 | if (index != -1) | 57 | if (index != -1) |
| 47 | { | 58 | { |
| 48 | - if (index == lastIndex) | ||
| 49 | - index = sortIndex(); | 59 | + if (index == this.lastIndex) |
| 60 | + index = sortIndex(1F); | ||
| 50 | 61 | ||
| 51 | - playAnimation(this.names[index]); | ||
| 52 | - } | 62 | + Debug.Log(_id++ + ". Calling playRandomAnimation for " + this.names[index]); |
| 63 | + this.playing = true; | ||
| 64 | + this.playerManager.playRandomAnimation(this.names[index]); | ||
| 53 | 65 | ||
| 54 | - playerManager.Invoke("playRandomAnimations", this.time); | 66 | + this.lastIndex = index; |
| 67 | + yield return null; | ||
| 68 | + } | ||
| 69 | + else yield return new WaitForSeconds(this.time); | ||
| 55 | } | 70 | } |
| 56 | } | 71 | } |
| 57 | 72 | ||
| 58 | - private int sortIndex() | 73 | + private int sortIndex(float probability) |
| 59 | { | 74 | { |
| 60 | - int rand = new System.Random().Next((int) (this.names.Length / this.probability)); | 75 | + int rand = new System.Random().Next((int) (this.names.Length / probability)); |
| 61 | return rand < this.names.Length ? rand : -1; | 76 | return rand < this.names.Length ? rand : -1; |
| 62 | } | 77 | } |
| 78 | + private int sortIndex() { | ||
| 79 | + return sortIndex(this.probability); | ||
| 80 | + } | ||
| 63 | 81 | ||
| 64 | } | 82 | } |
| 65 | \ No newline at end of file | 83 | \ No newline at end of file |
Assets/Scripts/PlayerManager.cs
| @@ -46,7 +46,7 @@ public class PlayerManager : GenericPlayerManager { | @@ -46,7 +46,7 @@ public class PlayerManager : GenericPlayerManager { | ||
| 46 | stopButtonGraphic = stopButton.GetComponent<Graphic>(); | 46 | stopButtonGraphic = stopButton.GetComponent<Graphic>(); |
| 47 | stopButtonGraphic.color = disabledAlpha; | 47 | stopButtonGraphic.color = disabledAlpha; |
| 48 | 48 | ||
| 49 | - base.setRandomAnimations(new RandomAnimations(this, randomAnimationNames, 2, 1F), randomAnimationNames); | 49 | + base.setRandomAnimations(new RandomAnimations(this, randomAnimationNames, 3, 1F), randomAnimationNames); |
| 50 | base.Start(); | 50 | base.Start(); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| @@ -60,7 +60,8 @@ public class PlayerManager : GenericPlayerManager { | @@ -60,7 +60,8 @@ public class PlayerManager : GenericPlayerManager { | ||
| 60 | 60 | ||
| 61 | public void start_local_play() | 61 | public void start_local_play() |
| 62 | { | 62 | { |
| 63 | - this.catchGlosa(); | 63 | + base.glosa = "APURAR AQUILO"; |
| 64 | + //this.catchGlosa(); | ||
| 64 | base.play(); | 65 | base.play(); |
| 65 | } | 66 | } |
| 66 | 67 |