mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
clip events
This commit is contained in:
@@ -13,6 +13,27 @@ namespace FTRuntime {
|
||||
SwfClipAsset.Sequence _curSequence = null;
|
||||
MaterialPropertyBlock _curPropBlock = null;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Events
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when clip changes
|
||||
/// </summary>
|
||||
public event System.Action<SwfClip> OnChangeClipEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when sequence changes
|
||||
/// </summary>
|
||||
public event System.Action<SwfClip> OnChangeSequenceEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when current frame changes
|
||||
/// </summary>
|
||||
public event System.Action<SwfClip> 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 ) {
|
||||
|
||||
@@ -17,17 +17,17 @@ namespace FTRuntime {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when on stop playing event
|
||||
/// Occurs when the controller stops played clip
|
||||
/// </summary>
|
||||
public event System.Action<SwfClipController> OnStopPlayingEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when on play stopped event
|
||||
/// Occurs when the controller plays stopped clip
|
||||
/// </summary>
|
||||
public event System.Action<SwfClipController> OnPlayStoppedEvent;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when on rewind playing event
|
||||
/// Occurs when the controller rewinds played clip
|
||||
/// </summary>
|
||||
public event System.Action<SwfClipController> 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 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user