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;
|
SwfClipAsset.Sequence _curSequence = null;
|
||||||
MaterialPropertyBlock _curPropBlock = 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
|
// Serialized fields
|
||||||
@@ -94,6 +115,7 @@ namespace FTRuntime {
|
|||||||
_sequence = string.Empty;
|
_sequence = string.Empty;
|
||||||
_currentFrame = 0;
|
_currentFrame = 0;
|
||||||
ChangeClip();
|
ChangeClip();
|
||||||
|
EmitChangeEvents(true, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +129,7 @@ namespace FTRuntime {
|
|||||||
_sequence = value;
|
_sequence = value;
|
||||||
_currentFrame = 0;
|
_currentFrame = 0;
|
||||||
ChangeSequence();
|
ChangeSequence();
|
||||||
|
EmitChangeEvents(false, true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +142,7 @@ namespace FTRuntime {
|
|||||||
set {
|
set {
|
||||||
_currentFrame = value;
|
_currentFrame = value;
|
||||||
ChangeCurrentFrame();
|
ChangeCurrentFrame();
|
||||||
|
EmitChangeEvents(false, false, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +166,7 @@ namespace FTRuntime {
|
|||||||
get {
|
get {
|
||||||
return clip
|
return clip
|
||||||
? clip.FrameRate
|
? 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() {
|
SwfClipAsset.Frame GetCurrentBakedFrame() {
|
||||||
var frames = _curSequence != null ? _curSequence.Frames : null;
|
var frames = _curSequence != null ? _curSequence.Frames : null;
|
||||||
return frames != null && currentFrame >= 0 && currentFrame < frames.Count
|
return frames != null && currentFrame >= 0 && currentFrame < frames.Count
|
||||||
@@ -347,6 +383,10 @@ namespace FTRuntime {
|
|||||||
Internal_UpdateAllProperties();
|
Internal_UpdateAllProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Start() {
|
||||||
|
EmitChangeEvents(true, true, true);
|
||||||
|
}
|
||||||
|
|
||||||
void OnEnable() {
|
void OnEnable() {
|
||||||
var swf_manager = SwfManager.GetInstance(true);
|
var swf_manager = SwfManager.GetInstance(true);
|
||||||
if ( swf_manager ) {
|
if ( swf_manager ) {
|
||||||
|
|||||||
@@ -17,17 +17,17 @@ namespace FTRuntime {
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when on stop playing event
|
/// Occurs when the controller stops played clip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event System.Action<SwfClipController> OnStopPlayingEvent;
|
public event System.Action<SwfClipController> OnStopPlayingEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when on play stopped event
|
/// Occurs when the controller plays stopped clip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event System.Action<SwfClipController> OnPlayStoppedEvent;
|
public event System.Action<SwfClipController> OnPlayStoppedEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when on rewind playing event
|
/// Occurs when the controller rewinds played clip
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event System.Action<SwfClipController> OnRewindPlayingEvent;
|
public event System.Action<SwfClipController> OnRewindPlayingEvent;
|
||||||
|
|
||||||
@@ -298,16 +298,17 @@ namespace FTRuntime {
|
|||||||
|
|
||||||
internal void Internal_Update(float dt) {
|
internal void Internal_Update(float dt) {
|
||||||
if ( isPlaying ) {
|
if ( isPlaying ) {
|
||||||
UpdateTimer(dt);
|
_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;
|
||||||
void UpdateTimer(float dt) {
|
if ( frame_time > 0.0f && frame_time <= _tickTimer ) {
|
||||||
var frame_rate = clip ? clip.frameRate : 1.0f;
|
_tickTimer -= frame_time;
|
||||||
_tickTimer += frame_rate * rateScale * dt;
|
TimerTick();
|
||||||
while ( _tickTimer > 1.0f ) {
|
} else {
|
||||||
_tickTimer -= 1.0f;
|
break;
|
||||||
TimerTick();
|
}
|
||||||
|
} while ( isPlaying );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user