diff --git a/Assets/DevTests/Scenes/Scene.unity b/Assets/DevTests/Scene.unity
similarity index 100%
rename from Assets/DevTests/Scenes/Scene.unity
rename to Assets/DevTests/Scene.unity
diff --git a/Assets/DevTests/Scenes/Scene.unity.meta b/Assets/DevTests/Scene.unity.meta
similarity index 100%
rename from Assets/DevTests/Scenes/Scene.unity.meta
rename to Assets/DevTests/Scene.unity.meta
diff --git a/Assets/DevTests/Scenes.meta b/Assets/DevTests/Scenes.meta
deleted file mode 100644
index ff9935f..0000000
--- a/Assets/DevTests/Scenes.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 0e3bddf96333643c8a12fd862ebc9ec7
-folderAsset: yes
-timeCreated: 1480709542
-licenseType: Free
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/FlashTools/Docs/CHANGELOG.md b/Assets/FlashTools/Docs/CHANGELOG.md
index e988284..d215ca1 100644
--- a/Assets/FlashTools/Docs/CHANGELOG.md
+++ b/Assets/FlashTools/Docs/CHANGELOG.md
@@ -1,6 +1,7 @@
###### Version 1.3.6
* Fix for scale very small vector items
* Big vector item optimization
+* More yield instructions and extensions
###### Version 1.3.5
* Fix sprite import problem
diff --git a/Assets/FlashTools/Example/Scripts/PurpleFlowerLogic.cs b/Assets/FlashTools/Example/Scripts/PurpleFlowerLogic.cs
index 862d288..3e5d96b 100644
--- a/Assets/FlashTools/Example/Scripts/PurpleFlowerLogic.cs
+++ b/Assets/FlashTools/Example/Scripts/PurpleFlowerLogic.cs
@@ -18,22 +18,25 @@ namespace FlashTools.Examples {
IEnumerator StartCoro(SwfClipController ctrl) {
while ( true ) {
- ctrl.Play(_fadeInSequence);
- yield return new SwfWaitStopPlaying(ctrl);
-
+ yield return ctrl.PlayAndWaitStopOrRewind(_fadeInSequence);
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);
+ var idle_seq = GetRandomIdleSequence(ctrl);
+ yield return ctrl.PlayAndWaitStopOrRewind(idle_seq);
}
-
- ctrl.Play(_fadeOutSequence);
- yield return new SwfWaitStopPlaying(ctrl);
+ yield return ctrl.PlayAndWaitStopOrRewind(_fadeOutSequence);
yield return new WaitForSeconds(2.0f);
}
}
+
+ string GetRandomIdleSequence(SwfClipController ctrl) {
+ var cur_seq = ctrl.clip.sequence;
+ do {
+ var seq_index = Random.Range(0, _idleSequences.Length);
+ var new_sequence = _idleSequences[seq_index];
+ if ( new_sequence != cur_seq ) {
+ return new_sequence;
+ }
+ } while ( true );
+ }
}
}
\ No newline at end of file
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitExtensions.cs b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitExtensions.cs
new file mode 100644
index 0000000..2829f58
--- /dev/null
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitExtensions.cs
@@ -0,0 +1,250 @@
+namespace FTRuntime.Yields {
+ public static class SwfWaitExtensions {
+
+ // ---------------------------------------------------------------------
+ //
+ // WaitFor[Event]
+ //
+ // ---------------------------------------------------------------------
+
+ /// Yield instruction for wait animation stop event
+ /// Yield instruction for wait animation stop event
+ /// The controller
+ public static SwfWaitStopPlaying WaitForStopPlaying(
+ this SwfClipController ctrl)
+ {
+ return new SwfWaitStopPlaying(ctrl);
+ }
+
+ /// Yield instruction for wait animation rewind event
+ /// Yield instruction for wait animation rewind event
+ /// The controller
+ public static SwfWaitRewindPlaying WaitForRewindPlaying(
+ this SwfClipController ctrl)
+ {
+ return new SwfWaitRewindPlaying(ctrl);
+ }
+
+ /// Yield instruction for wait animation stop or rewind event
+ /// Yield instruction for wait animation stop or rewind event
+ /// The controller
+ public static SwfWaitStopOrRewindPlaying WaitForStopOrRewindPlaying(
+ this SwfClipController ctrl)
+ {
+ return new SwfWaitStopOrRewindPlaying(ctrl);
+ }
+
+ /// Yield instruction for wait animation play event
+ /// Yield instruction for wait animation play event
+ /// The controller
+ public static SwfWaitPlayStopped WaitForPlayStopped(
+ this SwfClipController ctrl)
+ {
+ return new SwfWaitPlayStopped(ctrl);
+ }
+
+ // ---------------------------------------------------------------------
+ //
+ // PlayAndWait[Event]
+ //
+ // ---------------------------------------------------------------------
+
+ /// Play with specified rewind action
+ /// Yield instruction for wait animation stop event
+ /// The clip controller
+ /// If set to true rewind animation to begin frame
+ public static SwfWaitStopPlaying PlayAndWaitStop(
+ this SwfClipController ctrl, bool rewind)
+ {
+ ctrl.Play(rewind);
+ return WaitForStopPlaying(ctrl);
+ }
+
+ /// Changes the animation sequence and play controller with rewind
+ /// Yield instruction for wait animation stop event
+ /// The clip controller
+ /// The new sequence
+ public static SwfWaitStopPlaying PlayAndWaitStop(
+ this SwfClipController ctrl, string sequence)
+ {
+ ctrl.Play(sequence);
+ return WaitForStopPlaying(ctrl);
+ }
+
+ /// Play with specified rewind action
+ /// Yield instruction for wait animation rewind event
+ /// The clip controller
+ /// If set to true rewind animation to begin frame
+ public static SwfWaitRewindPlaying PlayAndWaitRewind(
+ this SwfClipController ctrl, bool rewind)
+ {
+ ctrl.Play(rewind);
+ return WaitForRewindPlaying(ctrl);
+ }
+
+ /// Changes the animation sequence and play controller with rewind
+ /// Yield instruction for wait animation rewind event
+ /// The clip controller
+ /// The new sequence
+ public static SwfWaitRewindPlaying PlayAndWaitRewind(
+ this SwfClipController ctrl, string sequence)
+ {
+ ctrl.Play(sequence);
+ return WaitForRewindPlaying(ctrl);
+ }
+
+ /// Play with specified rewind action
+ /// Yield instruction for wait animation stop or rewind event
+ /// The clip controller
+ /// If set to true rewind animation to begin frame
+ public static SwfWaitStopOrRewindPlaying PlayAndWaitStopOrRewind(
+ this SwfClipController ctrl, bool rewind)
+ {
+ ctrl.Play(rewind);
+ return WaitForStopOrRewindPlaying(ctrl);
+ }
+
+ /// Changes the animation sequence and play controller with rewind
+ /// Yield instruction for wait animation stop or rewind event
+ /// The clip controller
+ /// The new sequence
+ public static SwfWaitStopOrRewindPlaying PlayAndWaitStopOrRewind(
+ this SwfClipController ctrl, string sequence)
+ {
+ ctrl.Play(sequence);
+ return WaitForStopOrRewindPlaying(ctrl);
+ }
+
+ // ---------------------------------------------------------------------
+ //
+ // GotoAndPlayAndWait[Event]
+ //
+ // ---------------------------------------------------------------------
+
+ /// Changes the animation frame with plays it
+ /// Yield instruction for wait animation stop event
+ /// The clip controller
+ /// The new current frame
+ public static SwfWaitStopPlaying GotoAndPlayAndWaitStop(
+ this SwfClipController ctrl, int frame)
+ {
+ ctrl.GotoAndPlay(frame);
+ return WaitForStopPlaying(ctrl);
+ }
+
+ /// Changes the animation sequence and frame with plays it
+ /// Yield instruction for wait animation stop event
+ /// The clip controller
+ /// The new sequence
+ /// The new current frame
+ public static SwfWaitStopPlaying GotoAndPlayAndWaitStop(
+ this SwfClipController ctrl, string sequence, int frame)
+ {
+ ctrl.GotoAndPlay(sequence, frame);
+ return WaitForStopPlaying(ctrl);
+ }
+
+ /// Changes the animation frame with plays it
+ /// Yield instruction for wait animation rewind event
+ /// The clip controller
+ /// The new current frame
+ public static SwfWaitRewindPlaying GotoAndPlayAndWaitRewind(
+ this SwfClipController ctrl, int frame)
+ {
+ ctrl.GotoAndPlay(frame);
+ return WaitForRewindPlaying(ctrl);
+ }
+
+ /// Changes the animation sequence and frame with plays it
+ /// Yield instruction for wait animation rewind event
+ /// The clip controller
+ /// The new sequence
+ /// The new current frame
+ public static SwfWaitRewindPlaying GotoAndPlayAndWaitRewind(
+ this SwfClipController ctrl, string sequence, int frame)
+ {
+ ctrl.GotoAndPlay(sequence, frame);
+ return WaitForRewindPlaying(ctrl);
+ }
+
+ /// Changes the animation frame with plays it
+ /// Yield instruction for wait animation stop and rewind event
+ /// The clip controller
+ /// The new current frame
+ public static SwfWaitStopOrRewindPlaying GotoAndPlayAndWaitStopOrRewind(
+ this SwfClipController ctrl, int frame)
+ {
+ ctrl.GotoAndPlay(frame);
+ return WaitForStopOrRewindPlaying(ctrl);
+ }
+
+ /// Changes the animation sequence and frame with plays it
+ /// Yield instruction for wait animation stop and rewind event
+ /// The clip controller
+ /// The new sequence
+ /// The new current frame
+ public static SwfWaitStopOrRewindPlaying GotoAndPlayAndWaitStopOrRewind(
+ this SwfClipController ctrl, string sequence, int frame)
+ {
+ ctrl.GotoAndPlay(sequence, frame);
+ return WaitForStopOrRewindPlaying(ctrl);
+ }
+
+ // ---------------------------------------------------------------------
+ //
+ // StopAndWait[Event]
+ //
+ // ---------------------------------------------------------------------
+
+ /// Stop with specified rewind action
+ /// Yield instruction for wait animation play event
+ /// The clip controller
+ /// If set to true rewind animation to begin frame
+ public static SwfWaitPlayStopped StopAndWaitPlay(
+ this SwfClipController ctrl, bool rewind)
+ {
+ ctrl.Stop(rewind);
+ return WaitForPlayStopped(ctrl);
+ }
+
+ /// Changes the animation sequence and stop controller with rewind
+ /// Yield instruction for wait animation play event
+ /// The clip controller
+ /// The new sequence
+ public static SwfWaitPlayStopped StopAndWaitPlay(
+ this SwfClipController ctrl, string sequence)
+ {
+ ctrl.Stop(sequence);
+ return WaitForPlayStopped(ctrl);
+ }
+
+ // ---------------------------------------------------------------------
+ //
+ // GotoAndStopAndWait[Event]
+ //
+ // ---------------------------------------------------------------------
+
+ /// Changes the animation frame with stops it
+ /// Yield instruction for wait animation play event
+ /// The clip controller
+ /// The new current frame
+ public static SwfWaitPlayStopped GotoAndStopAndWaitPlay(
+ this SwfClipController ctrl, int frame)
+ {
+ ctrl.GotoAndStop(frame);
+ return WaitForPlayStopped(ctrl);
+ }
+
+ /// Changes the animation sequence and frame with stops it
+ /// Yield instruction for wait animation play event
+ /// The clip controller
+ /// The new sequence
+ /// The new current frame
+ public static SwfWaitPlayStopped GotoAndStopAndWaitPlay(
+ this SwfClipController ctrl, string sequence, int frame)
+ {
+ ctrl.GotoAndStop(sequence, frame);
+ return WaitForPlayStopped(ctrl);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitExtensions.cs.meta b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitExtensions.cs.meta
new file mode 100644
index 0000000..2c061a3
--- /dev/null
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitExtensions.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: da7412b1ce89b4952869f7a85515b954
+timeCreated: 1487268103
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitPlayStopped.cs b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitPlayStopped.cs
index 754e5b4..3423eba 100644
--- a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitPlayStopped.cs
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitPlayStopped.cs
@@ -1,7 +1,7 @@
-using System.Collections;
+using UnityEngine;
namespace FTRuntime.Yields {
- public class SwfWaitPlayStopped : IEnumerator {
+ public class SwfWaitPlayStopped : CustomYieldInstruction {
SwfClipController _waitCtrl;
public SwfWaitPlayStopped(SwfClipController ctrl) {
@@ -12,12 +12,20 @@ namespace FTRuntime.Yields {
return Subscribe(ctrl);
}
+ public override bool keepWaiting {
+ get {
+ return _waitCtrl != null;
+ }
+ }
+
+ // ---------------------------------------------------------------------
//
- // Private
+ // Internal
//
+ // ---------------------------------------------------------------------
SwfWaitPlayStopped Subscribe(SwfClipController ctrl) {
- (this as IEnumerator).Reset();
+ Unsubscribe();
if ( ctrl ) {
_waitCtrl = ctrl;
ctrl.OnPlayStoppedEvent += OnPlayStopped;
@@ -25,27 +33,15 @@ namespace FTRuntime.Yields {
return this;
}
- void OnPlayStopped(SwfClipController ctrl) {
- (this as IEnumerator).Reset();
- }
-
- //
- // IEnumerator
- //
-
- bool IEnumerator.MoveNext() {
- return _waitCtrl != null;
- }
-
- void IEnumerator.Reset() {
+ void Unsubscribe() {
if ( _waitCtrl != null ) {
_waitCtrl.OnPlayStoppedEvent -= OnPlayStopped;
_waitCtrl = null;
}
}
- object IEnumerator.Current {
- get { return null; }
+ void OnPlayStopped(SwfClipController ctrl) {
+ Unsubscribe();
}
}
}
\ No newline at end of file
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitRewindPlaying.cs b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitRewindPlaying.cs
index 000de25..b90dbb9 100644
--- a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitRewindPlaying.cs
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitRewindPlaying.cs
@@ -1,7 +1,7 @@
-using System.Collections;
+using UnityEngine;
namespace FTRuntime.Yields {
- public class SwfWaitRewindPlaying : IEnumerator {
+ public class SwfWaitRewindPlaying : CustomYieldInstruction {
SwfClipController _waitCtrl;
public SwfWaitRewindPlaying(SwfClipController ctrl) {
@@ -12,12 +12,20 @@ namespace FTRuntime.Yields {
return Subscribe(ctrl);
}
+ public override bool keepWaiting {
+ get {
+ return _waitCtrl != null;
+ }
+ }
+
+ // ---------------------------------------------------------------------
//
- // Private
+ // Internal
//
+ // ---------------------------------------------------------------------
SwfWaitRewindPlaying Subscribe(SwfClipController ctrl) {
- (this as IEnumerator).Reset();
+ Unsubscribe();
if ( ctrl ) {
_waitCtrl = ctrl;
ctrl.OnRewindPlayingEvent += OnRewindPlaying;
@@ -25,27 +33,15 @@ namespace FTRuntime.Yields {
return this;
}
- void OnRewindPlaying(SwfClipController ctrl) {
- (this as IEnumerator).Reset();
- }
-
- //
- // IEnumerator
- //
-
- bool IEnumerator.MoveNext() {
- return _waitCtrl != null;
- }
-
- void IEnumerator.Reset() {
+ void Unsubscribe() {
if ( _waitCtrl != null ) {
_waitCtrl.OnRewindPlayingEvent -= OnRewindPlaying;
_waitCtrl = null;
}
}
- object IEnumerator.Current {
- get { return null; }
+ void OnRewindPlaying(SwfClipController ctrl) {
+ Unsubscribe();
}
}
}
\ No newline at end of file
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopOrRewindPlaying.cs b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopOrRewindPlaying.cs
new file mode 100644
index 0000000..46cc6ab
--- /dev/null
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopOrRewindPlaying.cs
@@ -0,0 +1,49 @@
+using UnityEngine;
+
+namespace FTRuntime.Yields {
+ public class SwfWaitStopOrRewindPlaying : CustomYieldInstruction {
+ SwfClipController _waitCtrl;
+
+ public SwfWaitStopOrRewindPlaying(SwfClipController ctrl) {
+ Subscribe(ctrl);
+ }
+
+ public SwfWaitStopOrRewindPlaying Reuse(SwfClipController ctrl) {
+ return Subscribe(ctrl);
+ }
+
+ public override bool keepWaiting {
+ get {
+ return _waitCtrl != null;
+ }
+ }
+
+ // ---------------------------------------------------------------------
+ //
+ // Internal
+ //
+ // ---------------------------------------------------------------------
+
+ SwfWaitStopOrRewindPlaying Subscribe(SwfClipController ctrl) {
+ Unsubscribe();
+ if ( ctrl ) {
+ _waitCtrl = ctrl;
+ ctrl.OnStopPlayingEvent += OnStopOrRewindPlaying;
+ ctrl.OnRewindPlayingEvent += OnStopOrRewindPlaying;
+ }
+ return this;
+ }
+
+ void Unsubscribe() {
+ if ( _waitCtrl != null ) {
+ _waitCtrl.OnStopPlayingEvent -= OnStopOrRewindPlaying;
+ _waitCtrl.OnRewindPlayingEvent -= OnStopOrRewindPlaying;
+ _waitCtrl = null;
+ }
+ }
+
+ void OnStopOrRewindPlaying(SwfClipController ctrl) {
+ Unsubscribe();
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopOrRewindPlaying.cs.meta b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopOrRewindPlaying.cs.meta
new file mode 100644
index 0000000..4dac170
--- /dev/null
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopOrRewindPlaying.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e7fb55d9b749a4fae9c1598651878ea9
+timeCreated: 1487272051
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopPlaying.cs b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopPlaying.cs
index 873435f..1e586d9 100644
--- a/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopPlaying.cs
+++ b/Assets/FlashTools/Scripts/FTRuntime/Yields/SwfWaitStopPlaying.cs
@@ -1,7 +1,7 @@
-using System.Collections;
+using UnityEngine;
namespace FTRuntime.Yields {
- public class SwfWaitStopPlaying : IEnumerator {
+ public class SwfWaitStopPlaying : CustomYieldInstruction {
SwfClipController _waitCtrl;
public SwfWaitStopPlaying(SwfClipController ctrl) {
@@ -12,12 +12,20 @@ namespace FTRuntime.Yields {
return Subscribe(ctrl);
}
+ public override bool keepWaiting {
+ get {
+ return _waitCtrl != null;
+ }
+ }
+
+ // ---------------------------------------------------------------------
//
- // Private
+ // Internal
//
+ // ---------------------------------------------------------------------
SwfWaitStopPlaying Subscribe(SwfClipController ctrl) {
- (this as IEnumerator).Reset();
+ Unsubscribe();
if ( ctrl ) {
_waitCtrl = ctrl;
ctrl.OnStopPlayingEvent += OnStopPlaying;
@@ -25,27 +33,15 @@ namespace FTRuntime.Yields {
return this;
}
- void OnStopPlaying(SwfClipController ctrl) {
- (this as IEnumerator).Reset();
- }
-
- //
- // IEnumerator
- //
-
- bool IEnumerator.MoveNext() {
- return _waitCtrl != null;
- }
-
- void IEnumerator.Reset() {
+ void Unsubscribe() {
if ( _waitCtrl != null ) {
_waitCtrl.OnStopPlayingEvent -= OnStopPlaying;
_waitCtrl = null;
}
}
- object IEnumerator.Current {
- get { return null; }
+ void OnStopPlaying(SwfClipController ctrl) {
+ Unsubscribe();
}
}
}
\ No newline at end of file
diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset
index b009c54..c378980 100644
--- a/ProjectSettings/EditorBuildSettings.asset
+++ b/ProjectSettings/EditorBuildSettings.asset
@@ -6,4 +6,4 @@ EditorBuildSettings:
serializedVersion: 2
m_Scenes:
- enabled: 1
- path: Assets/DevTests/Scenes/Scene.unity
+ path: Assets/DevTests/Scene.unity