separate clips wip

This commit is contained in:
2016-09-01 23:45:45 +07:00
parent 15ff6b8da6
commit 274f1c2c00
8 changed files with 51 additions and 49 deletions
@@ -54,9 +54,7 @@ namespace FlashTools.Internal {
}
static void ReconvertAnimationAsset(SwfAnimationAsset asset) {
AssetDatabase.ImportAsset(
GetSwfPath(asset),
ImportAssetOptions.ForceUpdate);
AssetDatabase.ImportAsset(GetSwfPath(asset));
}
//
@@ -73,8 +73,7 @@ namespace FlashTools.Internal {
atlas_importer.filterMode = SwfAtlasFilterToImporterFilter(asset.Settings.AtlasTextureFilter);
atlas_importer.textureFormat = SwfAtlasFormatToImporterFormat(asset.Settings.AtlasTextureFormat);
AssetDatabase.ImportAsset(
SwfEditorUtils.GetAtlasPathFromSettingsPath(asset_path),
ImportAssetOptions.ForceUpdate);
SwfEditorUtils.GetAtlasPathFromSettingsPath(asset_path));
}
static TextureImporter GetBitmapsAtlasImporter(string asset_path) {
@@ -150,9 +149,11 @@ namespace FlashTools.Internal {
static void ConfigureClip(
string asset_path,
SwfAnimationAsset asset, SwfAnimationSymbolData symbol)
SwfAnimationAsset asset,
SwfAnimationSymbolData symbol)
{
var clip_asset_path = Path.ChangeExtension(asset_path, symbol.Id.ToString() + ".asset");
var clip_asset_path = SwfEditorUtils.GetClipPathFromSettingsPath(
asset_path, symbol.Name);
var clip_asset = AssetDatabase.LoadAssetAtPath<SwfAnimationClipAsset>(clip_asset_path);
if ( !clip_asset ) {
clip_asset = ScriptableObject.CreateInstance<SwfAnimationClipAsset>();
@@ -229,15 +230,7 @@ namespace FlashTools.Internal {
var v2 = new Vector3(width, height, 0);
var v3 = new Vector3( 0, height, 0);
var frame_offset = Matrix4x4.TRS(
new Vector2(
-asset.Data.FrameSize.x * 0.5f / asset.Settings.PixelsPerUnit,
+asset.Data.FrameSize.y * 0.5f / asset.Settings.PixelsPerUnit),
Quaternion.identity,
Vector3.one);
var matrix =
frame_offset *
Matrix4x4.Scale(new Vector3(
+1.0f / asset.Settings.PixelsPerUnit,
-1.0f / asset.Settings.PixelsPerUnit,
@@ -51,23 +51,23 @@ namespace FlashTools.Internal {
}
public static string GetSwfPathFromSettingsPath(string settings_path) {
return Path.ChangeExtension(
Path.Combine(
Path.GetDirectoryName(settings_path),
Path.GetFileNameWithoutExtension(settings_path)),
".swf");
return Path.ChangeExtension(settings_path, ".swf");
}
public static string GetAtlasPathFromSwfPath(string swf_path) {
return Path.ChangeExtension(swf_path, ".settings.png");
return Path.ChangeExtension(swf_path, "._Atlas.png");
}
public static string GetAtlasPathFromSettingsPath(string settings_path) {
return Path.ChangeExtension(settings_path, ".png");
return Path.ChangeExtension(settings_path, "._Atlas.png");
}
public static string GetSettingsPathFromSwfPath(string swf_path) {
return Path.ChangeExtension(swf_path, ".settings.asset");
return Path.ChangeExtension(swf_path, ".asset");
}
public static string GetClipPathFromSettingsPath(string settings_path, string clip_name) {
return Path.ChangeExtension(settings_path, clip_name + ".asset");
}
}
}
@@ -63,7 +63,6 @@ namespace FlashTools.Internal {
var library = new SwfLibrary();
return new SwfAnimationData{
FrameRate = decoder.UncompressedHeader.FrameRate,
FrameSize = decoder.UncompressedHeader.FrameSize.ToUnityVectorSize(),
Symbols = LoadAnimationSymbols(library, decoder),
Bitmaps = LoadAnimationBitmaps(swf_asset, asset.Settings, library)};
}
@@ -72,12 +71,24 @@ namespace FlashTools.Internal {
SwfLibrary library, SwfDecoder decoder)
{
var symbols = new List<SwfAnimationSymbolData>();
symbols.Add(LoadAnimationSymbol(0, library, decoder.Tags));
symbols.Add(LoadAnimationSymbol(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(
sprite_def.Key,
sprite_def.Value.ExportName,
library,
sprite_def.Value.ControlTags.Tags));
}
return symbols;
}
static SwfAnimationSymbolData LoadAnimationSymbol(
int symbol_id, SwfLibrary library, List<SwfTagBase> tags)
int symbol_id, string symbol_name, SwfLibrary library, List<SwfTagBase> tags)
{
var disp_lst = new SwfDisplayList();
var executer = new SwfContextExecuter(library, 0);
@@ -87,6 +98,7 @@ namespace FlashTools.Internal {
}
return new SwfAnimationSymbolData{
Id = symbol_id,
Name = symbol_name,
Frames = symbol_frames};
}
@@ -202,15 +214,14 @@ namespace FlashTools.Internal {
{
var bitmap_defines = library.Defines
.Where (p => p.Value.Type == SwfLibraryDefineType.Bitmap)
.Select (p => new KeyValuePair<int, SwfLibraryBitmapDefine>(p.Key, p.Value as SwfLibraryBitmapDefine))
.Select (p => new KeyValuePair<int, SwfLibraryBitmapDefine>(
p.Key, p.Value as SwfLibraryBitmapDefine))
.ToArray();
var textures = bitmap_defines
.Select (p => LoadTextureFromBitmapDefine(p.Value))
.ToArray();
var rects = PackAndSaveBitmapsAtlas(
swf_asset,
textures,
settings);
swf_asset, textures, settings);
var bitmaps = new List<SwfAnimationBitmapData>(bitmap_defines.Length);
for ( var i = 0; i < bitmap_defines.Length; ++i ) {
var bitmap_define = bitmap_defines[i];
@@ -253,24 +264,17 @@ namespace FlashTools.Internal {
}
static Rect[] PackAndSaveBitmapsAtlas(
string swf_asset,
Texture2D[] textures,
SwfSettings settings)
string swf_asset, Texture2D[] textures, SwfSettings settings)
{
var atlas_info = PackBitmapsAtlas(textures, settings);
File.WriteAllBytes(
SwfEditorUtils.GetAtlasPathFromSwfPath(swf_asset),
atlas_info.Atlas.EncodeToPNG());
var atlas_path = SwfEditorUtils.GetAtlasPathFromSwfPath(swf_asset);
File.WriteAllBytes(atlas_path, atlas_info.Atlas.EncodeToPNG());
GameObject.DestroyImmediate(atlas_info.Atlas, true);
AssetDatabase.ImportAsset(
SwfEditorUtils.GetAtlasPathFromSwfPath(swf_asset));
AssetDatabase.ImportAsset(atlas_path);
return atlas_info.Rects;
}
static BitmapsAtlasInfo PackBitmapsAtlas(
Texture2D[] textures,
SwfSettings settings)
{
static BitmapsAtlasInfo PackBitmapsAtlas(Texture2D[] textures, SwfSettings settings) {
var atlas_padding = Mathf.Max(0, settings.AtlasPadding);
var max_atlas_size = Mathf.Max(32, settings.AtlasPowerOfTwo
? Mathf.ClosestPowerOfTwo(settings.MaxAtlasSize)
@@ -17,6 +17,7 @@ namespace FlashTools.Internal.SwfTools {
}
public abstract class SwfLibraryDefine {
public string ExportName = string.Empty;
public abstract SwfLibraryDefineType Type { get; }
}
@@ -175,10 +175,22 @@ namespace FlashTools.Internal.SwfTools {
}
public SwfDisplayList Visit(ExportAssetsTag tag, SwfDisplayList dl) {
foreach ( var asset_tag in tag.AssetTags ) {
var define = Library.FindDefine<SwfLibraryDefine>(asset_tag.Tag);
if ( define != null ) {
define.ExportName = asset_tag.Name.Trim();
}
}
return dl;
}
public SwfDisplayList Visit(SymbolClassTag tag, SwfDisplayList dl) {
foreach ( var symbol_tag in tag.SymbolTags ) {
var define = Library.FindDefine<SwfLibraryDefine>(symbol_tag.Tag);
if ( define != null ) {
define.ExportName = symbol_tag.Name.Trim();
}
}
return dl;
}
@@ -43,11 +43,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
XMin, YMin,
XMax, YMax);
}
public Vector2 ToUnityVectorSize() {
return new Vector2(
Mathf.Abs(XMax - XMin),
Mathf.Abs(YMax - YMin));
}
}
}
@@ -58,6 +58,7 @@ namespace FlashTools {
[System.Serializable]
public class SwfAnimationSymbolData {
public int Id = 0;
public string Name = string.Empty;
public List<SwfAnimationFrameData> Frames = new List<SwfAnimationFrameData>();
}
@@ -71,7 +72,6 @@ namespace FlashTools {
[System.Serializable]
public class SwfAnimationData {
public float FrameRate = 0.0f;
public Vector2 FrameSize = Vector2.zero;
public List<SwfAnimationSymbolData> Symbols = new List<SwfAnimationSymbolData>();
public List<SwfAnimationBitmapData> Bitmaps = new List<SwfAnimationBitmapData>();
}