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