mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 22:19:31 +07:00
big name refactor continue
This commit is contained in:
@@ -150,7 +150,7 @@ namespace FlashTools.Internal {
|
||||
static void ConfigureClip(
|
||||
string asset_path,
|
||||
SwfAsset asset,
|
||||
SwfAnimationSymbolData symbol)
|
||||
SwfSymbolData symbol)
|
||||
{
|
||||
var clip_asset_path = SwfEditorUtils.GetClipPathFromSettingsPath(
|
||||
asset_path, symbol.Name);
|
||||
@@ -173,7 +173,7 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static List<SwfClipAsset.Sequence> LoadClipSequences(
|
||||
SwfAsset asset, SwfAnimationSymbolData symbol)
|
||||
SwfAsset asset, SwfSymbolData symbol)
|
||||
{
|
||||
var sequences = new List<SwfClipAsset.Sequence>();
|
||||
if ( IsValidAssetsForFrame(asset, symbol) ) {
|
||||
@@ -193,7 +193,7 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static bool IsValidAssetsForFrame(
|
||||
SwfAsset asset, SwfAnimationSymbolData symbol)
|
||||
SwfAsset asset, SwfSymbolData symbol)
|
||||
{
|
||||
return
|
||||
asset && asset.Atlas && asset.Data != null &&
|
||||
@@ -201,14 +201,14 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
class BakedGroup {
|
||||
public SwfAnimationInstanceType Type;
|
||||
public int ClipDepth;
|
||||
public List<int> Triangles;
|
||||
public Material Material;
|
||||
public SwfInstanceData.Types Type;
|
||||
public int ClipDepth;
|
||||
public List<int> Triangles;
|
||||
public Material Material;
|
||||
}
|
||||
|
||||
static SwfClipAsset.Frame BakeClipFrame(
|
||||
SwfAsset asset, SwfAnimationFrameData frame)
|
||||
SwfAsset asset, SwfFrameData frame)
|
||||
{
|
||||
List<Vector2> baked_uvs = new List<Vector2>();
|
||||
List<Color> baked_mulcolors = new List<Color>();
|
||||
@@ -248,15 +248,15 @@ namespace FlashTools.Internal {
|
||||
baked_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
|
||||
baked_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
|
||||
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTransform.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTrans.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTrans.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTrans.Mul);
|
||||
baked_mulcolors.Add(inst.ColorTrans.Mul);
|
||||
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTransform.Add);
|
||||
baked_addcolors.Add(inst.ColorTrans.Add);
|
||||
baked_addcolors.Add(inst.ColorTrans.Add);
|
||||
baked_addcolors.Add(inst.ColorTrans.Add);
|
||||
baked_addcolors.Add(inst.ColorTrans.Add);
|
||||
|
||||
if ( baked_groups.Count == 0 ||
|
||||
baked_groups[baked_groups.Count - 1].Type != inst.Type ||
|
||||
@@ -283,16 +283,16 @@ namespace FlashTools.Internal {
|
||||
for ( var i = 0; i < baked_groups.Count; ++i ) {
|
||||
var group = baked_groups[i];
|
||||
switch ( group.Type ) {
|
||||
case SwfAnimationInstanceType.Mask:
|
||||
case SwfInstanceData.Types.Mask:
|
||||
group.Material = default_converter.GetIncrMaskMaterial();
|
||||
break;
|
||||
case SwfAnimationInstanceType.Group:
|
||||
case SwfInstanceData.Types.Group:
|
||||
group.Material = default_converter.GetSimpleMaterial();
|
||||
break;
|
||||
case SwfAnimationInstanceType.Masked:
|
||||
case SwfInstanceData.Types.Masked:
|
||||
group.Material = default_converter.GetMaskedMaterial(group.ClipDepth);
|
||||
break;
|
||||
case SwfAnimationInstanceType.MaskReset:
|
||||
case SwfInstanceData.Types.MaskReset:
|
||||
group.Material = default_converter.GetDecrMaskMaterial();
|
||||
break;
|
||||
default:
|
||||
@@ -326,7 +326,7 @@ namespace FlashTools.Internal {
|
||||
Materials = baked_materials.ToArray()};
|
||||
}
|
||||
|
||||
static SwfAnimationBitmapData FindBitmapFromAnimationData(SwfAnimationData data, int bitmap_id) {
|
||||
static SwfBitmapData FindBitmapFromAnimationData(SwfAssetData data, int bitmap_id) {
|
||||
for ( var i = 0; i < data.Bitmaps.Count; ++i ) {
|
||||
var bitmap = data.Bitmaps[i];
|
||||
if ( bitmap.Id == bitmap_id ) {
|
||||
|
||||
@@ -57,55 +57,50 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
static SwfAnimationData LoadDataFromSwfDecoder(
|
||||
static SwfAssetData LoadDataFromSwfDecoder(
|
||||
string swf_asset, SwfAsset asset, SwfDecoder decoder)
|
||||
{
|
||||
var library = new SwfLibrary();
|
||||
return new SwfAnimationData{
|
||||
return new SwfAssetData{
|
||||
FrameRate = decoder.UncompressedHeader.FrameRate,
|
||||
Symbols = LoadSymbols(library, decoder),
|
||||
Bitmaps = LoadBitmaps(swf_asset, asset.Settings, library)};
|
||||
}
|
||||
|
||||
static List<SwfAnimationSymbolData> LoadSymbols(
|
||||
static List<SwfSymbolData> LoadSymbols(
|
||||
SwfLibrary library, SwfDecoder decoder)
|
||||
{
|
||||
var symbols = new List<SwfAnimationSymbolData>();
|
||||
symbols.Add(LoadSymbol(0, "_Stage", library, decoder.Tags));
|
||||
var sprite_defs = library.Defines
|
||||
.Where (p => p.Value.Type == SwfLibraryDefineType.Sprite)
|
||||
.Select(p => new KeyValuePair<int, SwfLibrarySpriteDefine>(
|
||||
p.Key, p.Value as SwfLibrarySpriteDefine))
|
||||
.Where (p => !string.IsNullOrEmpty(p.Value.ExportName));
|
||||
var symbols = new List<SwfSymbolData>();
|
||||
symbols.Add(LoadSymbol("_Stage", library, decoder.Tags));
|
||||
var sprite_defs = library.Defines.Values
|
||||
.OfType<SwfLibrarySpriteDefine>()
|
||||
.Where(p => !string.IsNullOrEmpty(p.ExportName));
|
||||
foreach ( var sprite_def in sprite_defs ) {
|
||||
symbols.Add(LoadSymbol(
|
||||
sprite_def.Key,
|
||||
sprite_def.Value.ExportName,
|
||||
library,
|
||||
sprite_def.Value.ControlTags.Tags));
|
||||
var name = sprite_def.ExportName;
|
||||
var tags = sprite_def.ControlTags.Tags;
|
||||
symbols.Add(LoadSymbol(name, library, tags));
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
static SwfAnimationSymbolData LoadSymbol(
|
||||
int symbol_id, string symbol_name, SwfLibrary library, List<SwfTagBase> tags)
|
||||
static SwfSymbolData LoadSymbol(
|
||||
string symbol_name, SwfLibrary library, List<SwfTagBase> tags)
|
||||
{
|
||||
var disp_lst = new SwfDisplayList();
|
||||
var executer = new SwfContextExecuter(library, 0);
|
||||
var symbol_frames = new List<SwfAnimationFrameData>();
|
||||
var symbol_frames = new List<SwfFrameData>();
|
||||
while ( executer.NextFrame(tags, disp_lst) ) {
|
||||
symbol_frames.Add(LoadSymbolFrame(library, disp_lst));
|
||||
}
|
||||
return new SwfAnimationSymbolData{
|
||||
Id = symbol_id,
|
||||
return new SwfSymbolData{
|
||||
Name = symbol_name,
|
||||
Frames = symbol_frames};
|
||||
}
|
||||
|
||||
static SwfAnimationFrameData LoadSymbolFrame(
|
||||
static SwfFrameData LoadSymbolFrame(
|
||||
SwfLibrary library, SwfDisplayList display_list)
|
||||
{
|
||||
var frame = new SwfAnimationFrameData();
|
||||
var frame = new SwfFrameData();
|
||||
frame.Name = display_list.FrameName;
|
||||
return AddDisplayListToFrame(
|
||||
library,
|
||||
@@ -114,25 +109,25 @@ namespace FlashTools.Internal {
|
||||
0,
|
||||
null,
|
||||
Matrix4x4.identity,
|
||||
SwfAnimationColorTransform.identity,
|
||||
SwfColorTransData.identity,
|
||||
frame);
|
||||
}
|
||||
|
||||
static SwfAnimationFrameData AddDisplayListToFrame(
|
||||
SwfLibrary library,
|
||||
SwfDisplayList display_list,
|
||||
ushort parent_masked,
|
||||
ushort parent_mask,
|
||||
List<SwfAnimationInstanceData> parent_masks,
|
||||
Matrix4x4 parent_matrix,
|
||||
SwfAnimationColorTransform parent_color_transform,
|
||||
SwfAnimationFrameData frame)
|
||||
static SwfFrameData AddDisplayListToFrame(
|
||||
SwfLibrary library,
|
||||
SwfDisplayList display_list,
|
||||
ushort parent_masked,
|
||||
ushort parent_mask,
|
||||
List<SwfInstanceData> parent_masks,
|
||||
Matrix4x4 parent_matrix,
|
||||
SwfColorTransData parent_color_transform,
|
||||
SwfFrameData frame)
|
||||
{
|
||||
var self_masks = new List<SwfAnimationInstanceData>();
|
||||
var self_masks = new List<SwfInstanceData>();
|
||||
foreach ( var inst in display_list.Instances.Values.Where(p => p.Visible) ) {
|
||||
CheckSelfMasks(self_masks, inst.Depth, frame);
|
||||
var child_matrix = parent_matrix * inst.Matrix.ToUnityMatrix();
|
||||
var child_color_transform = parent_color_transform * inst.ColorTransform.ToAnimationColorTransform();
|
||||
var child_color_transform = parent_color_transform * inst.ColorTransform.ToColorTransData();
|
||||
switch ( inst.Type ) {
|
||||
case SwfDisplayInstanceType.Shape:
|
||||
var shape_def = library.FindDefine<SwfLibraryShapeDefine>(inst.Id);
|
||||
@@ -144,22 +139,22 @@ namespace FlashTools.Internal {
|
||||
if ( bitmap_def != null ) {
|
||||
var frame_inst_type =
|
||||
(parent_mask > 0 || inst.ClipDepth > 0)
|
||||
? SwfAnimationInstanceType.Mask
|
||||
? SwfInstanceData.Types.Mask
|
||||
: (parent_masked > 0 || self_masks.Count > 0)
|
||||
? SwfAnimationInstanceType.Masked
|
||||
: SwfAnimationInstanceType.Group;
|
||||
? SwfInstanceData.Types.Masked
|
||||
: SwfInstanceData.Types.Group;
|
||||
var frame_inst_clip_depth =
|
||||
(parent_mask > 0)
|
||||
? parent_mask
|
||||
: (inst.ClipDepth > 0)
|
||||
? inst.ClipDepth
|
||||
: parent_masked + self_masks.Count;
|
||||
frame.Instances.Add(new SwfAnimationInstanceData{
|
||||
Type = frame_inst_type,
|
||||
ClipDepth = (ushort)frame_inst_clip_depth,
|
||||
Bitmap = bitmap_id,
|
||||
Matrix = child_matrix * bitmap_matrix.ToUnityMatrix(),
|
||||
ColorTransform = child_color_transform});
|
||||
frame.Instances.Add(new SwfInstanceData{
|
||||
Type = frame_inst_type,
|
||||
ClipDepth = (ushort)frame_inst_clip_depth,
|
||||
Bitmap = bitmap_id,
|
||||
Matrix = child_matrix * bitmap_matrix.ToUnityMatrix(),
|
||||
ColorTrans = child_color_transform});
|
||||
if ( parent_mask > 0 ) {
|
||||
parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
|
||||
} else if ( inst.ClipDepth > 0 ) {
|
||||
@@ -194,22 +189,22 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static void CheckSelfMasks(
|
||||
List<SwfAnimationInstanceData> masks, ushort depth, SwfAnimationFrameData frame)
|
||||
List<SwfInstanceData> masks, ushort depth, SwfFrameData frame)
|
||||
{
|
||||
foreach ( var mask in masks ) {
|
||||
if ( mask.ClipDepth < depth ) {
|
||||
frame.Instances.Add(new SwfAnimationInstanceData{
|
||||
Type = SwfAnimationInstanceType.MaskReset,
|
||||
ClipDepth = 0,
|
||||
Bitmap = mask.Bitmap,
|
||||
Matrix = mask.Matrix,
|
||||
ColorTransform = mask.ColorTransform});
|
||||
frame.Instances.Add(new SwfInstanceData{
|
||||
Type = SwfInstanceData.Types.MaskReset,
|
||||
ClipDepth = 0,
|
||||
Bitmap = mask.Bitmap,
|
||||
Matrix = mask.Matrix,
|
||||
ColorTrans = mask.ColorTrans});
|
||||
}
|
||||
}
|
||||
masks.RemoveAll(p => p.ClipDepth < depth);
|
||||
}
|
||||
|
||||
static List<SwfAnimationBitmapData> LoadBitmaps(
|
||||
static List<SwfBitmapData> LoadBitmaps(
|
||||
string swf_asset, SwfSettings settings, SwfLibrary library)
|
||||
{
|
||||
var bitmap_defines = library.Defines
|
||||
@@ -222,10 +217,10 @@ namespace FlashTools.Internal {
|
||||
.ToArray();
|
||||
var rects = PackAndSaveBitmapsAtlas(
|
||||
swf_asset, textures, settings);
|
||||
var bitmaps = new List<SwfAnimationBitmapData>(bitmap_defines.Length);
|
||||
var bitmaps = new List<SwfBitmapData>(bitmap_defines.Length);
|
||||
for ( var i = 0; i < bitmap_defines.Length; ++i ) {
|
||||
var bitmap_define = bitmap_defines[i];
|
||||
var bitmap_data = new SwfAnimationBitmapData{
|
||||
var bitmap_data = new SwfBitmapData{
|
||||
Id = bitmap_define.Key,
|
||||
RealSize = new Vector2(bitmap_define.Value.Width, bitmap_define.Value.Height),
|
||||
SourceRect = rects[i]};
|
||||
|
||||
@@ -59,8 +59,8 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
|
||||
RAdd, GAdd, BAdd, AAdd, HasAdd);
|
||||
}
|
||||
|
||||
public SwfAnimationColorTransform ToAnimationColorTransform() {
|
||||
var trans = SwfAnimationColorTransform.identity;
|
||||
public SwfColorTransData ToColorTransData() {
|
||||
var trans = SwfColorTransData.identity;
|
||||
if ( HasAdd ) {
|
||||
trans.Add = new Vector4(
|
||||
RAdd / 255.0f,
|
||||
|
||||
@@ -4,22 +4,22 @@ using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools {
|
||||
[System.Serializable]
|
||||
public struct SwfAnimationColorTransform {
|
||||
public struct SwfColorTransData {
|
||||
public Vector4 Mul;
|
||||
public Vector4 Add;
|
||||
|
||||
public static SwfAnimationColorTransform identity {
|
||||
public static SwfColorTransData identity {
|
||||
get {
|
||||
return new SwfAnimationColorTransform{
|
||||
return new SwfColorTransData{
|
||||
Mul = Vector4.one,
|
||||
Add = Vector4.zero};
|
||||
}
|
||||
}
|
||||
|
||||
public static SwfAnimationColorTransform operator*(
|
||||
SwfAnimationColorTransform a, SwfAnimationColorTransform b)
|
||||
public static SwfColorTransData operator*(
|
||||
SwfColorTransData a, SwfColorTransData b)
|
||||
{
|
||||
return new SwfAnimationColorTransform{
|
||||
return new SwfColorTransData{
|
||||
Mul = new Vector4(
|
||||
b.Mul.x * a.Mul.x,
|
||||
b.Mul.y * a.Mul.y,
|
||||
@@ -33,51 +33,49 @@ namespace FlashTools {
|
||||
}
|
||||
}
|
||||
|
||||
public enum SwfAnimationInstanceType {
|
||||
Mask,
|
||||
Group,
|
||||
Masked,
|
||||
MaskReset
|
||||
[System.Serializable]
|
||||
public class SwfInstanceData {
|
||||
public enum Types {
|
||||
Mask,
|
||||
Group,
|
||||
Masked,
|
||||
MaskReset
|
||||
}
|
||||
public Types Type = Types.Group;
|
||||
public ushort ClipDepth = 0;
|
||||
public ushort Bitmap = 0;
|
||||
public Matrix4x4 Matrix = Matrix4x4.identity;
|
||||
public SwfColorTransData ColorTrans = SwfColorTransData.identity;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfAnimationInstanceData {
|
||||
public SwfAnimationInstanceType Type = SwfAnimationInstanceType.Group;
|
||||
public ushort ClipDepth = 0;
|
||||
public ushort Bitmap = 0;
|
||||
public Matrix4x4 Matrix = Matrix4x4.identity;
|
||||
public SwfAnimationColorTransform ColorTransform = SwfAnimationColorTransform.identity;
|
||||
public class SwfFrameData {
|
||||
public string Name = string.Empty;
|
||||
public List<SwfInstanceData> Instances = new List<SwfInstanceData>();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfAnimationFrameData {
|
||||
public string Name = string.Empty;
|
||||
public List<SwfAnimationInstanceData> Instances = new List<SwfAnimationInstanceData>();
|
||||
public class SwfSymbolData {
|
||||
public string Name = string.Empty;
|
||||
public List<SwfFrameData> Frames = new List<SwfFrameData>();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfAnimationSymbolData {
|
||||
public int Id = 0;
|
||||
public string Name = string.Empty;
|
||||
public List<SwfAnimationFrameData> Frames = new List<SwfAnimationFrameData>();
|
||||
public class SwfBitmapData {
|
||||
public int Id = 0;
|
||||
public Vector2 RealSize = Vector2.zero;
|
||||
public Rect SourceRect = new Rect();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfAnimationBitmapData {
|
||||
public int Id = 0;
|
||||
public Vector2 RealSize = Vector2.zero;
|
||||
public Rect SourceRect = new Rect();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfAnimationData {
|
||||
public float FrameRate = 0.0f;
|
||||
public List<SwfAnimationSymbolData> Symbols = new List<SwfAnimationSymbolData>();
|
||||
public List<SwfAnimationBitmapData> Bitmaps = new List<SwfAnimationBitmapData>();
|
||||
public class SwfAssetData {
|
||||
public float FrameRate = 0.0f;
|
||||
public List<SwfSymbolData> Symbols = new List<SwfSymbolData>();
|
||||
public List<SwfBitmapData> Bitmaps = new List<SwfBitmapData>();
|
||||
}
|
||||
|
||||
public class SwfAsset : ScriptableObject {
|
||||
public SwfAnimationData Data;
|
||||
public SwfAssetData Data;
|
||||
public Texture2D Atlas;
|
||||
public List<SwfClipAsset> Clips;
|
||||
public SwfSettings Settings;
|
||||
@@ -85,7 +83,7 @@ namespace FlashTools {
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void Reset() {
|
||||
Data = new SwfAnimationData();
|
||||
Data = new SwfAssetData();
|
||||
Atlas = null;
|
||||
Clips = new List<SwfClipAsset>();
|
||||
Settings = SwfConverterSettings.GetDefaultSettings();
|
||||
|
||||
@@ -179,27 +179,29 @@ namespace FlashTools {
|
||||
_curPropBlock = new MaterialPropertyBlock();
|
||||
}
|
||||
_meshRenderer.GetPropertyBlock(_curPropBlock);
|
||||
var atlas = clip ? clip.Atlas : null;
|
||||
if ( atlas ) {
|
||||
_curPropBlock.SetTexture("_MainTex", atlas);
|
||||
}
|
||||
_curPropBlock.SetTexture(
|
||||
"_MainTex",
|
||||
clip && clip.Atlas ? clip.Atlas : Texture2D.whiteTexture);
|
||||
_meshRenderer.SetPropertyBlock(_curPropBlock);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateCurrentMesh() {
|
||||
if ( _meshFilter && _meshRenderer ) {
|
||||
var baked_frame = GetCurrentBakedFrame();
|
||||
_meshFilter.sharedMesh = baked_frame.Mesh;
|
||||
var baked_frame = GetCurrentBakedFrame();
|
||||
_meshFilter.sharedMesh = baked_frame.Mesh;
|
||||
_meshRenderer.sharedMaterials = baked_frame.Materials;
|
||||
}
|
||||
}
|
||||
|
||||
SwfClipAsset.Frame GetCurrentBakedFrame() {
|
||||
var frames = _curSequence != null ? _curSequence.Frames : null;
|
||||
return frames != null && currentFrame >= 0 && currentFrame < frames.Count
|
||||
var frame = frames != null && currentFrame >= 0 && currentFrame < frames.Count
|
||||
? frames[currentFrame]
|
||||
: new SwfClipAsset.Frame();
|
||||
return frame != null
|
||||
? frame
|
||||
: new SwfClipAsset.Frame();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using UnityEngine;
|
||||
using FlashTools.Internal;
|
||||
using System;
|
||||
|
||||
namespace FlashTools {
|
||||
[ExecuteInEditMode, DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(SwfClip))]
|
||||
public class SwfClipController : MonoBehaviour {
|
||||
|
||||
SwfClip _clip = null;
|
||||
float _frameTimer = 0.0f;
|
||||
SwfClip _clip = null;
|
||||
float _timer = 0.0f;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
@@ -16,11 +15,11 @@ namespace FlashTools {
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public event Action<SwfClipController> OnStopPlayingEvent;
|
||||
public event Action<SwfClipController> OnRewindPlayingEvent;
|
||||
public event System.Action<SwfClipController> OnStopPlayingEvent;
|
||||
public event System.Action<SwfClipController> OnRewindPlayingEvent;
|
||||
|
||||
public event Action<SwfClipController> OnPausePlayingEvent;
|
||||
public event Action<SwfClipController> OnResumePausedEvent;
|
||||
public event System.Action<SwfClipController> OnPausePlayingEvent;
|
||||
public event System.Action<SwfClipController> OnResumePausedEvent;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
@@ -73,21 +72,21 @@ namespace FlashTools {
|
||||
set { _loopMode = value; }
|
||||
}
|
||||
|
||||
States _currentState = States.Stopped;
|
||||
public States currentState {
|
||||
get { return _currentState; }
|
||||
States _state = States.Stopped;
|
||||
public States state {
|
||||
get { return _state; }
|
||||
}
|
||||
|
||||
public bool isStopped {
|
||||
get { return currentState == States.Stopped; }
|
||||
get { return state == States.Stopped; }
|
||||
}
|
||||
|
||||
public bool isPaused {
|
||||
get { return currentState == States.Paused; }
|
||||
get { return state == States.Paused; }
|
||||
}
|
||||
|
||||
public bool isPlaying {
|
||||
get { return currentState == States.Playing; }
|
||||
get { return state == States.Playing; }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
@@ -102,8 +101,8 @@ namespace FlashTools {
|
||||
|
||||
public void Stop(bool rewind) {
|
||||
var is_playing = isPlaying;
|
||||
_frameTimer = 0.0f;
|
||||
_currentState = States.Stopped;
|
||||
_timer = 0.0f;
|
||||
_state = States.Stopped;
|
||||
if ( rewind ) {
|
||||
Rewind();
|
||||
}
|
||||
@@ -114,7 +113,7 @@ namespace FlashTools {
|
||||
|
||||
public void Pause() {
|
||||
if ( isPlaying ) {
|
||||
_currentState = States.Paused;
|
||||
_state = States.Paused;
|
||||
if ( OnPausePlayingEvent != null ) {
|
||||
OnPausePlayingEvent(this);
|
||||
}
|
||||
@@ -123,7 +122,7 @@ namespace FlashTools {
|
||||
|
||||
public void Resume() {
|
||||
if ( isPaused ) {
|
||||
_currentState = States.Playing;
|
||||
_state = States.Playing;
|
||||
if ( OnResumePausedEvent != null ) {
|
||||
OnResumePausedEvent(this);
|
||||
}
|
||||
@@ -132,17 +131,21 @@ namespace FlashTools {
|
||||
|
||||
public void Play() {
|
||||
Rewind();
|
||||
_frameTimer = 0.0f;
|
||||
_currentState = States.Playing;
|
||||
_timer = 0.0f;
|
||||
_state = States.Playing;
|
||||
}
|
||||
|
||||
public void Rewind() {
|
||||
switch ( playMode ) {
|
||||
case PlayModes.Forward:
|
||||
_clip.ToBeginFrame();
|
||||
if ( _clip ) {
|
||||
_clip.ToBeginFrame();
|
||||
}
|
||||
break;
|
||||
case PlayModes.Backward:
|
||||
_clip.ToEndFrame();
|
||||
if ( _clip ) {
|
||||
_clip.ToEndFrame();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
@@ -162,19 +165,20 @@ namespace FlashTools {
|
||||
|
||||
public void InternalUpdate(float dt) {
|
||||
if ( isPlaying ) {
|
||||
UpdateFrameTimer(dt);
|
||||
UpdateTimer(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateFrameTimer(float dt) {
|
||||
_frameTimer += _clip.frameRate * rateScale * dt;
|
||||
while ( _frameTimer > 1.0f ) {
|
||||
_frameTimer -= 1.0f;
|
||||
FrameTimerTick();
|
||||
void UpdateTimer(float dt) {
|
||||
var frame_rate = _clip ? _clip.frameRate : 1.0f;
|
||||
_timer += frame_rate * rateScale * dt;
|
||||
while ( _timer > 1.0f ) {
|
||||
_timer -= 1.0f;
|
||||
TimerTick();
|
||||
}
|
||||
}
|
||||
|
||||
void FrameTimerTick() {
|
||||
void TimerTick() {
|
||||
if ( !NextClipFrame() ) {
|
||||
switch ( loopMode ) {
|
||||
case LoopModes.Once:
|
||||
@@ -194,9 +198,9 @@ namespace FlashTools {
|
||||
bool NextClipFrame() {
|
||||
switch ( playMode ) {
|
||||
case PlayModes.Forward:
|
||||
return _clip.ToNextFrame();
|
||||
return _clip ? _clip.ToNextFrame() : false;
|
||||
case PlayModes.Backward:
|
||||
return _clip.ToPrevFrame();
|
||||
return _clip ? _clip.ToPrevFrame() : false;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
"SwfClipController. Incorrect play mode: {0}",
|
||||
|
||||
Reference in New Issue
Block a user