Yields instructions

This commit is contained in:
2017-02-11 20:57:49 +07:00
parent 290fd066b5
commit 21fe31585f
9 changed files with 527 additions and 343 deletions

View File

@@ -1,7 +1,8 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using FTRuntime;
using FTRuntime.Yields;
namespace FlashTools.Examples {
[RequireComponent(typeof(SwfClipController))]
@@ -10,48 +11,28 @@ namespace FlashTools.Examples {
static string _fadeInSequence = "fadeIn";
static string _fadeOutSequence = "fadeOut";
enum States {
FadeIn,
Idle,
FadeOut
}
float _idleTimer = 0.0f;
States _currentState = States.FadeIn;
void Start() {
var ctrl = GetComponent<SwfClipController>();
ctrl.OnStopPlayingEvent += OnStopPlayingEvent;
ctrl.loopMode = SwfClipController.LoopModes.Once;
_currentState = States.FadeIn;
ctrl.Play(_fadeInSequence);
StartCoroutine(StartCoro(ctrl));
}
void OnStopPlayingEvent(SwfClipController ctrl) {
switch ( _currentState ) {
case States.FadeIn:
_idleTimer = Time.time;
_currentState = States.Idle;
ctrl.Play(_idleSequences[Random.Range(0, _idleSequences.Length)]);
break;
case States.Idle: {
if ( Time.time - _idleTimer > 5.0f ) {
_currentState = States.FadeOut;
ctrl.Play(_fadeOutSequence);
} else {
var last_seq = ctrl.clip.sequence;
do {
var seq_index = Random.Range(0, _idleSequences.Length);
ctrl.Play(_idleSequences[seq_index]);
} while ( last_seq == ctrl.clip.sequence );
}
}
break;
case States.FadeOut:
_currentState = States.FadeIn;
IEnumerator StartCoro(SwfClipController ctrl) {
while ( true ) {
ctrl.Play(_fadeInSequence);
break;
yield return new SwfWaitStopPlaying(ctrl);
for ( var i = 0; i < 3; ++i ) {
var last_seq = ctrl.clip.sequence;
do {
var seq_index = Random.Range(0, _idleSequences.Length);
ctrl.Play(_idleSequences[seq_index]);
} while ( last_seq == ctrl.clip.sequence );
yield return new SwfWaitStopPlaying(ctrl);
}
ctrl.Play(_fadeOutSequence);
yield return new SwfWaitStopPlaying(ctrl);
yield return new WaitForSeconds(2.0f);
}
}
}