mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
controller API improvements
This commit is contained in:
@@ -19,14 +19,11 @@ namespace FlashTools.Internal {
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
{
|
||||
if ( GUILayout.Button("Rewind") ) {
|
||||
AllControllersForeach(p => p.Rewind());
|
||||
}
|
||||
if ( GUILayout.Button("Stop") ) {
|
||||
AllControllersForeach(p => p.Stop());
|
||||
AllControllersForeach(ctrl => ctrl.Stop(ctrl.isStopped));
|
||||
}
|
||||
if ( GUILayout.Button("Play") ) {
|
||||
AllControllersForeach(p => p.Play());
|
||||
AllControllersForeach(ctrl => ctrl.Play(ctrl.isPlaying));
|
||||
}
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace FlashTools {
|
||||
|
||||
[Header("Sorting")]
|
||||
[SerializeField][SwfSortingLayer]
|
||||
public string _sortingLayer = "Default";
|
||||
public string _sortingLayer = string.Empty;
|
||||
public string sortingLayer {
|
||||
get { return _sortingLayer; }
|
||||
set {
|
||||
@@ -50,17 +50,20 @@ namespace FlashTools {
|
||||
public SwfClipAsset clip {
|
||||
get { return _clip; }
|
||||
set {
|
||||
_clip = value;
|
||||
_clip = value;
|
||||
_sequence = string.Empty;
|
||||
_currentFrame = 0;
|
||||
ChangeClip();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField][HideInInspector]
|
||||
string _sequence = "Default";
|
||||
string _sequence = string.Empty;
|
||||
public string sequence {
|
||||
get { return _sequence; }
|
||||
set {
|
||||
_sequence = value;
|
||||
_sequence = value;
|
||||
_currentFrame = 0;
|
||||
ChangeSequence();
|
||||
}
|
||||
}
|
||||
@@ -85,7 +88,9 @@ namespace FlashTools {
|
||||
|
||||
public float frameRate {
|
||||
get {
|
||||
return clip ? clip.FrameRate : 1.0f;
|
||||
return clip
|
||||
? clip.FrameRate
|
||||
: 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +105,9 @@ namespace FlashTools {
|
||||
}
|
||||
|
||||
public void ToEndFrame() {
|
||||
currentFrame = frameCount - 1;
|
||||
currentFrame = frameCount > 0
|
||||
? frameCount - 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
public bool ToPrevFrame() {
|
||||
@@ -129,10 +136,10 @@ namespace FlashTools {
|
||||
if ( _meshFilter && _meshRenderer && _dirtyMesh ) {
|
||||
var baked_frame = GetCurrentBakedFrame();
|
||||
if ( baked_frame != null ) {
|
||||
_meshFilter.sharedMesh = baked_frame.CachedMesh;
|
||||
_meshFilter .sharedMesh = baked_frame.CachedMesh;
|
||||
_meshRenderer.sharedMaterials = baked_frame.Materials;
|
||||
} else {
|
||||
_meshFilter.sharedMesh = null;
|
||||
_meshFilter .sharedMesh = null;
|
||||
_meshRenderer.sharedMaterials = new Material[0];
|
||||
}
|
||||
}
|
||||
@@ -140,11 +147,10 @@ namespace FlashTools {
|
||||
|
||||
public void UpdateAllProperties() {
|
||||
ClearCache();
|
||||
clip = _clip;
|
||||
sequence = _sequence;
|
||||
currentFrame = _currentFrame;
|
||||
sortingLayer = _sortingLayer;
|
||||
sortingOrder = _sortingOrder;
|
||||
ChangeClip();
|
||||
ChangeSequence();
|
||||
ChangeCurrentFrame();
|
||||
ChangeSortingProperties();
|
||||
}
|
||||
|
||||
void ClearCache() {
|
||||
@@ -155,13 +161,6 @@ namespace FlashTools {
|
||||
_curPropBlock = null;
|
||||
}
|
||||
|
||||
void ChangeSortingProperties() {
|
||||
if ( _meshRenderer ) {
|
||||
_meshRenderer.sortingOrder = sortingOrder;
|
||||
_meshRenderer.sortingLayerName = sortingLayer;
|
||||
}
|
||||
}
|
||||
|
||||
void ChangeClip() {
|
||||
if ( _meshRenderer ) {
|
||||
_meshRenderer.enabled = !!clip;
|
||||
@@ -173,11 +172,18 @@ namespace FlashTools {
|
||||
void ChangeSequence() {
|
||||
_curSequence = null;
|
||||
if ( clip && clip.Sequences != null ) {
|
||||
for ( int i = 0, e = clip.Sequences.Count; i < e; ++i ) {
|
||||
var clip_sequence = clip.Sequences[i];
|
||||
if ( clip_sequence != null && clip_sequence.Name == sequence ) {
|
||||
_curSequence = clip_sequence;
|
||||
break;
|
||||
if ( !string.IsNullOrEmpty(sequence) ) {
|
||||
for ( int i = 0, e = clip.Sequences.Count; i < e; ++i ) {
|
||||
var clip_sequence = clip.Sequences[i];
|
||||
if ( clip_sequence != null && clip_sequence.Name == sequence ) {
|
||||
_curSequence = clip_sequence;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( _curSequence == null ) {
|
||||
Debug.LogWarningFormat(this,
|
||||
"SwfClip. Sequence '{0}' not found",
|
||||
sequence);
|
||||
}
|
||||
}
|
||||
if ( _curSequence == null ) {
|
||||
@@ -201,6 +207,13 @@ namespace FlashTools {
|
||||
SetDirtyCurrentMesh();
|
||||
}
|
||||
|
||||
void ChangeSortingProperties() {
|
||||
if ( _meshRenderer ) {
|
||||
_meshRenderer.sortingOrder = sortingOrder;
|
||||
_meshRenderer.sortingLayerName = sortingLayer;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePropBlock() {
|
||||
if ( _meshRenderer ) {
|
||||
if ( _curPropBlock == null ) {
|
||||
|
||||
@@ -65,6 +65,10 @@ namespace FlashTools {
|
||||
set { _loopMode = value; }
|
||||
}
|
||||
|
||||
public SwfClip clip {
|
||||
get { return _clip; }
|
||||
}
|
||||
|
||||
public bool isPlaying {
|
||||
get { return _isPlaying; }
|
||||
}
|
||||
@@ -80,47 +84,101 @@ namespace FlashTools {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public void GotoAndStop(int frame) {
|
||||
if ( _clip ) {
|
||||
_clip.currentFrame = frame;
|
||||
if ( clip ) {
|
||||
clip.currentFrame = frame;
|
||||
}
|
||||
Stop();
|
||||
Stop(false);
|
||||
}
|
||||
|
||||
public void GotoAndStop(string sequence, int frame) {
|
||||
if ( clip ) {
|
||||
clip.sequence = sequence;
|
||||
}
|
||||
GotoAndStop(frame);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public void GotoAndPlay(int frame) {
|
||||
if ( _clip ) {
|
||||
_clip.currentFrame = frame;
|
||||
if ( clip ) {
|
||||
clip.currentFrame = frame;
|
||||
}
|
||||
Play();
|
||||
Play(false);
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
public void GotoAndPlay(string sequence, int frame) {
|
||||
if ( clip ) {
|
||||
clip.sequence = sequence;
|
||||
}
|
||||
GotoAndPlay(frame);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public void Stop(bool rewind) {
|
||||
var is_playing = isPlaying;
|
||||
_isPlaying = false;
|
||||
_tickTimer = 0.0f;
|
||||
if ( is_playing ) {
|
||||
_isPlaying = false;
|
||||
_tickTimer = 0.0f;
|
||||
}
|
||||
if ( rewind ) {
|
||||
Rewind();
|
||||
}
|
||||
if ( is_playing && OnStopPlayingEvent != null ) {
|
||||
OnStopPlayingEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play() {
|
||||
public void Stop(string sequence) {
|
||||
if ( clip ) {
|
||||
clip.sequence = sequence;
|
||||
}
|
||||
Stop(true);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public void Play(bool rewind) {
|
||||
var is_stopped = isStopped;
|
||||
_isPlaying = true;
|
||||
_tickTimer = 0.0f;
|
||||
if ( is_stopped ) {
|
||||
_isPlaying = true;
|
||||
_tickTimer = 0.0f;
|
||||
}
|
||||
if ( rewind ) {
|
||||
Rewind();
|
||||
}
|
||||
if ( is_stopped && OnPlayStoppedEvent != null ) {
|
||||
OnPlayStoppedEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string sequence) {
|
||||
if ( clip ) {
|
||||
clip.sequence = sequence;
|
||||
}
|
||||
Play(true);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
public void Rewind() {
|
||||
switch ( playMode ) {
|
||||
case PlayModes.Forward:
|
||||
if ( _clip ) {
|
||||
_clip.ToBeginFrame();
|
||||
if ( clip ) {
|
||||
clip.ToBeginFrame();
|
||||
}
|
||||
break;
|
||||
case PlayModes.Backward:
|
||||
if ( _clip ) {
|
||||
_clip.ToEndFrame();
|
||||
if ( clip ) {
|
||||
clip.ToEndFrame();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -146,7 +204,7 @@ namespace FlashTools {
|
||||
}
|
||||
|
||||
void UpdateTimer(float dt) {
|
||||
var frame_rate = _clip ? _clip.frameRate : 1.0f;
|
||||
var frame_rate = clip ? clip.frameRate : 1.0f;
|
||||
_tickTimer += frame_rate * rateScale * dt;
|
||||
while ( _tickTimer > 1.0f ) {
|
||||
_tickTimer -= 1.0f;
|
||||
@@ -158,7 +216,7 @@ namespace FlashTools {
|
||||
if ( !NextClipFrame() ) {
|
||||
switch ( loopMode ) {
|
||||
case LoopModes.Once:
|
||||
Stop();
|
||||
Stop(false);
|
||||
break;
|
||||
case LoopModes.Loop:
|
||||
Rewind();
|
||||
@@ -174,9 +232,9 @@ namespace FlashTools {
|
||||
bool NextClipFrame() {
|
||||
switch ( playMode ) {
|
||||
case PlayModes.Forward:
|
||||
return _clip ? _clip.ToNextFrame() : false;
|
||||
return clip ? clip.ToNextFrame() : false;
|
||||
case PlayModes.Backward:
|
||||
return _clip ? _clip.ToPrevFrame() : false;
|
||||
return clip ? clip.ToPrevFrame() : false;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"SwfClipController. Incorrect play mode: {0}",
|
||||
@@ -193,7 +251,7 @@ namespace FlashTools {
|
||||
void Awake() {
|
||||
_clip = GetComponent<SwfClip>();
|
||||
if ( autoPlay && Application.isPlaying ) {
|
||||
Play();
|
||||
Play(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user