mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-14 20:21:27 +07:00
very dirty experiment for render flash anim data
This commit is contained in:
Binary file not shown.
@@ -145,7 +145,7 @@ Camera:
|
||||
far clip plane: 1000
|
||||
field of view: 60
|
||||
orthographic: 1
|
||||
orthographic size: 5
|
||||
orthographic size: 256
|
||||
m_Depth: -1
|
||||
m_CullingMask:
|
||||
serializedVersion: 2
|
||||
@@ -166,7 +166,7 @@ Transform:
|
||||
m_PrefabInternal: {fileID: 0}
|
||||
m_GameObject: {fileID: 1173114888}
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: -10}
|
||||
m_LocalPosition: {x: 500, y: -400, z: -10}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
|
||||
@@ -1,6 +1,160 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools {
|
||||
[ExecuteInEditMode]
|
||||
public class FlashAnim : MonoBehaviour {
|
||||
public FlashAnimAsset Asset = null;
|
||||
|
||||
int _current_frame = 0;
|
||||
float _frame_timer = 0.0f;
|
||||
|
||||
List<Vector3> _vertices = new List<Vector3>();
|
||||
List<int> _triangles = new List<int>();
|
||||
List<Vector2> _uvs = new List<Vector2>();
|
||||
|
||||
public void Play() {
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
}
|
||||
|
||||
public void Pause() {
|
||||
}
|
||||
|
||||
public void GoToFrame(int frame) {
|
||||
}
|
||||
|
||||
public int frameCount {
|
||||
get {
|
||||
int frames = 0;
|
||||
if ( Asset ) {
|
||||
foreach ( var layer in GetCurrentSymbol().Layers ) {
|
||||
frames = Mathf.Max(frames, layer.Frames.Count);
|
||||
}
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
}
|
||||
|
||||
FlashAnimSymbolData GetCurrentSymbol() {
|
||||
//return Asset.Data.Library.Symbols[0];
|
||||
return Asset.Data.Stage;
|
||||
}
|
||||
|
||||
int GetNumFrameByNum(FlashAnimLayerData layer, int num) {
|
||||
return num % layer.Frames.Count;
|
||||
}
|
||||
|
||||
FlashAnimFrameData GetFrameByNum(FlashAnimLayerData layer, int num) {
|
||||
var frame_num = GetNumFrameByNum(layer, num);
|
||||
if ( frame_num >= 0 && frame_num < layer.Frames.Count ) {
|
||||
return layer.Frames[frame_num];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FlashAnimSymbolData FindSymbol(FlashAnimLibraryData library, string symbol_id) {
|
||||
foreach ( var symbol in library.Symbols ) {
|
||||
if ( symbol.Id == symbol_id ) {
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
FlashAnimBitmapData FindBitmap(FlashAnimLibraryData library, string bitmap_id) {
|
||||
foreach ( var bitmap in library.Bitmaps ) {
|
||||
if ( bitmap.Id == bitmap_id ) {
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void RenderInstance(FlashAnimInstData elem_data, int frame_num, Matrix4x4 matrix) {
|
||||
if ( elem_data.Type == FlashAnimInstType.Bitmap ) {
|
||||
var bitmap = Asset ? FindBitmap(Asset.Data.Library, elem_data.Asset) : null;
|
||||
if ( bitmap != null ) {
|
||||
var width = bitmap.RealSize.x;
|
||||
var height = bitmap.RealSize.y;
|
||||
|
||||
var v0 = new Vector3( 0, 0, 0);
|
||||
var v1 = new Vector3( width, 0, 0);
|
||||
var v2 = new Vector3( width, height, 0);
|
||||
var v3 = new Vector3( 0, height, 0);
|
||||
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v0));
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v1));
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v2));
|
||||
_vertices.Add(matrix.MultiplyPoint3x4(v3));
|
||||
|
||||
_triangles.Add(_vertices.Count - 4 + 2);
|
||||
_triangles.Add(_vertices.Count - 4 + 1);
|
||||
_triangles.Add(_vertices.Count - 4 + 0);
|
||||
_triangles.Add(_vertices.Count - 4 + 0);
|
||||
_triangles.Add(_vertices.Count - 4 + 3);
|
||||
_triangles.Add(_vertices.Count - 4 + 2);
|
||||
|
||||
var source_rect = bitmap.SourceRect;
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
|
||||
_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMin));
|
||||
_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMin));
|
||||
}
|
||||
} else if ( elem_data.Type == FlashAnimInstType.Symbol ) {
|
||||
var symbol = Asset ? FindSymbol(Asset.Data.Library, elem_data.Asset) : null;
|
||||
if ( symbol != null ) {
|
||||
RenderSymbol(symbol, frame_num, matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RenderSymbol(FlashAnimSymbolData symbol, int frame_num, Matrix4x4 matix) {
|
||||
foreach ( var layer in symbol.Layers ) {
|
||||
if ( layer.LayerType != FlashAnimLayerType.Mask ) {
|
||||
var frame = GetFrameByNum(layer, frame_num);
|
||||
if ( frame != null ) {
|
||||
foreach ( var elem in frame.Elems ) {
|
||||
if ( elem.Instance != null ) {
|
||||
RenderInstance(
|
||||
elem.Instance, frame_num, matix * elem.Matrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Update() {
|
||||
_frame_timer += 25.0f * Time.deltaTime;
|
||||
while ( _frame_timer > 1.0f ) {
|
||||
_frame_timer -= 1.0f;
|
||||
++_current_frame;
|
||||
if ( _current_frame > frameCount - 1 ) {
|
||||
_current_frame = 0;
|
||||
}
|
||||
//Debug.LogFormat("Cur frame: {0}", _current_frame);
|
||||
}
|
||||
}
|
||||
|
||||
void OnRenderObject() {
|
||||
if ( Asset ) {
|
||||
_vertices.Clear();
|
||||
_triangles.Clear();
|
||||
_uvs.Clear();
|
||||
RenderSymbol(
|
||||
GetCurrentSymbol(),
|
||||
_current_frame,
|
||||
Matrix4x4.Scale(new Vector3(1,-1,1)));
|
||||
|
||||
var mesh = new Mesh();
|
||||
mesh.vertices = _vertices.ToArray();
|
||||
mesh.triangles = _triangles.ToArray();
|
||||
mesh.uv = _uvs.ToArray();
|
||||
mesh.RecalculateNormals();
|
||||
GetComponent<MeshFilter>().mesh = mesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,12 @@ namespace FlashTools {
|
||||
Folder
|
||||
}
|
||||
|
||||
public enum FlashAnimLoopingType {
|
||||
Loop,
|
||||
PlayOnce,
|
||||
SingleFrame
|
||||
}
|
||||
|
||||
public enum FlashAnimInstType {
|
||||
Bitmap,
|
||||
Symbol
|
||||
@@ -38,70 +44,42 @@ namespace FlashTools {
|
||||
MovieClip
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct FlashAnimMatrix {
|
||||
public float a;
|
||||
public float b;
|
||||
public float c;
|
||||
public float d;
|
||||
public float tx;
|
||||
public float ty;
|
||||
public FlashAnimMatrix(
|
||||
float a, float b, float c, float d,
|
||||
float tx, float ty)
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
this.d = d;
|
||||
this.tx = tx;
|
||||
this.ty = ty;
|
||||
}
|
||||
static public FlashAnimMatrix identity {
|
||||
get {
|
||||
return new FlashAnimMatrix(
|
||||
1.0f, 1.0f, 1.0f, 1.0f,
|
||||
0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class FlashAnimBitmapData {
|
||||
public string Id = string.Empty;
|
||||
public string ImageSource = string.Empty;
|
||||
public string Id = string.Empty;
|
||||
public Vector2 RealSize = Vector2.zero;
|
||||
public Rect SourceRect = new Rect();
|
||||
public string ImageSource = string.Empty;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class FlashAnimInstData {
|
||||
public FlashAnimInstType Type = FlashAnimInstType.Bitmap;
|
||||
public FlashAnimInstSymbolType SymbolType = FlashAnimInstSymbolType.Graphic;
|
||||
public FlashAnimBlendMode BlendMode = FlashAnimBlendMode.Normal;
|
||||
public string Asset = string.Empty;
|
||||
public bool Visible = true;
|
||||
// TODO: color_mode, looping, filters
|
||||
public FlashAnimInstType Type = FlashAnimInstType.Bitmap;
|
||||
public FlashAnimInstSymbolType SymbolType = FlashAnimInstSymbolType.Graphic;
|
||||
public FlashAnimBlendMode BlendMode = FlashAnimBlendMode.Normal;
|
||||
public string Asset = string.Empty;
|
||||
public bool Visible = true;
|
||||
public FlashAnimLoopingType LoopingType = FlashAnimLoopingType.SingleFrame;
|
||||
public int LoopingFirstFrame = 0;
|
||||
// TODO: color_mode, filters
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class FlashAnimElemData {
|
||||
public string Id = string.Empty;
|
||||
public int Depth = 0;
|
||||
public FlashAnimMatrix Matrix = FlashAnimMatrix.identity;
|
||||
public List<FlashAnimInstData> Insts = new List<FlashAnimInstData>();
|
||||
public string Id = string.Empty;
|
||||
public Matrix4x4 Matrix = Matrix4x4.identity;
|
||||
public FlashAnimInstData Instance = null;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class FlashAnimFrameData {
|
||||
public string Id = string.Empty;
|
||||
public int Index = 0;
|
||||
public int Duration = 0;
|
||||
public List<FlashAnimElemData> Elems = new List<FlashAnimElemData>();
|
||||
public string Id = string.Empty;
|
||||
public List<FlashAnimElemData> Elems = new List<FlashAnimElemData>();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class FlashAnimLayerData {
|
||||
public string Id = string.Empty;
|
||||
public bool Visible = true;
|
||||
public FlashAnimLayerType LayerType = FlashAnimLayerType.Normal;
|
||||
public List<FlashAnimFrameData> Frames = new List<FlashAnimFrameData>();
|
||||
}
|
||||
@@ -120,13 +98,13 @@ namespace FlashTools {
|
||||
|
||||
[System.Serializable]
|
||||
public class FlashAnimData {
|
||||
public Texture2D Atlas = null;
|
||||
public FlashAnimSymbolData Stage = new FlashAnimSymbolData();
|
||||
public FlashAnimLibraryData Library = new FlashAnimLibraryData();
|
||||
public List<string> Strings = new List<string>();
|
||||
}
|
||||
|
||||
public class FlashAnimAsset : ScriptableObject {
|
||||
public FlashAnimData Data = new FlashAnimData();
|
||||
public float PixelsPerUnit = 100.0f;
|
||||
public FlashAnimData Data = new FlashAnimData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,57 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEditor;
|
||||
using System;
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
public class FlashAnimAssetEditor : MonoBehaviour {
|
||||
[CustomEditor(typeof(FlashAnimAsset))]
|
||||
public class FlashAnimAssetEditor : Editor {
|
||||
FlashAnimAsset _asset = null;
|
||||
|
||||
void CreateFlashAnimOnScene() {
|
||||
var anim_go = new GameObject("FlashAnim");
|
||||
try {
|
||||
CreateFlashAnim(anim_go);
|
||||
} catch ( Exception e ) {
|
||||
Debug.LogErrorFormat("Create animation error: {0}", e.Message);
|
||||
DestroyImmediate(anim_go, true);
|
||||
}
|
||||
Undo.RegisterCreatedObjectUndo(anim_go, "Create Animation");
|
||||
}
|
||||
|
||||
void CreateFlashAnim(GameObject anim_go) {
|
||||
var flash_anim = anim_go.AddComponent<FlashAnim>();
|
||||
flash_anim.Asset = _asset;
|
||||
|
||||
var mesh_filter = anim_go.AddComponent<MeshFilter>();
|
||||
mesh_filter.mesh = null;
|
||||
|
||||
var material = new Material(Shader.Find("Sprites/Default"));
|
||||
material.SetTexture("_MainTex", _asset.Data.Atlas);
|
||||
|
||||
var mesh_renderer = anim_go.AddComponent<MeshRenderer>();
|
||||
mesh_renderer.sharedMaterial = material;
|
||||
mesh_renderer.useLightProbes = false;
|
||||
mesh_renderer.receiveShadows = false;
|
||||
mesh_renderer.shadowCastingMode = ShadowCastingMode.Off;
|
||||
mesh_renderer.reflectionProbeUsage = ReflectionProbeUsage.Off;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
void OnEnable() {
|
||||
_asset = target as FlashAnimAsset;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
DrawDefaultInspector();
|
||||
if ( GUILayout.Button("Create animation on scene") ) {
|
||||
CreateFlashAnimOnScene();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
public class FlashAnimEditor : MonoBehaviour {
|
||||
[CustomEditor(typeof(FlashAnim))]
|
||||
public class FlashAnimEditor : Editor {
|
||||
//FlashAnim _anim = null;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
void OnEnable() {
|
||||
//_anim = target as FlashAnim;
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,9 @@ using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using System.Reflection;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
public class FlashAnimPostprocessor : AssetPostprocessor {
|
||||
@@ -36,11 +38,13 @@ namespace FlashTools.Internal {
|
||||
|
||||
static FlashAnimData LoadFlashAnimFromFtaFile(string fta_path) {
|
||||
try {
|
||||
var fta_root_elem = XDocument.Load(fta_path).Document.Root;
|
||||
var fta_root_elem = XDocument.Load(fta_path).Document.Root;
|
||||
var flash_anim_data = new FlashAnimData();
|
||||
LoadFlashAnimStageFromFtaRootElem (fta_root_elem, flash_anim_data);
|
||||
LoadFlashAnimLibraryFromFtaRootElem(fta_root_elem, flash_anim_data);
|
||||
LoadFlashAnimStringsFromFtaRootElem(fta_root_elem, flash_anim_data);
|
||||
PrepareBitmapTextures(fta_path, flash_anim_data);
|
||||
PackBitmapTextures(fta_path, flash_anim_data);
|
||||
return flash_anim_data;
|
||||
} catch ( Exception e ) {
|
||||
Debug.LogErrorFormat("Parsing FTA file error: {0}", e.Message);
|
||||
@@ -70,12 +74,8 @@ namespace FlashTools.Internal {
|
||||
static void LoadFlashAnimBitmapsFromFtaLibraryElem(XElement library_elem, FlashAnimData data) {
|
||||
foreach ( var bitmap_elem in library_elem.Elements("bitmap") ) {
|
||||
var bitmap = new FlashAnimBitmapData();
|
||||
bitmap.Id = SafeLoadStrFromElemAttr(bitmap_elem, "id", bitmap.Id);
|
||||
if ( string.IsNullOrEmpty(bitmap.Id) ) {
|
||||
throw new UnityException("bitmap id not found");
|
||||
}
|
||||
bitmap.Id = SafeLoadStrFromElemAttr(bitmap_elem, "id", bitmap.Id);
|
||||
bitmap.ImageSource = bitmap.Id + ".png";
|
||||
// TODO: add image importer check
|
||||
data.Library.Bitmaps.Add(bitmap);
|
||||
}
|
||||
}
|
||||
@@ -83,10 +83,7 @@ namespace FlashTools.Internal {
|
||||
static void LoadFlashAnimSymbolsFromFtaLibraryElem(XElement library_elem, FlashAnimData data) {
|
||||
foreach ( var symbol_elem in library_elem.Elements("symbol") ) {
|
||||
var symbol = new FlashAnimSymbolData();
|
||||
symbol.Id = SafeLoadStrFromElemAttr(symbol_elem, "id", symbol.Id);
|
||||
if ( string.IsNullOrEmpty(symbol.Id) ) {
|
||||
throw new UnityException("symbol id not found");
|
||||
}
|
||||
symbol.Id = SafeLoadStrFromElemAttr(symbol_elem, "id", symbol.Id);
|
||||
LoadFlashAnimLayersFromFtaSymbolElem(symbol_elem, symbol);
|
||||
data.Library.Symbols.Add(symbol);
|
||||
}
|
||||
@@ -94,9 +91,8 @@ namespace FlashTools.Internal {
|
||||
|
||||
static void LoadFlashAnimLayersFromFtaSymbolElem(XElement symbol_elem, FlashAnimSymbolData data) {
|
||||
foreach ( var layer_elem in symbol_elem.Elements("layer") ) {
|
||||
var layer = new FlashAnimLayerData();
|
||||
var layer = new FlashAnimLayerData();
|
||||
layer.Id = SafeLoadStrFromElemAttr (layer_elem, "id" , layer.Id);
|
||||
layer.Visible = SafeLoadBoolFromElemAttr(layer_elem, "visible" , layer.Visible);
|
||||
layer.LayerType = SafeLoadEnumFromElemAttr(layer_elem, "layer_type", FlashAnimLayerType.Normal);
|
||||
LoadFlashAnimFramesFromFtaLayerElem(layer_elem, layer);
|
||||
data.Layers.Add(layer);
|
||||
@@ -106,9 +102,7 @@ namespace FlashTools.Internal {
|
||||
static void LoadFlashAnimFramesFromFtaLayerElem(XElement layer_elem, FlashAnimLayerData data) {
|
||||
foreach ( var frame_elem in layer_elem.Elements("frame") ) {
|
||||
var frame = new FlashAnimFrameData();
|
||||
frame.Id = SafeLoadStrFromElemAttr(frame_elem, "id" , frame.Id);
|
||||
frame.Index = SafeLoadIntFromElemAttr(frame_elem, "index" , frame.Index);
|
||||
frame.Duration = SafeLoadIntFromElemAttr(frame_elem, "duration" , frame.Duration);
|
||||
frame.Id = SafeLoadStrFromElemAttr(frame_elem, "id", frame.Id);
|
||||
LoadFlashAnimElemsFromFtaFrameElem(frame_elem, frame);
|
||||
data.Frames.Add(frame);
|
||||
}
|
||||
@@ -116,25 +110,28 @@ namespace FlashTools.Internal {
|
||||
|
||||
static void LoadFlashAnimElemsFromFtaFrameElem(XElement frame_elem, FlashAnimFrameData data) {
|
||||
foreach ( var elem_elem in frame_elem.Elements("element") ) {
|
||||
var elem = new FlashAnimElemData();
|
||||
var elem = new FlashAnimElemData();
|
||||
elem.Id = SafeLoadStrFromElemAttr(elem_elem, "id" , elem.Id);
|
||||
elem.Depth = SafeLoadIntFromElemAttr(elem_elem, "depth" , elem.Depth);
|
||||
elem.Matrix = SafeLoadMatFromElemAttr(elem_elem, "matrix", elem.Matrix);
|
||||
LoadFlashAnimInstsFromFtaElemElem(elem_elem, elem);
|
||||
LoadFlashAnimInstFromFtaElemElem(elem_elem, elem);
|
||||
data.Elems.Add(elem);
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadFlashAnimInstsFromFtaElemElem(XElement elem_elem, FlashAnimElemData data) {
|
||||
foreach ( var inst_elem in elem_elem.Elements("instance") ) {
|
||||
var inst = new FlashAnimInstData();
|
||||
inst.Type = SafeLoadEnumFromElemAttr(inst_elem, "type" , inst.Type);
|
||||
inst.SymbolType = SafeLoadEnumFromElemAttr(inst_elem, "symbol_type", inst.SymbolType);
|
||||
inst.BlendMode = SafeLoadEnumFromElemAttr(inst_elem, "blend_mode" , inst.BlendMode);
|
||||
inst.Asset = SafeLoadStrFromElemAttr (inst_elem, "asset" , inst.Asset);
|
||||
inst.Visible = SafeLoadBoolFromElemAttr(inst_elem, "visible" , inst.Visible);
|
||||
data.Insts.Add(inst);
|
||||
static void LoadFlashAnimInstFromFtaElemElem(XElement elem_elem, FlashAnimElemData data) {
|
||||
var inst_elem = elem_elem.Element("instance");
|
||||
var instance = new FlashAnimInstData();
|
||||
instance.Type = SafeLoadEnumFromElemAttr(inst_elem, "type" , instance.Type);
|
||||
instance.SymbolType = SafeLoadEnumFromElemAttr(inst_elem, "symbol_type", instance.SymbolType);
|
||||
instance.BlendMode = SafeLoadEnumFromElemAttr(inst_elem, "blend_mode" , instance.BlendMode);
|
||||
instance.Asset = SafeLoadStrFromElemAttr (inst_elem, "asset" , instance.Asset);
|
||||
instance.Visible = SafeLoadBoolFromElemAttr(inst_elem, "visible" , instance.Visible);
|
||||
var looping_elem = inst_elem.Element("looping");
|
||||
if ( looping_elem != null ) {
|
||||
instance.LoopingType = SafeLoadEnumFromElemAttr(looping_elem, "type" , instance.LoopingType);
|
||||
instance.LoopingFirstFrame = SafeLoadIntFromElemAttr (looping_elem, "first_frame" , instance.LoopingFirstFrame);
|
||||
}
|
||||
data.Instance = instance;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
@@ -153,6 +150,91 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Textures
|
||||
// -----------------------------
|
||||
|
||||
static void PrepareBitmapTextures(string fta_path, FlashAnimData data) {
|
||||
}
|
||||
|
||||
static void PackBitmapTextures(string fta_path, FlashAnimData data) {
|
||||
var base_path = Path.GetDirectoryName(fta_path);
|
||||
var textures = new List<Texture2D>();
|
||||
var texturen = new List<string>();
|
||||
foreach ( var bitmap in data.Library.Bitmaps ) {
|
||||
var texture_path = Path.Combine(base_path, bitmap.ImageSource);
|
||||
var importer = AssetImporter.GetAtPath(texture_path) as TextureImporter;
|
||||
if ( !importer ) {
|
||||
throw new UnityException(string.Format(
|
||||
"bitmap ({0}) texture importer not found ({1})",
|
||||
bitmap.Id, texture_path));
|
||||
}
|
||||
if ( !importer.isReadable ) {
|
||||
importer.isReadable = true;
|
||||
AssetDatabase.ImportAsset(texture_path, ImportAssetOptions.ForceUpdate);
|
||||
AssetDatabase.ImportAsset(fta_path, ImportAssetOptions.ForceUpdate);
|
||||
return;
|
||||
}
|
||||
var texture = AssetDatabase.LoadAssetAtPath<Texture2D>(texture_path);
|
||||
if ( !texture ) {
|
||||
throw new UnityException(string.Format(
|
||||
"bitmap ({0}) texture not found ({1})",
|
||||
bitmap.Id, texture_path));
|
||||
}
|
||||
textures.Add(texture);
|
||||
texturen.Add(bitmap.ImageSource);
|
||||
}
|
||||
|
||||
var atlas = new Texture2D(0, 0);
|
||||
var atlas_rects = atlas.PackTextures(textures.ToArray(), 1, 1024);
|
||||
var atlas_asset_path = Path.Combine(
|
||||
Path.GetDirectoryName(Application.dataPath),
|
||||
Path.Combine(base_path, "atlas.png"));
|
||||
File.WriteAllBytes(atlas_asset_path, atlas.EncodeToPNG());
|
||||
GameObject.DestroyImmediate(atlas);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
var atlas_path = Path.Combine(base_path, "atlas.png");
|
||||
data.Atlas = AssetDatabase.LoadAssetAtPath<Texture2D>(atlas_path);
|
||||
if ( !data.Atlas ) {
|
||||
AssetDatabase.ImportAsset(fta_path, ImportAssetOptions.ForceUpdate);
|
||||
return;
|
||||
}
|
||||
|
||||
var atlas_importer = AssetImporter.GetAtPath(atlas_path) as TextureImporter;
|
||||
if ( !atlas_importer ) {
|
||||
throw new UnityException(string.Format(
|
||||
"atlas importer not found ({0})",
|
||||
atlas_path));
|
||||
}
|
||||
|
||||
var method_args = new object[2]{0,0};
|
||||
typeof(TextureImporter)
|
||||
.GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
.Invoke(atlas_importer, method_args);
|
||||
var atlas_width = (int)method_args[0];
|
||||
var atlas_height = (int)method_args[1];
|
||||
|
||||
var meta_data = new List<SpriteMetaData>();
|
||||
for ( var i = 0; i < atlas_rects.Length; ++i ) {
|
||||
var meta_elem = new SpriteMetaData();
|
||||
meta_elem.name = texturen[i];
|
||||
data.Library.Bitmaps[i].RealSize = new Vector2(textures[i].width, textures[i].height);
|
||||
data.Library.Bitmaps[i].SourceRect = atlas_rects[i];
|
||||
meta_elem.rect = new Rect(
|
||||
atlas_rects[i].xMin * atlas_width,
|
||||
atlas_rects[i].yMin * atlas_height,
|
||||
atlas_rects[i].width * atlas_width,
|
||||
atlas_rects[i].height * atlas_height);
|
||||
meta_data.Add(meta_elem);
|
||||
}
|
||||
atlas_importer.spritesheet = meta_data.ToArray();
|
||||
atlas_importer.textureType = TextureImporterType.Sprite;
|
||||
atlas_importer.spriteImportMode = SpriteImportMode.Multiple;
|
||||
atlas_importer.textureFormat = TextureImporterFormat.AutomaticTruecolor;
|
||||
AssetDatabase.ImportAsset(atlas_path, ImportAssetOptions.ForceUpdate);
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Common
|
||||
// -----------------------------
|
||||
@@ -166,7 +248,7 @@ namespace FlashTools.Internal {
|
||||
|
||||
static int SafeLoadIntFromElemAttr(XElement elem, string attr_name, int def_value) {
|
||||
int value;
|
||||
if ( elem != null && int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) {
|
||||
if ( elem != null && int.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, string.Empty), out value) ) {
|
||||
return value;
|
||||
}
|
||||
return def_value;
|
||||
@@ -174,14 +256,14 @@ namespace FlashTools.Internal {
|
||||
|
||||
static bool SafeLoadBoolFromElemAttr(XElement elem, string attr_name, bool def_value) {
|
||||
bool value;
|
||||
if ( elem != null && bool.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, ""), out value) ) {
|
||||
if ( elem != null && bool.TryParse(SafeLoadStrFromElemAttr(elem, attr_name, string.Empty), out value) ) {
|
||||
return value;
|
||||
}
|
||||
return def_value;
|
||||
}
|
||||
|
||||
static FlashAnimMatrix SafeLoadMatFromElemAttr(XElement elem, string attr_name, FlashAnimMatrix def_value) {
|
||||
var mat_str = SafeLoadStrFromElemAttr(elem, attr_name, "");
|
||||
static Matrix4x4 SafeLoadMatFromElemAttr(XElement elem, string attr_name, Matrix4x4 def_value) {
|
||||
var mat_str = SafeLoadStrFromElemAttr(elem, attr_name, string.Empty);
|
||||
var mat_strs = mat_str.Split(';');
|
||||
if ( mat_strs.Length == 6 ) {
|
||||
float a, b, c, d, tx, ty;
|
||||
@@ -193,7 +275,14 @@ namespace FlashTools.Internal {
|
||||
float.TryParse(mat_strs[4], NumberStyles.Any, CultureInfo.InvariantCulture, out tx) &&
|
||||
float.TryParse(mat_strs[5], NumberStyles.Any, CultureInfo.InvariantCulture, out ty) )
|
||||
{
|
||||
return new FlashAnimMatrix(a, b, c, d, tx, ty);
|
||||
var mat = Matrix4x4.identity;
|
||||
mat.m00 = a;
|
||||
mat.m10 = b;
|
||||
mat.m01 = c;
|
||||
mat.m11 = d;
|
||||
mat.m03 = tx;
|
||||
mat.m13 = ty;
|
||||
return mat;
|
||||
}
|
||||
}
|
||||
return def_value;
|
||||
@@ -201,10 +290,10 @@ namespace FlashTools.Internal {
|
||||
|
||||
static T SafeLoadEnumFromElemAttr<T>(XElement elem, string attr_name, T def_value) {
|
||||
try {
|
||||
return (T)Enum.Parse(typeof(T), SafeLoadStrFromElemAttr(elem, attr_name, ""));
|
||||
return (T)Enum.Parse(typeof(T), SafeLoadStrFromElemAttr(elem, attr_name, string.Empty), true);
|
||||
} catch ( Exception ) {
|
||||
return def_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,24 +162,4 @@ QualitySettings:
|
||||
asyncUploadTimeSlice: 2
|
||||
asyncUploadBufferSize: 4
|
||||
excludedTargetPlatforms: []
|
||||
m_PerPlatformDefaultQuality:
|
||||
Android: 2
|
||||
BlackBerry: 2
|
||||
GLES Emulation: 5
|
||||
Nintendo 3DS: 5
|
||||
PS3: 5
|
||||
PS4: 5
|
||||
PSM: 5
|
||||
PSP2: 2
|
||||
Samsung TV: 2
|
||||
Standalone: 5
|
||||
Tizen: 2
|
||||
WP8: 5
|
||||
Web: 5
|
||||
WebGL: 3
|
||||
WiiU: 5
|
||||
Windows Store Apps: 5
|
||||
XBOX360: 5
|
||||
XboxOne: 5
|
||||
iPhone: 2
|
||||
tvOS: 5
|
||||
m_PerPlatformDefaultQuality: {}
|
||||
|
||||
@@ -162,6 +162,18 @@ if (typeof Object.create != 'function') {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ft.array_reverse_foreach = function (arr, func, filter) {
|
||||
ft.type_assert(arr, Array);
|
||||
ft.type_assert(func, Function);
|
||||
ft.type_assert_if_defined(filter, Function);
|
||||
for (var index = arr.length - 1; index >= 0; --index) {
|
||||
var value = arr[index];
|
||||
if (filter === undefined || filter(value, index)) {
|
||||
func(value, index);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ft.object_foreach = function (obj, func, filter) {
|
||||
ft.type_assert(obj, 'object');
|
||||
@@ -509,7 +521,7 @@ if (typeof Object.create != 'function') {
|
||||
this.timeline.selectAllFrames();
|
||||
this.timeline.convertToKeyframes();
|
||||
}
|
||||
ft.array_foreach(this.timeline.layers, function(layer, index) {
|
||||
ft.array_reverse_foreach(this.timeline.layers, function(layer, index) {
|
||||
this.timeline.setSelectedLayers(index);
|
||||
new LayerInst(layer, this.uniqueIds)
|
||||
.convert(document, this.timeline);
|
||||
@@ -518,7 +530,7 @@ if (typeof Object.create != 'function') {
|
||||
|
||||
TimelineInst.prototype.prepare = function (document) {
|
||||
ft.type_assert(document, Document);
|
||||
ft.array_foreach(this.timeline.layers, function(layer, index) {
|
||||
ft.array_reverse_foreach(this.timeline.layers, function(layer, index) {
|
||||
this.timeline.setSelectedLayers(index);
|
||||
new LayerInst(layer, this.uniqueIds)
|
||||
.prepare(document, this.timeline);
|
||||
@@ -527,7 +539,7 @@ if (typeof Object.create != 'function') {
|
||||
|
||||
TimelineInst.prototype.export_description = function (xml_node) {
|
||||
ft.type_assert(xml_node, XmlNode);
|
||||
ft.array_foreach(this.timeline.layers, function(layer) {
|
||||
ft.array_reverse_foreach(this.timeline.layers, function(layer) {
|
||||
new LayerInst(layer, this.uniqueIds)
|
||||
.export_description(xml_node);
|
||||
}.bind(this));
|
||||
@@ -564,11 +576,13 @@ if (typeof Object.create != 'function') {
|
||||
};
|
||||
|
||||
LayerInst.prototype.is_empty = function () {
|
||||
var frames = this.layer.frames;
|
||||
for ( var i = 0; i < frames.length; ++i ) {
|
||||
var is_empty = new FrameInst(frames[i], i, this.uniqueIds).is_empty();
|
||||
if ( !is_empty ) {
|
||||
return false;
|
||||
if ( this.layer.visible ) {
|
||||
var frames = this.layer.frames;
|
||||
for ( var i = 0; i < frames.length; ++i ) {
|
||||
var is_empty = new FrameInst(frames[i], i, this.uniqueIds).is_empty();
|
||||
if ( !is_empty ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -620,7 +634,6 @@ if (typeof Object.create != 'function') {
|
||||
ft.type_assert(xml_node, XmlNode);
|
||||
var layer_node = xml_node.child("layer")
|
||||
.attr("id" , this.get_id())
|
||||
.attr("visible" , this.layer.visible)
|
||||
.attr("layer_type", this.layer.layerType);
|
||||
if (this.layer.parentLayer) {
|
||||
var parent_layer = new LayerInst(this.layer.parentLayer, this.uniqueIds);
|
||||
@@ -736,9 +749,7 @@ if (typeof Object.create != 'function') {
|
||||
FrameInst.prototype.export_description = function (xml_node) {
|
||||
ft.type_assert(xml_node, XmlNode);
|
||||
var frame_node = xml_node.child("frame")
|
||||
.attr("id" , this.get_id())
|
||||
.attr("index" , this.get_index())
|
||||
.attr("duration", this.frame.duration);
|
||||
.attr("id", this.get_id());
|
||||
ft.array_foreach(this.frame.elements, function (element) {
|
||||
this.export_element(frame_node, element);
|
||||
}.bind(this));
|
||||
@@ -777,7 +788,6 @@ if (typeof Object.create != 'function') {
|
||||
ft.type_assert(xml_node, XmlNode);
|
||||
return xml_node.child("element")
|
||||
.attr("id" , this.get_id())
|
||||
.attr("depth" , this.inst.depth)
|
||||
.attr("matrix", "{0};{1};{2};{3};{4};{5}".format(
|
||||
this.inst.matrix.a, this.inst.matrix.b,
|
||||
this.inst.matrix.c, this.inst.matrix.d,
|
||||
@@ -827,6 +837,24 @@ if (typeof Object.create != 'function') {
|
||||
.format(symbol_type);
|
||||
}
|
||||
};
|
||||
|
||||
SymbolInst.prototype.get_looping_type = function () {
|
||||
var looping_type = this.inst.loop !== undefined ? this.inst.loop : "single frame";
|
||||
if ( looping_type == "loop" ) {
|
||||
return "loop";
|
||||
} else if ( looping_type == "play once" ) {
|
||||
return "playonce";
|
||||
} else if ( looping_type == "single frame" ) {
|
||||
return "single frame";
|
||||
} else {
|
||||
throw "Unsupported looping type ({0})!"
|
||||
.format(looping_type);
|
||||
}
|
||||
};
|
||||
|
||||
SymbolInst.prototype.get_looping_first_frame = function () {
|
||||
return this.inst.firstFrame !== undefined ? this.inst.firstFrame : 0;
|
||||
};
|
||||
|
||||
SymbolInst.prototype.export_description = function (xml_node) {
|
||||
ft.type_assert(xml_node, XmlNode);
|
||||
@@ -837,6 +865,11 @@ if (typeof Object.create != 'function') {
|
||||
.attr("asset" , this.uniqueIds.get_string_id(this.inst.libraryItem.name))
|
||||
.attr("visible" , this.inst.visible)
|
||||
.attr("blend_mode" , this.inst.blendMode);
|
||||
instance_node.child("looping")
|
||||
.attr("type" , this.get_looping_type())
|
||||
.attr("first_frame", this.get_looping_first_frame());
|
||||
|
||||
/* \TODO export color mode
|
||||
if (this.inst.colorMode !== "none") {
|
||||
var color_mode_node = instance_node.child("color_mode")
|
||||
.attr("color_mode", this.inst.colorMode);
|
||||
@@ -853,28 +886,23 @@ if (typeof Object.create != 'function') {
|
||||
} else if (this.inst.colorMode == "advanced") {
|
||||
color_mode_node
|
||||
.attr("a", "{0};{1}".format(this.inst.colorAlphaAmount, this.inst.colorAlphaPercent))
|
||||
.attr("r", "{0};{1}".format(this.inst.colorRedAmount, this.inst.colorRedPercent))
|
||||
.attr("r", "{0};{1}".format(this.inst.colorRedAmount, this.inst.colorRedPercent ))
|
||||
.attr("g", "{0};{1}".format(this.inst.colorGreenAmount, this.inst.colorGreenPercent))
|
||||
.attr("b", "{0};{1}".format(this.inst.colorBlueAmount, this.inst.colorBluePercent));
|
||||
.attr("b", "{0};{1}".format(this.inst.colorBlueAmount, this.inst.colorBluePercent ));
|
||||
} else {
|
||||
ft.assert(false,
|
||||
"Unsupported color mode ({0})!",
|
||||
this.inst.colorMode);
|
||||
}
|
||||
}
|
||||
if (this.inst.loop !== undefined && this.inst.firstFrame !== undefined) {
|
||||
instance_node.child("looping")
|
||||
.attr("loop" , this.inst.loop)
|
||||
.attr("first_frame", this.inst.firstFrame);
|
||||
}
|
||||
}*/
|
||||
/* \TODO export filters
|
||||
if (this.inst.filters && this.inst.filters.length > 0) {
|
||||
var filters_node = instance_node.child("filters");
|
||||
ft.array_foreach(this.inst.filters, function (filter) {
|
||||
/// \TODO export filters
|
||||
filters_node.child("filter")
|
||||
.attr("name", filter.name);
|
||||
});
|
||||
}
|
||||
}*/
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
<Properties StartupItem="Assembly-CSharp.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/FlashTools/Scripts/Internal/Editor/FlashAnimPostprocessor.cs">
|
||||
<MonoDevelop.Ide.Workbench>
|
||||
<Files>
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/FlashAnimAssetEditor.cs" Line="6" Column="2" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/FlashAnimPostprocessor.cs" Line="26" Column="20" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/FlashAnimEditor.cs" Line="3" Column="32" />
|
||||
<File FileName="Assets/FlashTools/Scripts/FlashAnimAsset.cs" Line="12" Column="21" />
|
||||
<File FileName="Assets/FlashTools/Scripts/FlashAnim.cs" Line="1" Column="1" />
|
||||
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/FlashAnimPostprocessor.cs" Line="1" Column="1" />
|
||||
<File FileName="Assets/FlashTools/Scripts/FlashAnimAsset.cs" Line="1" Column="1" NotebookId="1" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user