diff --git a/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs b/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs index 50916a1..e37a99e 100644 --- a/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs +++ b/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs @@ -13,6 +13,27 @@ namespace FTRuntime { SwfClipAsset.Sequence _curSequence = null; MaterialPropertyBlock _curPropBlock = null; + // --------------------------------------------------------------------- + // + // Events + // + // --------------------------------------------------------------------- + + /// + /// Occurs when clip changes + /// + public event System.Action OnChangeClipEvent; + + /// + /// Occurs when sequence changes + /// + public event System.Action OnChangeSequenceEvent; + + /// + /// Occurs when current frame changes + /// + public event System.Action OnChangeCurrentFrameEvent; + // --------------------------------------------------------------------- // // Serialized fields @@ -94,6 +115,7 @@ namespace FTRuntime { _sequence = string.Empty; _currentFrame = 0; ChangeClip(); + EmitChangeEvents(true, true, true); } } @@ -107,6 +129,7 @@ namespace FTRuntime { _sequence = value; _currentFrame = 0; ChangeSequence(); + EmitChangeEvents(false, true, true); } } @@ -119,6 +142,7 @@ namespace FTRuntime { set { _currentFrame = value; ChangeCurrentFrame(); + EmitChangeEvents(false, false, true); } } @@ -142,7 +166,7 @@ namespace FTRuntime { get { return clip ? clip.FrameRate - : 1.0f; + : 0.0f; } } @@ -330,6 +354,18 @@ namespace FTRuntime { } } + void EmitChangeEvents(bool clip, bool sequence, bool current_frame) { + if ( clip && OnChangeClipEvent != null ) { + OnChangeClipEvent(this); + } + if ( sequence && OnChangeSequenceEvent != null ) { + OnChangeSequenceEvent(this); + } + if ( current_frame && OnChangeCurrentFrameEvent != null ) { + OnChangeCurrentFrameEvent(this); + } + } + SwfClipAsset.Frame GetCurrentBakedFrame() { var frames = _curSequence != null ? _curSequence.Frames : null; return frames != null && currentFrame >= 0 && currentFrame < frames.Count @@ -347,6 +383,10 @@ namespace FTRuntime { Internal_UpdateAllProperties(); } + void Start() { + EmitChangeEvents(true, true, true); + } + void OnEnable() { var swf_manager = SwfManager.GetInstance(true); if ( swf_manager ) { diff --git a/Assets/FlashTools/Scripts/FTRuntime/SwfClipController.cs b/Assets/FlashTools/Scripts/FTRuntime/SwfClipController.cs index c779015..b8c47e2 100644 --- a/Assets/FlashTools/Scripts/FTRuntime/SwfClipController.cs +++ b/Assets/FlashTools/Scripts/FTRuntime/SwfClipController.cs @@ -17,17 +17,17 @@ namespace FTRuntime { // --------------------------------------------------------------------- /// - /// Occurs when on stop playing event + /// Occurs when the controller stops played clip /// public event System.Action OnStopPlayingEvent; /// - /// Occurs when on play stopped event + /// Occurs when the controller plays stopped clip /// public event System.Action OnPlayStoppedEvent; /// - /// Occurs when on rewind playing event + /// Occurs when the controller rewinds played clip /// public event System.Action OnRewindPlayingEvent; @@ -298,16 +298,17 @@ namespace FTRuntime { internal void Internal_Update(float dt) { if ( isPlaying ) { - UpdateTimer(dt); - } - } - - void UpdateTimer(float dt) { - var frame_rate = clip ? clip.frameRate : 1.0f; - _tickTimer += frame_rate * rateScale * dt; - while ( _tickTimer > 1.0f ) { - _tickTimer -= 1.0f; - TimerTick(); + _tickTimer += dt; + do { + var frame_rate = clip ? clip.frameRate * rateScale : 0.0f; + var frame_time = frame_rate > 0.0f ? 1.0f / frame_rate : 0.0f; + if ( frame_time > 0.0f && frame_time <= _tickTimer ) { + _tickTimer -= frame_time; + TimerTick(); + } else { + break; + } + } while ( isPlaying ); } }