big name refactor

This commit is contained in:
2016-09-02 01:32:43 +07:00
parent 274f1c2c00
commit b5b74e92e7
25 changed files with 227 additions and 227 deletions
+5 -5
View File
@@ -45,11 +45,11 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationAssetEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationAssetPostprocessor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationClipAssetEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationControllerEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAnimationEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAssetEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfAssetPostprocessor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfClipAssetEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfClipControllerEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfClipEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfEditorUtils.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfManagerEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfPostprocessor.cs" />
+4 -4
View File
@@ -48,10 +48,10 @@
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfConverterSettings.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfPropertyAttributes.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfSettings.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfAnimation.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfAnimationAsset.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfAnimationClipAsset.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfAnimationController.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfAsset.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfClip.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfClipAsset.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfClipController.cs" />
<Compile Include="Assets\FlashTools\Scripts\SwfManager.cs" />
<None Include="Assets\FlashTools\Resources\Shaders\SwfDecrMask.shader" />
<None Include="Assets\FlashTools\Resources\Shaders\SwfSimple.shader" />
@@ -7,22 +7,22 @@ using System.Linq;
using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfAnimationAsset)), CanEditMultipleObjects]
public class SwfAnimationAssetEditor : Editor {
List<SwfAnimationAsset> _assets = new List<SwfAnimationAsset>();
bool _settingsFoldout = false;
[CustomEditor(typeof(SwfAsset)), CanEditMultipleObjects]
public class SwfAssetEditor : Editor {
List<SwfAsset> _assets = new List<SwfAsset>();
bool _settingsFoldout = false;
//
//
//
static string GetAssetPath(SwfAnimationAsset asset) {
static string GetAssetPath(SwfAsset asset) {
return asset
? AssetDatabase.GetAssetPath(asset)
: string.Empty;
}
static string GetSwfPath(SwfAnimationAsset asset) {
static string GetSwfPath(SwfAsset asset) {
var asset_path = GetAssetPath(asset);
return string.IsNullOrEmpty(asset_path)
? string.Empty
@@ -33,27 +33,27 @@ namespace FlashTools.Internal {
//
//
static void RevertOverriddenSettings(SwfAnimationAsset asset) {
static void RevertOverriddenSettings(SwfAsset asset) {
asset.Overridden = asset.Settings;
}
static void OverriddenSettingsToDefault(SwfAnimationAsset asset) {
static void OverriddenSettingsToDefault(SwfAsset asset) {
asset.Overridden = SwfConverterSettings.GetDefaultSettings();
}
static void ApplyOverriddenSettings(SwfAnimationAsset asset) {
static void ApplyOverriddenSettings(SwfAsset asset) {
if ( File.Exists(GetSwfPath(asset)) ) {
asset.Settings = asset.Overridden;
ReconvertAnimationAsset(asset);
ReconvertAsset(asset);
} else {
Debug.LogErrorFormat(
"Swf source for animation not found: '{0}'",
"Swf source for asset not found: '{0}'",
GetSwfPath(asset));
RevertOverriddenSettings(asset);
}
}
static void ReconvertAnimationAsset(SwfAnimationAsset asset) {
static void ReconvertAsset(SwfAsset asset) {
AssetDatabase.ImportAsset(GetSwfPath(asset));
}
@@ -61,7 +61,7 @@ namespace FlashTools.Internal {
//
//
void AllAssetsForeach(Action<SwfAnimationAsset> act) {
void AllAssetsForeach(Action<SwfAsset> act) {
foreach ( var asset in _assets ) {
act(asset);
}
@@ -89,13 +89,13 @@ namespace FlashTools.Internal {
.ToArray();
if ( unapplied.Length > 0 ) {
var title =
"Unapplied swf animation settings";
"Unapplied swf asset settings";
var message = unapplied.Length == 1
? string.Format(
"Unapplied swf animation settings for '{0}'",
"Unapplied swf asset settings for '{0}'",
GetAssetPath(unapplied[0]))
: string.Format(
"Unapplied multiple({0}) swf animation settings",
"Unapplied multiple({0}) swf asset settings",
unapplied.Length);
if ( EditorUtility.DisplayDialog(title, message, "Apply", "Revert") ) {
ApplyAllOverriddenSettings();
@@ -163,7 +163,7 @@ namespace FlashTools.Internal {
void OnEnable() {
_assets = targets
.OfType<SwfAnimationAsset>()
.OfType<SwfAsset>()
.ToList();
_settingsFoldout =
_assets.Any(p => !p.Settings.CheckEquals(SwfConverterSettings.GetDefaultSettings()));
@@ -7,7 +7,7 @@ using System.Reflection;
using System.Collections.Generic;
namespace FlashTools.Internal {
public class SwfAnimationAssetPostprocessor : AssetPostprocessor {
public class SwfAssetPostprocessor : AssetPostprocessor {
static void OnPostprocessAllAssets(
string[] imported_assets,
string[] deleted_assets,
@@ -17,14 +17,14 @@ namespace FlashTools.Internal {
var asset_paths = imported_assets
.Where(p => Path.GetExtension(p).ToLower().Equals(".asset"));
foreach ( var asset_path in asset_paths ) {
var asset = AssetDatabase.LoadAssetAtPath<SwfAnimationAsset>(asset_path);
var asset = AssetDatabase.LoadAssetAtPath<SwfAsset>(asset_path);
if ( asset ) {
AssetProcess(asset_path, asset);
}
}
}
static void AssetProcess(string asset_path, SwfAnimationAsset asset) {
static void AssetProcess(string asset_path, SwfAsset asset) {
try {
var atlas_asset = LoadAtlasAsset(asset_path);
if ( atlas_asset != asset.Atlas ) {
@@ -34,12 +34,12 @@ namespace FlashTools.Internal {
EditorUtility.SetDirty(asset);
AssetDatabase.SaveAssets();
}
ConfigureAssetAnimations(asset);
ConfigureAssetClips(asset);
} catch ( Exception e ) {
Debug.LogErrorFormat(
"Postprocess swf animation asset error: {0}",
e.Message);
SwfEditorUtils.DeleteAnimationAssetWithDepends(asset);
SwfEditorUtils.DeleteAssetWithDepends(asset);
}
}
@@ -54,7 +54,7 @@ namespace FlashTools.Internal {
//
// ---------------------------------------------------------------------
static void ConfigureAtlas(string asset_path, SwfAnimationAsset asset) {
static void ConfigureAtlas(string asset_path, SwfAsset asset) {
var atlas_importer = GetBitmapsAtlasImporter(asset_path);
var atlas_importer_size = GetSizeFromTextureImporter(atlas_importer);
atlas_importer.spritesheet = asset.Data.Bitmaps
@@ -139,7 +139,7 @@ namespace FlashTools.Internal {
static void ConfigureClips(
string asset_path,
SwfAnimationAsset asset)
SwfAsset asset)
{
SwfEditorUtils.RemoveAllSubAssets(asset_path);
foreach ( var symbol in asset.Data.Symbols ) {
@@ -149,14 +149,14 @@ namespace FlashTools.Internal {
static void ConfigureClip(
string asset_path,
SwfAnimationAsset asset,
SwfAsset asset,
SwfAnimationSymbolData symbol)
{
var clip_asset_path = SwfEditorUtils.GetClipPathFromSettingsPath(
asset_path, symbol.Name);
var clip_asset = AssetDatabase.LoadAssetAtPath<SwfAnimationClipAsset>(clip_asset_path);
var clip_asset = AssetDatabase.LoadAssetAtPath<SwfClipAsset>(clip_asset_path);
if ( !clip_asset ) {
clip_asset = ScriptableObject.CreateInstance<SwfAnimationClipAsset>();
clip_asset = ScriptableObject.CreateInstance<SwfClipAsset>();
AssetDatabase.CreateAsset(clip_asset, clip_asset_path);
}
clip_asset.Atlas = asset.Atlas;
@@ -172,19 +172,19 @@ namespace FlashTools.Internal {
}
}
static List<SwfAnimationClipAsset.Sequence> LoadClipSequences(
SwfAnimationAsset asset, SwfAnimationSymbolData symbol)
static List<SwfClipAsset.Sequence> LoadClipSequences(
SwfAsset asset, SwfAnimationSymbolData symbol)
{
var sequences = new List<SwfAnimationClipAsset.Sequence>();
var sequences = new List<SwfClipAsset.Sequence>();
if ( IsValidAssetsForFrame(asset, symbol) ) {
foreach ( var frame in symbol.Frames ) {
var baked_frame = BakeClipFrame(asset, frame);
if ( !string.IsNullOrEmpty(frame.Name) &&
(sequences.Count < 1 || sequences.Last().Name != frame.Name) )
{
sequences.Add(new SwfAnimationClipAsset.Sequence{Name = frame.Name});
sequences.Add(new SwfClipAsset.Sequence{Name = frame.Name});
} else if ( sequences.Count < 1 ) {
sequences.Add(new SwfAnimationClipAsset.Sequence{Name = "Default"});
sequences.Add(new SwfClipAsset.Sequence{Name = "Default"});
}
sequences.Last().Frames.Add(baked_frame);
}
@@ -193,7 +193,7 @@ namespace FlashTools.Internal {
}
static bool IsValidAssetsForFrame(
SwfAnimationAsset asset, SwfAnimationSymbolData symbol)
SwfAsset asset, SwfAnimationSymbolData symbol)
{
return
asset && asset.Atlas && asset.Data != null &&
@@ -207,8 +207,8 @@ namespace FlashTools.Internal {
public Material Material;
}
static SwfAnimationClipAsset.Frame BakeClipFrame(
SwfAnimationAsset asset, SwfAnimationFrameData frame)
static SwfClipAsset.Frame BakeClipFrame(
SwfAsset asset, SwfAnimationFrameData frame)
{
List<Vector2> baked_uvs = new List<Vector2>();
List<Color> baked_mulcolors = new List<Color>();
@@ -321,7 +321,7 @@ namespace FlashTools.Internal {
mesh.SetColors(baked_mulcolors);
mesh.RecalculateNormals();
return new SwfAnimationClipAsset.Frame{
return new SwfClipAsset.Frame{
Mesh = mesh,
Materials = baked_materials.ToArray()};
}
@@ -338,15 +338,15 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
//
// ConfigureAssetAnimations
// ConfigureAssetClips
//
// ---------------------------------------------------------------------
static void ConfigureAssetAnimations(SwfAnimationAsset asset) {
var animations = GameObject.FindObjectsOfType<SwfAnimation>();
foreach ( var animation in animations ) {
if ( animation && animation.clip && asset.Clips.Contains(animation.clip) ) {
animation.UpdateAllProperties();
static void ConfigureAssetClips(SwfAsset asset) {
var clips = GameObject.FindObjectsOfType<SwfClip>();
foreach ( var clip in clips ) {
if ( clip && clip.clip && asset.Clips.Contains(clip.clip) ) {
clip.UpdateAllProperties();
}
}
}
@@ -7,17 +7,17 @@ using System.Linq;
using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfAnimationClipAsset)), CanEditMultipleObjects]
public class SwfAnimationClipAssetEditor : Editor {
List<SwfAnimationClipAsset> _clips = new List<SwfAnimationClipAsset>();
[CustomEditor(typeof(SwfClipAsset)), CanEditMultipleObjects]
public class SwfClipAssetEditor : Editor {
List<SwfClipAsset> _clips = new List<SwfClipAsset>();
static string GetClipPath(SwfAnimationClipAsset clip) {
static string GetClipPath(SwfClipAsset clip) {
return clip
? AssetDatabase.GetAssetPath(clip)
: string.Empty;
}
static string GetPrefabPath(SwfAnimationClipAsset clip) {
static string GetPrefabPath(SwfClipAsset clip) {
var clip_path = GetClipPath(clip);
return string.IsNullOrEmpty(clip_path)
? string.Empty
@@ -28,21 +28,21 @@ namespace FlashTools.Internal {
//
//
static GameObject CreateAnimationGO(SwfAnimationClipAsset clip) {
static GameObject CreateClipGO(SwfClipAsset clip) {
if ( clip ) {
var anim_go = new GameObject(clip.name);
anim_go.AddComponent<MeshFilter>();
anim_go.AddComponent<MeshRenderer>();
anim_go.AddComponent<SwfAnimation>().clip = clip;
anim_go.AddComponent<SwfAnimationController>();
return anim_go;
var clip_go = new GameObject(clip.name);
clip_go.AddComponent<MeshFilter>();
clip_go.AddComponent<MeshRenderer>();
clip_go.AddComponent<SwfClip>().clip = clip;
clip_go.AddComponent<SwfClipController>();
return clip_go;
}
return null;
}
static void CreateClipPrefab(SwfAnimationClipAsset clip) {
var anim_go = CreateAnimationGO(clip);
if ( anim_go ) {
static void CreateClipPrefab(SwfClipAsset clip) {
var clip_go = CreateClipGO(clip);
if ( clip_go ) {
var prefab_path = GetPrefabPath(clip);
if ( !string.IsNullOrEmpty(prefab_path) ) {
var prefab = AssetDatabase.LoadMainAssetAtPath(prefab_path);
@@ -50,18 +50,18 @@ namespace FlashTools.Internal {
prefab = PrefabUtility.CreateEmptyPrefab(prefab_path);
}
PrefabUtility.ReplacePrefab(
anim_go,
clip_go,
prefab,
ReplacePrefabOptions.ConnectToPrefab);
}
GameObject.DestroyImmediate(anim_go, true);
GameObject.DestroyImmediate(clip_go, true);
}
}
static void CreateClipOnScene(SwfAnimationClipAsset clip) {
var anim_go = CreateAnimationGO(clip);
if ( anim_go ) {
Undo.RegisterCreatedObjectUndo(anim_go, "Instance SwfAnimation");
static void CreateClipOnScene(SwfClipAsset clip) {
var clip_go = CreateClipGO(clip);
if ( clip_go ) {
Undo.RegisterCreatedObjectUndo(clip_go, "Instance SwfClip");
}
}
@@ -69,7 +69,7 @@ namespace FlashTools.Internal {
//
//
void AllClipsForeach(Action<SwfAnimationClipAsset> act) {
void AllClipsForeach(Action<SwfClipAsset> act) {
foreach ( var clip in _clips ) {
act(clip);
}
@@ -129,7 +129,7 @@ namespace FlashTools.Internal {
void OnEnable() {
_clips = targets
.OfType<SwfAnimationClipAsset>()
.OfType<SwfClipAsset>()
.ToList();
}
@@ -6,17 +6,17 @@ using System.Linq;
using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfAnimationController)), CanEditMultipleObjects]
public class SwfAnimationControllerEditor : Editor {
List<SwfAnimationController> _controllers = new List<SwfAnimationController>();
[CustomEditor(typeof(SwfClipController)), CanEditMultipleObjects]
public class SwfClipControllerEditor : Editor {
List<SwfClipController> _controllers = new List<SwfClipController>();
void AllControllersForeach(Action<SwfAnimationController> act) {
void AllControllersForeach(Action<SwfClipController> act) {
foreach ( var controller in _controllers ) {
act(controller);
}
}
void DrawAnimationControls() {
void DrawClipControls() {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
@@ -44,7 +44,7 @@ namespace FlashTools.Internal {
void OnEnable() {
_controllers = targets
.OfType<SwfAnimationController>()
.OfType<SwfClipController>()
.ToList();
}
@@ -52,7 +52,7 @@ namespace FlashTools.Internal {
serializedObject.Update();
DrawDefaultInspector();
if ( Application.isPlaying ) {
DrawAnimationControls();
DrawClipControls();
}
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();
@@ -6,29 +6,29 @@ using System.Linq;
using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfAnimation)), CanEditMultipleObjects]
public class SwfAnimationEditor : Editor {
List<SwfAnimation> _animations = new List<SwfAnimation>();
[CustomEditor(typeof(SwfClip)), CanEditMultipleObjects]
public class SwfClipEditor : Editor {
List<SwfClip> _clips = new List<SwfClip>();
void AllAnimationsForeachWithUndo(Action<SwfAnimation> act) {
void AllClipsForeachWithUndo(Action<SwfClip> act) {
Undo.RecordObjects(
_animations.ToArray(),
_clips.ToArray(),
"Inspector");
foreach ( var animation in _animations ) {
act(animation);
EditorUtility.SetDirty(animation);
foreach ( var clip in _clips ) {
act(clip);
EditorUtility.SetDirty(clip);
}
}
int GetMinAnimationsFrameCount() {
return _animations.Count > 0
? _animations.Min(anim => anim.frameCount)
int GetMinClipsFrameCount() {
return _clips.Count > 0
? _clips.Min(clip => clip.frameCount)
: 0;
}
string GetAnimationsFrameCountStr() {
return _animations.Aggregate(string.Empty, (acc, anim) => {
var frame_count = anim.frameCount > 0 ? anim.frameCount - 1 : 0;
string GetClipsFrameCountStr() {
return _clips.Aggregate(string.Empty, (acc, clip) => {
var frame_count = clip.frameCount > 0 ? clip.frameCount - 1 : 0;
var frame_count_str = frame_count.ToString();
return string.IsNullOrEmpty(acc)
? frame_count_str
@@ -36,9 +36,9 @@ namespace FlashTools.Internal {
});
}
string GetAnimationsCurrentFrameStr() {
return _animations.Aggregate(string.Empty, (acc, anim) => {
var current_frame = anim.currentFrame;
string GetClipsCurrentFrameStr() {
return _clips.Aggregate(string.Empty, (acc, clip) => {
var current_frame = clip.currentFrame;
var current_frame_str = current_frame.ToString();
return string.IsNullOrEmpty(acc)
? current_frame_str
@@ -46,12 +46,12 @@ namespace FlashTools.Internal {
});
}
bool IsAllAnimationsHasOneClip() {
foreach ( var animation in _animations ) {
if ( !animation.clip ) {
bool IsAllClipsHasOneClip() {
foreach ( var clip in _clips ) {
if ( !clip.clip ) {
return false;
}
if ( animation.clip != _animations.First().clip ) {
if ( clip.clip != _clips.First().clip ) {
return false;
}
}
@@ -59,7 +59,7 @@ namespace FlashTools.Internal {
}
List<string> GetAllSequences(bool include_empty) {
var seq_set = new HashSet<string>(_animations
var seq_set = new HashSet<string>(_clips
.Where(p => p.clip)
.SelectMany(p => p.clip.Sequences)
.Select(p => p.Name));
@@ -70,7 +70,7 @@ namespace FlashTools.Internal {
}
void DrawSequence() {
if ( IsAllAnimationsHasOneClip() ) {
if ( IsAllClipsHasOneClip() ) {
var sequence_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "_sequence");
SwfEditorUtils.DoWithMixedValue(
sequence_prop.hasMultipleDifferentValues, () => {
@@ -94,36 +94,36 @@ namespace FlashTools.Internal {
}
void DrawCurrentFrame() {
var min_frame_count = GetMinAnimationsFrameCount();
var min_frame_count = GetMinClipsFrameCount();
if ( min_frame_count > 1 ) {
EditorGUILayout.IntSlider(
SwfEditorUtils.GetPropertyByName(serializedObject, "_currentFrame"),
0,
min_frame_count - 1,
"Current frame");
DrawAnimationControls();
DrawClipControls();
}
}
void DrawAnimationControls() {
void DrawClipControls() {
EditorGUILayout.Space();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
if ( GUILayout.Button(new GUIContent("<<", "to begin frame")) ) {
AllAnimationsForeachWithUndo(p => p.ToBeginFrame());
AllClipsForeachWithUndo(p => p.ToBeginFrame());
}
if ( GUILayout.Button(new GUIContent("<", "to prev frame")) ) {
AllAnimationsForeachWithUndo(p => p.ToPrevFrame());
AllClipsForeachWithUndo(p => p.ToPrevFrame());
}
GUILayout.Label(string.Format(
"{0}/{1}",
GetAnimationsCurrentFrameStr(), GetAnimationsFrameCountStr()));
GetClipsCurrentFrameStr(), GetClipsFrameCountStr()));
if ( GUILayout.Button(new GUIContent(">", "to next frame")) ) {
AllAnimationsForeachWithUndo(p => p.ToNextFrame());
AllClipsForeachWithUndo(p => p.ToNextFrame());
}
if ( GUILayout.Button(new GUIContent(">>", "to end frame")) ) {
AllAnimationsForeachWithUndo(p => p.ToEndFrame());
AllClipsForeachWithUndo(p => p.ToEndFrame());
}
}
GUILayout.FlexibleSpace();
@@ -137,8 +137,8 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
void OnEnable() {
_animations = targets
.OfType<SwfAnimation>()
_clips = targets
.OfType<SwfClip>()
.ToList();
}
@@ -30,7 +30,7 @@ namespace FlashTools.Internal {
return prop;
}
public static void DeleteAnimationAssetWithDepends(SwfAnimationAsset asset) {
public static void DeleteAssetWithDepends(SwfAsset asset) {
if ( asset ) {
if ( asset.Atlas ) {
AssetDatabase.DeleteAsset(
@@ -9,8 +9,8 @@ namespace FlashTools.Internal {
void DrawAnimationCount() {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
EditorGUILayout.IntField(
"Animation count",
_manager.AllAnimationCount);
"Clip count",
_manager.AllClipCount);
});
}
@@ -26,27 +26,27 @@ namespace FlashTools.Internal {
static void SwfAssetProcess(string swf_asset) {
var new_asset_path = SwfEditorUtils.GetSettingsPathFromSwfPath(swf_asset);
var new_asset = AssetDatabase.LoadAssetAtPath<SwfAnimationAsset>(new_asset_path);
var new_asset = AssetDatabase.LoadAssetAtPath<SwfAsset>(new_asset_path);
if ( !new_asset ) {
new_asset = ScriptableObject.CreateInstance<SwfAnimationAsset>();
new_asset = ScriptableObject.CreateInstance<SwfAsset>();
AssetDatabase.CreateAsset(new_asset, new_asset_path);
}
if ( LoadDataFromSwfFile(swf_asset, new_asset) ) {
EditorUtility.SetDirty(new_asset);
AssetDatabase.SaveAssets();
} else {
SwfEditorUtils.DeleteAnimationAssetWithDepends(new_asset);
SwfEditorUtils.DeleteAssetWithDepends(new_asset);
}
}
static bool LoadDataFromSwfFile(string swf_asset, SwfAnimationAsset asset) {
static bool LoadDataFromSwfFile(string swf_asset, SwfAsset asset) {
try {
if ( asset.Atlas ) {
AssetDatabase.DeleteAsset(
AssetDatabase.GetAssetPath(asset.Atlas));
asset.Atlas = null;
}
asset.Data = LoadAnimationDataFromSwfDecoder(
asset.Data = LoadDataFromSwfDecoder(
swf_asset,
asset,
new SwfDecoder(swf_asset));
@@ -57,28 +57,28 @@ namespace FlashTools.Internal {
}
}
static SwfAnimationData LoadAnimationDataFromSwfDecoder(
string swf_asset, SwfAnimationAsset asset, SwfDecoder decoder)
static SwfAnimationData LoadDataFromSwfDecoder(
string swf_asset, SwfAsset asset, SwfDecoder decoder)
{
var library = new SwfLibrary();
return new SwfAnimationData{
FrameRate = decoder.UncompressedHeader.FrameRate,
Symbols = LoadAnimationSymbols(library, decoder),
Bitmaps = LoadAnimationBitmaps(swf_asset, asset.Settings, library)};
Symbols = LoadSymbols(library, decoder),
Bitmaps = LoadBitmaps(swf_asset, asset.Settings, library)};
}
static List<SwfAnimationSymbolData> LoadAnimationSymbols(
static List<SwfAnimationSymbolData> LoadSymbols(
SwfLibrary library, SwfDecoder decoder)
{
var symbols = new List<SwfAnimationSymbolData>();
symbols.Add(LoadAnimationSymbol(0, "_Stage", library, decoder.Tags));
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));
foreach ( var sprite_def in sprite_defs ) {
symbols.Add(LoadAnimationSymbol(
symbols.Add(LoadSymbol(
sprite_def.Key,
sprite_def.Value.ExportName,
library,
@@ -87,14 +87,14 @@ namespace FlashTools.Internal {
return symbols;
}
static SwfAnimationSymbolData LoadAnimationSymbol(
static SwfAnimationSymbolData LoadSymbol(
int symbol_id, 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>();
while ( executer.NextFrame(tags, disp_lst) ) {
symbol_frames.Add(LoadAnimationSymbolFrame(library, disp_lst));
symbol_frames.Add(LoadSymbolFrame(library, disp_lst));
}
return new SwfAnimationSymbolData{
Id = symbol_id,
@@ -102,7 +102,7 @@ namespace FlashTools.Internal {
Frames = symbol_frames};
}
static SwfAnimationFrameData LoadAnimationSymbolFrame(
static SwfAnimationFrameData LoadSymbolFrame(
SwfLibrary library, SwfDisplayList display_list)
{
var frame = new SwfAnimationFrameData();
@@ -209,7 +209,7 @@ namespace FlashTools.Internal {
masks.RemoveAll(p => p.ClipDepth < depth);
}
static List<SwfAnimationBitmapData> LoadAnimationBitmaps(
static List<SwfAnimationBitmapData> LoadBitmaps(
string swf_asset, SwfSettings settings, SwfLibrary library)
{
var bitmap_defines = library.Defines
@@ -1,29 +0,0 @@
using UnityEngine;
using FlashTools.Internal;
using System.Collections.Generic;
namespace FlashTools {
public class SwfAnimationClipAsset : ScriptableObject {
[System.Serializable]
public class Frame {
public Mesh Mesh = new Mesh();
public Material[] Materials = new Material[0];
}
[System.Serializable]
public class Sequence {
public string Name = string.Empty;
public List<Frame> Frames = new List<Frame>();
}
public Texture2D Atlas;
public float FrameRate;
public List<Sequence> Sequences;
#if UNITY_EDITOR
void Reset() {
Atlas = null;
FrameRate = 1.0f;
Sequences = new List<Sequence>();
}
#endif
}
}
@@ -76,18 +76,18 @@ namespace FlashTools {
public List<SwfAnimationBitmapData> Bitmaps = new List<SwfAnimationBitmapData>();
}
public class SwfAnimationAsset : ScriptableObject {
public SwfAnimationData Data;
public Texture2D Atlas;
public List<SwfAnimationClipAsset> Clips;
public SwfSettings Settings;
public SwfSettings Overridden;
public class SwfAsset : ScriptableObject {
public SwfAnimationData Data;
public Texture2D Atlas;
public List<SwfClipAsset> Clips;
public SwfSettings Settings;
public SwfSettings Overridden;
#if UNITY_EDITOR
void Reset() {
Data = new SwfAnimationData();
Atlas = null;
Clips = new List<SwfAnimationClipAsset>();
Clips = new List<SwfClipAsset>();
Settings = SwfConverterSettings.GetDefaultSettings();
Overridden = SwfConverterSettings.GetDefaultSettings();
}
@@ -4,13 +4,13 @@ using FlashTools.Internal;
namespace FlashTools {
[ExecuteInEditMode, DisallowMultipleComponent]
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class SwfAnimation : MonoBehaviour {
public class SwfClip : MonoBehaviour {
MeshFilter _meshFilter = null;
MeshRenderer _meshRenderer = null;
MeshFilter _meshFilter = null;
MeshRenderer _meshRenderer = null;
SwfAnimationClipAsset.Sequence _curSequence = null;
MaterialPropertyBlock _curPropBlock = null;
SwfClipAsset.Sequence _curSequence = null;
MaterialPropertyBlock _curPropBlock = null;
// ---------------------------------------------------------------------
//
@@ -41,8 +41,8 @@ namespace FlashTools {
[Header("Animation")]
[SerializeField]
SwfAnimationClipAsset _clip = null;
public SwfAnimationClipAsset clip {
SwfClipAsset _clip = null;
public SwfClipAsset clip {
get { return _clip; }
set {
_clip = value;
@@ -195,11 +195,11 @@ namespace FlashTools {
}
}
SwfAnimationClipAsset.Frame GetCurrentBakedFrame() {
SwfClipAsset.Frame GetCurrentBakedFrame() {
var frames = _curSequence != null ? _curSequence.Frames : null;
return frames != null && currentFrame >= 0 && currentFrame < frames.Count
? frames[currentFrame]
: new SwfAnimationClipAsset.Frame();
: new SwfClipAsset.Frame();
}
// ---------------------------------------------------------------------
@@ -219,14 +219,14 @@ namespace FlashTools {
void OnEnable() {
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfAnimation(this);
swf_manager.AddSwfClip(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfAnimation(this);
swf_manager.RemoveSwfClip(this);
}
}
+29
View File
@@ -0,0 +1,29 @@
using UnityEngine;
using FlashTools.Internal;
using System.Collections.Generic;
namespace FlashTools {
public class SwfClipAsset : ScriptableObject {
[System.Serializable]
public class Frame {
public Mesh Mesh = new Mesh();
public Material[] Materials = new Material[0];
}
[System.Serializable]
public class Sequence {
public string Name = string.Empty;
public List<Frame> Frames = new List<Frame>();
}
public Texture2D Atlas;
public float FrameRate;
public List<Sequence> Sequences;
#if UNITY_EDITOR
void Reset() {
Atlas = null;
FrameRate = 1.0f;
Sequences = new List<Sequence>();
}
#endif
}
}
@@ -4,11 +4,11 @@ using System;
namespace FlashTools {
[ExecuteInEditMode, DisallowMultipleComponent]
[RequireComponent(typeof(SwfAnimation))]
public class SwfAnimationController : MonoBehaviour {
[RequireComponent(typeof(SwfClip))]
public class SwfClipController : MonoBehaviour {
SwfAnimation _animation = null;
float _frameTimer = 0.0f;
SwfClip _clip = null;
float _frameTimer = 0.0f;
// ---------------------------------------------------------------------
//
@@ -16,11 +16,11 @@ namespace FlashTools {
//
// ---------------------------------------------------------------------
public event Action<SwfAnimationController> OnStopPlayingEvent;
public event Action<SwfAnimationController> OnRewindPlayingEvent;
public event Action<SwfClipController> OnStopPlayingEvent;
public event Action<SwfClipController> OnRewindPlayingEvent;
public event Action<SwfAnimationController> OnPausePlayingEvent;
public event Action<SwfAnimationController> OnResumePausedEvent;
public event Action<SwfClipController> OnPausePlayingEvent;
public event Action<SwfClipController> OnResumePausedEvent;
// ---------------------------------------------------------------------
//
@@ -139,14 +139,14 @@ namespace FlashTools {
public void Rewind() {
switch ( playMode ) {
case PlayModes.Forward:
_animation.ToBeginFrame();
_clip.ToBeginFrame();
break;
case PlayModes.Backward:
_animation.ToEndFrame();
_clip.ToEndFrame();
break;
default:
throw new UnityException(string.Format(
"SwfAnimationController. Incorrect play mode: {0}",
"SwfClipController. Incorrect play mode: {0}",
playMode));
}
if ( isPlaying && OnRewindPlayingEvent != null ) {
@@ -162,20 +162,20 @@ namespace FlashTools {
public void InternalUpdate(float dt) {
if ( isPlaying ) {
UpdateAnimationTimer(dt);
UpdateFrameTimer(dt);
}
}
void UpdateAnimationTimer(float dt) {
_frameTimer += _animation.frameRate * rateScale * dt;
void UpdateFrameTimer(float dt) {
_frameTimer += _clip.frameRate * rateScale * dt;
while ( _frameTimer > 1.0f ) {
_frameTimer -= 1.0f;
AnimationTimerTick();
FrameTimerTick();
}
}
void AnimationTimerTick() {
if ( !NextAnimationFrame() ) {
void FrameTimerTick() {
if ( !NextClipFrame() ) {
switch ( loopMode ) {
case LoopModes.Once:
Stop(false);
@@ -185,21 +185,21 @@ namespace FlashTools {
break;
default:
throw new UnityException(string.Format(
"SwfAnimationController. Incorrect loop mode: {0}",
"SwfClipController. Incorrect loop mode: {0}",
loopMode));
}
}
}
bool NextAnimationFrame() {
bool NextClipFrame() {
switch ( playMode ) {
case PlayModes.Forward:
return _animation.ToNextFrame();
return _clip.ToNextFrame();
case PlayModes.Backward:
return _animation.ToPrevFrame();
return _clip.ToPrevFrame();
default:
throw new UnityException(string.Format(
"SwfAnimationController. Incorrect play mode: {0}",
"SwfClipController. Incorrect play mode: {0}",
playMode));
}
}
@@ -211,7 +211,7 @@ namespace FlashTools {
// ---------------------------------------------------------------------
void Awake() {
_animation = GetComponent<SwfAnimation>();
_clip = GetComponent<SwfClip>();
if ( autoPlay ) {
Play();
}
@@ -220,14 +220,14 @@ namespace FlashTools {
void OnEnable() {
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfAnimationController(this);
swf_manager.AddSwfClipController(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfAnimationController(this);
swf_manager.RemoveSwfClipController(this);
}
}
}
+22 -22
View File
@@ -5,8 +5,8 @@ namespace FlashTools {
[ExecuteInEditMode, DisallowMultipleComponent]
public class SwfManager : MonoBehaviour {
HashSet<SwfAnimation> _animations = new HashSet<SwfAnimation>();
HashSet<SwfAnimationController> _controllers = new HashSet<SwfAnimationController>();
HashSet<SwfClip> _clips = new HashSet<SwfClip>();
HashSet<SwfClipController> _controllers = new HashSet<SwfClipController>();
// ---------------------------------------------------------------------
//
@@ -32,27 +32,27 @@ namespace FlashTools {
//
// ---------------------------------------------------------------------
public int AllAnimationCount {
get { return _animations.Count; }
public int AllClipCount {
get { return _clips.Count; }
}
public void AddSwfAnimation(SwfAnimation animation) {
_animations.Add(animation);
public void AddSwfClip(SwfClip clip) {
_clips.Add(clip);
}
public void RemoveSwfAnimation(SwfAnimation animation) {
_animations.Remove(animation);
public void RemoveSwfClip(SwfClip clip) {
_clips.Remove(clip);
}
public int AllAnimationControllerCount {
public int AllClipControllerCount {
get { return _controllers.Count; }
}
public void AddSwfAnimationController(SwfAnimationController controller) {
public void AddSwfClipController(SwfClipController controller) {
_controllers.Add(controller);
}
public void RemoveSwfAnimationController(SwfAnimationController controller) {
public void RemoveSwfClipController(SwfClipController controller) {
_controllers.Remove(controller);
}
@@ -62,18 +62,18 @@ namespace FlashTools {
//
// ---------------------------------------------------------------------
void GrabEnabledAnimations() {
var all_animations = FindObjectsOfType<SwfAnimation>();
for ( int i = 0, e = all_animations.Length; i < e; ++i ) {
var animation = all_animations[i];
if ( animation.enabled ) {
_animations.Add(animation);
void GrabEnabledClips() {
var all_clips = FindObjectsOfType<SwfClip>();
for ( int i = 0, e = all_clips.Length; i < e; ++i ) {
var clip = all_clips[i];
if ( clip.enabled ) {
_clips.Add(clip);
}
}
}
void GrabEnabledControllers() {
var all_controllers = FindObjectsOfType<SwfAnimationController>();
var all_controllers = FindObjectsOfType<SwfClipController>();
for ( int i = 0, e = all_controllers.Length; i < e; ++i ) {
var controller = all_controllers[i];
if ( controller.enabled ) {
@@ -82,8 +82,8 @@ namespace FlashTools {
}
}
void DropAnimations() {
_animations.Clear();
void DropClips() {
_clips.Clear();
}
void DropControllers() {
@@ -105,12 +105,12 @@ namespace FlashTools {
// ---------------------------------------------------------------------
void OnEnable() {
GrabEnabledAnimations();
GrabEnabledClips();
GrabEnabledControllers();
}
void OnDisable() {
DropAnimations();
DropClips();
DropControllers();
}