diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index 2da18c4..a986810 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -45,16 +45,7 @@ - - - - - - - - - - + @@ -68,6 +59,9 @@ /Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll + + + /Users/matov/Programming/Projects/unityflash/Assets/FlashTools/Plugins/FTRuntime_Release.dll diff --git a/Assets/FlashTools/Resources/SwfSettings.asset b/Assets/FlashTools/Resources/SwfSettings.asset index 9a03aff..198c25d 100644 --- a/Assets/FlashTools/Resources/SwfSettings.asset +++ b/Assets/FlashTools/Resources/SwfSettings.asset @@ -8,7 +8,7 @@ MonoBehaviour: m_GameObject: {fileID: 0} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 202113923, guid: 2d72a763e7d744285b19a282e955a055, type: 3} + m_Script: {fileID: 1806722981, guid: 2d72a763e7d744285b19a282e955a055, type: 3} m_Name: SwfSettings m_EditorClassIdentifier: Settings: diff --git a/FTSources/FTEditor/FTEditor.csproj b/FTSources/FTEditor/FTEditor.csproj index 509eab3..9a7aa8e 100644 --- a/FTSources/FTEditor/FTEditor.csproj +++ b/FTSources/FTEditor/FTEditor.csproj @@ -49,6 +49,7 @@ + diff --git a/FTSources/FTEditor/Sources/Postprocessors/SwfAssetPostprocessor.cs b/FTSources/FTEditor/Sources/Postprocessors/SwfAssetPostprocessor.cs index 9f4a885..4440b3f 100644 --- a/FTSources/FTEditor/Sources/Postprocessors/SwfAssetPostprocessor.cs +++ b/FTSources/FTEditor/Sources/Postprocessors/SwfAssetPostprocessor.cs @@ -364,14 +364,14 @@ namespace FTEditor.Postprocessors { uint mul_pack0, mul_pack1; SwfUtils.PackFColorToUInts( - inst.ColorTrans.mulColor, + inst.ColorTrans.mulColor.ToUVector4(), out mul_pack0, out mul_pack1); baked_mulcolors.Add(mul_pack0); baked_mulcolors.Add(mul_pack1); uint add_pack0, add_pack1; SwfUtils.PackFColorToUInts( - inst.ColorTrans.addColor, + inst.ColorTrans.addColor.ToUVector4(), out add_pack0, out add_pack1); baked_addcolors.Add(add_pack0); baked_addcolors.Add(add_pack1); diff --git a/FTSources/FTEditor/Sources/SwfAssetData.cs b/FTSources/FTEditor/Sources/SwfAssetData.cs new file mode 100644 index 0000000..140b9a0 --- /dev/null +++ b/FTSources/FTEditor/Sources/SwfAssetData.cs @@ -0,0 +1,234 @@ +using UnityEngine; + +using System.Collections.Generic; + +namespace FTEditor { + [System.Serializable] + public struct SwfVec2Data { + public float x; + public float y; + + public SwfVec2Data(float x, float y) { + this.x = x; + this.y = y; + } + + public Vector2 ToUVector2() { + return new Vector2(x, y); + } + + public static SwfVec2Data one { + get { return new SwfVec2Data(1.0f, 1.0f); } + } + + public static SwfVec2Data zero { + get { return new SwfVec2Data(0.0f, 0.0f); } + } + } + + [System.Serializable] + public struct SwfVec4Data { + public float x; + public float y; + public float z; + public float w; + + public SwfVec4Data(float x, float y, float z, float w) { + this.x = x; + this.y = y; + this.z = z; + this.w = w; + } + + public Vector4 ToUVector4() { + return new Vector4(x, y, z, w); + } + + public static SwfVec4Data one { + get { return new SwfVec4Data(1.0f, 1.0f, 1.0f, 1.0f); } + } + + public static SwfVec4Data zero { + get { return new SwfVec4Data(0.0f, 0.0f, 0.0f, 0.0f); } + } + } + + [System.Serializable] + public struct SwfRectData { + public float xMin; + public float xMax; + public float yMin; + public float yMax; + + public static SwfRectData identity { + get { + return new SwfRectData{ + xMin = 0.0f, + xMax = 0.0f, + yMin = 0.0f, + yMax = 0.0f}; + } + } + + public static SwfRectData FromURect(Rect rect) { + return new SwfRectData{ + xMin = rect.xMin, + xMax = rect.xMax, + yMin = rect.yMin, + yMax = rect.yMax}; + } + } + + [System.Serializable] + public struct SwfMatrixData { + public SwfVec2Data sc; + public SwfVec2Data sk; + public SwfVec2Data tr; + + public static SwfMatrixData identity { + get { + return new SwfMatrixData{ + sc = SwfVec2Data.one, + sk = SwfVec2Data.zero, + tr = SwfVec2Data.zero}; + } + } + + public Matrix4x4 ToUMatrix() { + var mat = Matrix4x4.identity; + mat.m00 = sc.x; + mat.m11 = sc.y; + mat.m10 = sk.x; + mat.m01 = sk.y; + mat.m03 = tr.x; + mat.m13 = tr.y; + return mat; + } + + public static SwfMatrixData FromUMatrix(Matrix4x4 mat) { + return new SwfMatrixData{ + sc = new SwfVec2Data(mat.m00, mat.m11), + sk = new SwfVec2Data(mat.m10, mat.m01), + tr = new SwfVec2Data(mat.m03, mat.m13)}; + } + } + + [System.Serializable] + public struct SwfBlendModeData { + public enum Types : byte { + Normal, + Layer, + Multiply, + Screen, + Lighten, + Darken, // GrabPass + Difference, // GrabPass + Add, + Subtract, + Invert, // GrabPass + Overlay, // GrabPass + Hardlight // GrabPass + } + public Types type; + + public SwfBlendModeData(Types type) { + this.type = type; + } + + public static SwfBlendModeData identity { + get { + return new SwfBlendModeData{ + type = Types.Normal}; + } + } + + public static SwfBlendModeData operator*( + SwfBlendModeData a, SwfBlendModeData b) + { + return (a.type == Types.Normal || a.type == Types.Layer) ? b : a; + } + } + + [System.Serializable] + public struct SwfColorTransData { + public SwfVec4Data mulColor; + public SwfVec4Data addColor; + + public Color ApplyToColor(Color color) { + return new Color( + Mathf.Clamp01(color.r * mulColor.x + addColor.x), + Mathf.Clamp01(color.g * mulColor.y + addColor.y), + Mathf.Clamp01(color.b * mulColor.z + addColor.z), + Mathf.Clamp01(color.a * mulColor.w + addColor.w)); + } + + public static SwfColorTransData identity { + get { + return new SwfColorTransData{ + mulColor = SwfVec4Data.one, + addColor = SwfVec4Data.zero}; + } + } + + public static SwfColorTransData operator*( + SwfColorTransData a, SwfColorTransData b) + { + return new SwfColorTransData{ + mulColor = new SwfVec4Data( + b.mulColor.x * a.mulColor.x, + b.mulColor.y * a.mulColor.y, + b.mulColor.z * a.mulColor.z, + b.mulColor.w * a.mulColor.w), + addColor = new SwfVec4Data( + b.addColor.x * a.mulColor.x + a.addColor.x, + b.addColor.y * a.mulColor.y + a.addColor.y, + b.addColor.z * a.mulColor.z + a.addColor.z, + b.addColor.w * a.mulColor.w + a.addColor.w)}; + } + } + + [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 SwfMatrixData Matrix = SwfMatrixData.identity; + public SwfBlendModeData BlendMode = SwfBlendModeData.identity; + public SwfColorTransData ColorTrans = SwfColorTransData.identity; + } + + [System.Serializable] + public class SwfFrameData { + public string Name = string.Empty; + public List Instances = new List(); + } + + [System.Serializable] + public class SwfSymbolData { + public string Name = string.Empty; + public List Frames = new List(); + } + + [System.Serializable] + public class SwfBitmapData { + public ushort Id = 0; + public byte[] ARGB32 = new byte[0]; + public ushort Redirect = 0; + public int RealWidth = 0; + public int RealHeight = 0; + public SwfRectData SourceRect = SwfRectData.identity; + } + + [System.Serializable] + public class SwfAssetData { + public float FrameRate = 0.0f; + public List Symbols = new List(); + public List Bitmaps = new List(); + } +} \ No newline at end of file diff --git a/FTSources/FTEditor/Sources/SwfEditorUtils.cs b/FTSources/FTEditor/Sources/SwfEditorUtils.cs index 6d4407f..5a537fc 100644 --- a/FTSources/FTEditor/Sources/SwfEditorUtils.cs +++ b/FTSources/FTEditor/Sources/SwfEditorUtils.cs @@ -16,7 +16,7 @@ namespace FTEditor { // --------------------------------------------------------------------- // - // Functions + // Inspector // // --------------------------------------------------------------------- @@ -79,6 +79,12 @@ namespace FTEditor { return prop; } + // --------------------------------------------------------------------- + // + // Assets + // + // --------------------------------------------------------------------- + public static SwfSettings GetSettingsHolder() { var holder = LoadFirstAssetByFilter("t:SwfSettings"); if ( !holder ) { @@ -143,7 +149,7 @@ namespace FTEditor { // --------------------------------------------------------------------- // - // Internal + // Menu // // --------------------------------------------------------------------- diff --git a/FTSources/FTEditor/Sources/SwfPropertyDrawers.cs b/FTSources/FTEditor/Sources/SwfPropertyDrawers.cs index bec804d..6936c3f 100644 --- a/FTSources/FTEditor/Sources/SwfPropertyDrawers.cs +++ b/FTSources/FTEditor/Sources/SwfPropertyDrawers.cs @@ -4,7 +4,7 @@ using UnityEditor; using System.Linq; using System.Collections.Generic; -using FTRuntime.Internal; +using FTRuntime; namespace FTEditor { @@ -237,43 +237,6 @@ namespace FTEditor { } } - // - // SwfAssetGUIDDrawer - // - - [CustomPropertyDrawer(typeof(SwfAssetGUIDAttribute))] - public class SwfAssetGUIDDrawer : PropertyDrawer { - public override void OnGUI( - Rect position, SerializedProperty property, GUIContent label) - { - if ( property.propertyType == SerializedPropertyType.String ) { - var attr = attribute as SwfAssetGUIDAttribute; - SwfEditorUtils.DoWithEnabledGUI(!attr.ReadOnly, () => { - SwfEditorUtils.DoWithMixedValue( - property.hasMultipleDifferentValues, () => { - label = EditorGUI.BeginProperty(position, label, property); - EditorGUI.BeginChangeCheck(); - var asset_path = AssetDatabase.GUIDToAssetPath(property.stringValue); - var asset = AssetDatabase.LoadMainAssetAtPath(asset_path); - var new_asset = EditorGUI.ObjectField( - position, property.displayName, asset, typeof(UnityEngine.Object), false); - if ( EditorGUI.EndChangeCheck() ) { - if ( property.hasMultipleDifferentValues ) { - property.stringValue = "--"; - } - var new_asset_path = AssetDatabase.GetAssetPath(new_asset); - property.stringValue = AssetDatabase.AssetPathToGUID(new_asset_path); - property.serializedObject.ApplyModifiedProperties(); - } - EditorGUI.EndProperty(); - }); - }); - } else { - EditorGUI.LabelField(position, label.text, "Use SwfAssetGUID with string attribute."); - } - } - } - // // SwfDisplayNameDrawer // diff --git a/FTSources/FTRuntime/FTRuntime.csproj b/FTSources/FTRuntime/FTRuntime.csproj index f6fb6e9..f65fec8 100644 --- a/FTSources/FTRuntime/FTRuntime.csproj +++ b/FTSources/FTRuntime/FTRuntime.csproj @@ -34,21 +34,6 @@ AnyCPU - - - - - - - - - - - - - - - ..\DLLs\mscorlib.dll @@ -59,4 +44,19 @@ False + + + + + + + + + + + + + + + diff --git a/FTSources/FTRuntime/Sources/Internal/SwfUtils.cs b/FTSources/FTRuntime/Sources/Internal/SwfUtils.cs index 8b77dcc..35a6aea 100644 --- a/FTSources/FTRuntime/Sources/Internal/SwfUtils.cs +++ b/FTSources/FTRuntime/Sources/Internal/SwfUtils.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System.Collections.Generic; namespace FTRuntime.Internal { public static class SwfUtils { @@ -69,7 +70,7 @@ namespace FTRuntime.Internal { } public static void PackFColorToUInts( - SwfVec4Data v, + Vector4 v, out uint pack0, out uint pack1) { PackFColorToUInts(v.x, v.y, v.z, v.w, out pack0, out pack1); @@ -96,5 +97,139 @@ namespace FTRuntime.Internal { c2 = (short)((pack1 >> 16) & 0xFFFF) / InvFColorPrecision; c3 = (short)((pack1 ) & 0xFFFF) / InvFColorPrecision; } + + // + // + // + + public static void FillGeneratedMesh(Mesh mesh, SwfClipAsset.MeshData mesh_data) { + if ( mesh_data.SubMeshes.Length > 0 ) { + mesh.subMeshCount = mesh_data.SubMeshes.Length; + + GeneratedMeshCache.FillVertices(mesh_data.Vertices); + mesh.SetVertices(GeneratedMeshCache.Vertices); + + for ( int i = 0, e = mesh_data.SubMeshes.Length; i < e; ++i ) { + GeneratedMeshCache.FillTriangles( + mesh_data.SubMeshes[i].StartVertex, + mesh_data.SubMeshes[i].IndexCount); + mesh.SetTriangles(GeneratedMeshCache.Indices, i); + } + + GeneratedMeshCache.FillUVs(mesh_data.UVs); + mesh.SetUVs(0, GeneratedMeshCache.UVs); + + GeneratedMeshCache.FillAddColors(mesh_data.AddColors); + mesh.SetUVs(1, GeneratedMeshCache.AddColors); + + GeneratedMeshCache.FillMulColors(mesh_data.MulColors); + mesh.SetColors(GeneratedMeshCache.MulColors); + } + } + + // + // + // + + static class GeneratedMeshCache { + const int PreallocatedVertices = 500; + + public static List Indices = new List(PreallocatedVertices * 6 / 4); + public static void FillTriangles(int start_vertex, int index_count) { + Indices.Clear(); + if ( Indices.Capacity < index_count ) { + Indices.Capacity = index_count * 2; + } + for ( var i = 0; i < index_count; i += 6 ) { + Indices.Add(start_vertex + 2); + Indices.Add(start_vertex + 1); + Indices.Add(start_vertex + 0); + Indices.Add(start_vertex + 0); + Indices.Add(start_vertex + 3); + Indices.Add(start_vertex + 2); + start_vertex += 4; + } + } + + static Vector3 Vertex = Vector3.zero; + public static List Vertices = new List(PreallocatedVertices); + public static void FillVertices(Vector2[] vertices) { + Vertices.Clear(); + if ( Vertices.Capacity < vertices.Length ) { + Vertices.Capacity = vertices.Length * 2; + } + for ( int i = 0, e = vertices.Length; i < e; ++i ) { + var vert = vertices[i]; + Vertex.x = vert.x; + Vertex.y = vert.y; + Vertices.Add(Vertex); + } + } + + static Vector2 UV0 = Vector2.zero; + static Vector2 UV1 = Vector2.zero; + static Vector2 UV2 = Vector2.zero; + static Vector2 UV3 = Vector2.zero; + public static List UVs = new List(PreallocatedVertices); + public static void FillUVs(uint[] uvs) { + UVs.Clear(); + if ( UVs.Capacity < uvs.Length * 2 ) { + UVs.Capacity = uvs.Length * 2 * 2; + } + for ( int i = 0, e = uvs.Length; i < e; i += 2 ) { + float min_x, min_y, max_x, max_y; + SwfUtils.UnpackUV(uvs[i+0], out min_x, out min_y); + SwfUtils.UnpackUV(uvs[i+1], out max_x, out max_y); + + UV0.x = min_x; UV0.y = min_y; + UV1.x = max_x; UV1.y = min_y; + UV2.x = max_x; UV2.y = max_y; + UV3.x = min_x; UV3.y = max_y; + + UVs.Add(UV0); + UVs.Add(UV1); + UVs.Add(UV2); + UVs.Add(UV3); + } + } + + static Vector4 AddColor = Vector4.one; + public static List AddColors = new List(PreallocatedVertices); + public static void FillAddColors(uint[] colors) { + AddColors.Clear(); + if ( AddColors.Capacity < colors.Length * 2 ) { + AddColors.Capacity = colors.Length * 2 * 2; + } + for ( int i = 0, e = colors.Length; i < e; i += 2 ) { + SwfUtils.UnpackFColorFromUInts( + colors[i+0], colors[i+1], + out AddColor.x, out AddColor.y, + out AddColor.z, out AddColor.w); + AddColors.Add(AddColor); + AddColors.Add(AddColor); + AddColors.Add(AddColor); + AddColors.Add(AddColor); + } + } + + static Color MulColor = Color.white; + public static List MulColors = new List(PreallocatedVertices); + public static void FillMulColors(uint[] colors) { + MulColors.Clear(); + if ( MulColors.Capacity < colors.Length * 2 ) { + MulColors.Capacity = colors.Length * 2 * 2; + } + for ( int i = 0, e = colors.Length; i < e; i += 2 ) { + SwfUtils.UnpackFColorFromUInts( + colors[i+0], colors[i+1], + out MulColor.r, out MulColor.g, + out MulColor.b, out MulColor.a); + MulColors.Add(MulColor); + MulColors.Add(MulColor); + MulColors.Add(MulColor); + MulColors.Add(MulColor); + } + } + } } } \ No newline at end of file diff --git a/FTSources/FTRuntime/Sources/SwfAsset.cs b/FTSources/FTRuntime/Sources/SwfAsset.cs index 13bf826..3bca5cd 100644 --- a/FTSources/FTRuntime/Sources/SwfAsset.cs +++ b/FTSources/FTRuntime/Sources/SwfAsset.cs @@ -1,229 +1,7 @@ using UnityEngine; -using FTRuntime.Internal; using System.Collections.Generic; namespace FTRuntime { - [System.Serializable] - public struct SwfVec2Data { - public float x; - public float y; - - public SwfVec2Data(float x, float y) { - this.x = x; - this.y = y; - } - - public static SwfVec2Data one { - get { return new SwfVec2Data(1.0f, 1.0f); } - } - - public static SwfVec2Data zero { - get { return new SwfVec2Data(0.0f, 0.0f); } - } - } - - [System.Serializable] - public struct SwfVec4Data { - public float x; - public float y; - public float z; - public float w; - - public SwfVec4Data(float x, float y, float z, float w) { - this.x = x; - this.y = y; - this.z = z; - this.w = w; - } - - public static SwfVec4Data one { - get { return new SwfVec4Data(1.0f, 1.0f, 1.0f, 1.0f); } - } - - public static SwfVec4Data zero { - get { return new SwfVec4Data(0.0f, 0.0f, 0.0f, 0.0f); } - } - } - - [System.Serializable] - public struct SwfRectData { - public float xMin; - public float xMax; - public float yMin; - public float yMax; - - public static SwfRectData identity { - get { - return new SwfRectData{ - xMin = 0.0f, - xMax = 0.0f, - yMin = 0.0f, - yMax = 0.0f}; - } - } - - public static SwfRectData FromURect(Rect rect) { - return new SwfRectData{ - xMin = rect.xMin, - xMax = rect.xMax, - yMin = rect.yMin, - yMax = rect.yMax}; - } - } - - [System.Serializable] - public struct SwfMatrixData { - public SwfVec2Data sc; - public SwfVec2Data sk; - public SwfVec2Data tr; - - public static SwfMatrixData identity { - get { - return new SwfMatrixData{ - sc = SwfVec2Data.one, - sk = SwfVec2Data.zero, - tr = SwfVec2Data.zero}; - } - } - - public Matrix4x4 ToUMatrix() { - var mat = Matrix4x4.identity; - mat.m00 = sc.x; - mat.m11 = sc.y; - mat.m10 = sk.x; - mat.m01 = sk.y; - mat.m03 = tr.x; - mat.m13 = tr.y; - return mat; - } - - public static SwfMatrixData FromUMatrix(Matrix4x4 mat) { - return new SwfMatrixData{ - sc = new SwfVec2Data(mat.m00, mat.m11), - sk = new SwfVec2Data(mat.m10, mat.m01), - tr = new SwfVec2Data(mat.m03, mat.m13)}; - } - } - - [System.Serializable] - public struct SwfBlendModeData { - public enum Types : byte { - Normal, - Layer, - Multiply, - Screen, - Lighten, - Darken, // GrabPass - Difference, // GrabPass - Add, - Subtract, - Invert, // GrabPass - Overlay, // GrabPass - Hardlight // GrabPass - } - public Types type; - - public SwfBlendModeData(Types type) { - this.type = type; - } - - public static SwfBlendModeData identity { - get { - return new SwfBlendModeData{ - type = Types.Normal}; - } - } - - public static SwfBlendModeData operator*( - SwfBlendModeData a, SwfBlendModeData b) - { - return (a.type == Types.Normal || a.type == Types.Layer) ? b : a; - } - } - - [System.Serializable] - public struct SwfColorTransData { - public SwfVec4Data mulColor; - public SwfVec4Data addColor; - - public Color ApplyToColor(Color color) { - return new Color( - Mathf.Clamp01(color.r * mulColor.x + addColor.x), - Mathf.Clamp01(color.g * mulColor.y + addColor.y), - Mathf.Clamp01(color.b * mulColor.z + addColor.z), - Mathf.Clamp01(color.a * mulColor.w + addColor.w)); - } - - public static SwfColorTransData identity { - get { - return new SwfColorTransData{ - mulColor = SwfVec4Data.one, - addColor = SwfVec4Data.zero}; - } - } - - public static SwfColorTransData operator*( - SwfColorTransData a, SwfColorTransData b) - { - return new SwfColorTransData{ - mulColor = new SwfVec4Data( - b.mulColor.x * a.mulColor.x, - b.mulColor.y * a.mulColor.y, - b.mulColor.z * a.mulColor.z, - b.mulColor.w * a.mulColor.w), - addColor = new SwfVec4Data( - b.addColor.x * a.mulColor.x + a.addColor.x, - b.addColor.y * a.mulColor.y + a.addColor.y, - b.addColor.z * a.mulColor.z + a.addColor.z, - b.addColor.w * a.mulColor.w + a.addColor.w)}; - } - } - - [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 SwfMatrixData Matrix = SwfMatrixData.identity; - public SwfBlendModeData BlendMode = SwfBlendModeData.identity; - public SwfColorTransData ColorTrans = SwfColorTransData.identity; - } - - [System.Serializable] - public class SwfFrameData { - public string Name = string.Empty; - public List Instances = new List(); - } - - [System.Serializable] - public class SwfSymbolData { - public string Name = string.Empty; - public List Frames = new List(); - } - - [System.Serializable] - public class SwfBitmapData { - public ushort Id = 0; - public byte[] ARGB32 = new byte[0]; - public ushort Redirect = 0; - public int RealWidth = 0; - public int RealHeight = 0; - public SwfRectData SourceRect = SwfRectData.identity; - } - - [System.Serializable] - public class SwfAssetData { - public float FrameRate = 0.0f; - public List Symbols = new List(); - public List Bitmaps = new List(); - } - public class SwfAsset : ScriptableObject { [System.Serializable] public struct ConvertingState { diff --git a/FTSources/FTRuntime/Sources/Internal/SwfAttributes.cs b/FTSources/FTRuntime/Sources/SwfAttributes.cs similarity index 83% rename from FTSources/FTRuntime/Sources/Internal/SwfAttributes.cs rename to FTSources/FTRuntime/Sources/SwfAttributes.cs index dcbf110..1a36c82 100644 --- a/FTSources/FTRuntime/Sources/Internal/SwfAttributes.cs +++ b/FTSources/FTRuntime/Sources/SwfAttributes.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace FTRuntime.Internal { +namespace FTRuntime { public class SwfIntRangeAttribute : PropertyAttribute { public int Min; public int Max; @@ -36,13 +36,6 @@ namespace FTRuntime.Internal { public class SwfReadOnlyAttribute : PropertyAttribute { } - public class SwfAssetGUIDAttribute : PropertyAttribute { - public bool ReadOnly; - public SwfAssetGUIDAttribute(bool read_only) { - ReadOnly = read_only; - } - } - public class SwfDisplayNameAttribute : PropertyAttribute { public string DisplayName; public SwfDisplayNameAttribute(string display_name) { diff --git a/FTSources/FTRuntime/Sources/SwfClipAsset.cs b/FTSources/FTRuntime/Sources/SwfClipAsset.cs index f76e760..7f29e2b 100644 --- a/FTSources/FTRuntime/Sources/SwfClipAsset.cs +++ b/FTSources/FTRuntime/Sources/SwfClipAsset.cs @@ -17,31 +17,6 @@ namespace FTRuntime { public uint[] UVs = new uint[0]; public uint[] AddColors = new uint[0]; public uint[] MulColors = new uint[0]; - - public void FillMesh(Mesh mesh) { - if ( SubMeshes.Length > 0 ) { - mesh.subMeshCount = SubMeshes.Length; - - SwfClipAssetCache.FillVertices(Vertices); - mesh.SetVertices(SwfClipAssetCache.Vertices); - - for ( int i = 0, e = SubMeshes.Length; i < e; ++i ) { - SwfClipAssetCache.FillTriangles( - SubMeshes[i].StartVertex, - SubMeshes[i].IndexCount); - mesh.SetTriangles(SwfClipAssetCache.Indices, i); - } - - SwfClipAssetCache.FillUVs(UVs); - mesh.SetUVs(0, SwfClipAssetCache.UVs); - - SwfClipAssetCache.FillAddColors(AddColors); - mesh.SetUVs(1, SwfClipAssetCache.AddColors); - - SwfClipAssetCache.FillMulColors(MulColors); - mesh.SetColors(SwfClipAssetCache.MulColors); - } - } } [System.Serializable] @@ -64,7 +39,7 @@ namespace FTRuntime { get { if ( !_cachedMesh ) { _cachedMesh = new Mesh(); - MeshData.FillMesh(_cachedMesh); + SwfUtils.FillGeneratedMesh(_cachedMesh, MeshData); } return _cachedMesh; } @@ -93,111 +68,4 @@ namespace FTRuntime { Sequences = new List(); } } - - // --------------------------------------------------------------------- - // - // SwfClipAssetCache - // - // --------------------------------------------------------------------- - - static class SwfClipAssetCache { - const int PreallocatedVertices = 500; - - public static List Indices = new List(PreallocatedVertices * 6 / 4); - public static void FillTriangles(int start_vertex, int index_count) { - Indices.Clear(); - if ( Indices.Capacity < index_count ) { - Indices.Capacity = index_count * 2; - } - for ( var i = 0; i < index_count; i += 6 ) { - Indices.Add(start_vertex + 2); - Indices.Add(start_vertex + 1); - Indices.Add(start_vertex + 0); - Indices.Add(start_vertex + 0); - Indices.Add(start_vertex + 3); - Indices.Add(start_vertex + 2); - start_vertex += 4; - } - } - - static Vector3 Vertex = Vector3.zero; - public static List Vertices = new List(PreallocatedVertices); - public static void FillVertices(Vector2[] vertices) { - Vertices.Clear(); - if ( Vertices.Capacity < vertices.Length ) { - Vertices.Capacity = vertices.Length * 2; - } - for ( int i = 0, e = vertices.Length; i < e; ++i ) { - var vert = vertices[i]; - Vertex.x = vert.x; - Vertex.y = vert.y; - Vertices.Add(Vertex); - } - } - - static Vector2 UV0 = Vector2.zero; - static Vector2 UV1 = Vector2.zero; - static Vector2 UV2 = Vector2.zero; - static Vector2 UV3 = Vector2.zero; - public static List UVs = new List(PreallocatedVertices); - public static void FillUVs(uint[] uvs) { - UVs.Clear(); - if ( UVs.Capacity < uvs.Length * 2 ) { - UVs.Capacity = uvs.Length * 2 * 2; - } - for ( int i = 0, e = uvs.Length; i < e; i += 2 ) { - float min_x, min_y, max_x, max_y; - SwfUtils.UnpackUV(uvs[i+0], out min_x, out min_y); - SwfUtils.UnpackUV(uvs[i+1], out max_x, out max_y); - - UV0.x = min_x; UV0.y = min_y; - UV1.x = max_x; UV1.y = min_y; - UV2.x = max_x; UV2.y = max_y; - UV3.x = min_x; UV3.y = max_y; - - UVs.Add(UV0); - UVs.Add(UV1); - UVs.Add(UV2); - UVs.Add(UV3); - } - } - - static Vector4 AddColor = Vector4.one; - public static List AddColors = new List(PreallocatedVertices); - public static void FillAddColors(uint[] colors) { - AddColors.Clear(); - if ( AddColors.Capacity < colors.Length * 2 ) { - AddColors.Capacity = colors.Length * 2 * 2; - } - for ( int i = 0, e = colors.Length; i < e; i += 2 ) { - SwfUtils.UnpackFColorFromUInts( - colors[i+0], colors[i+1], - out AddColor.x, out AddColor.y, - out AddColor.z, out AddColor.w); - AddColors.Add(AddColor); - AddColors.Add(AddColor); - AddColors.Add(AddColor); - AddColors.Add(AddColor); - } - } - - static Color MulColor = Color.white; - public static List MulColors = new List(PreallocatedVertices); - public static void FillMulColors(uint[] colors) { - MulColors.Clear(); - if ( MulColors.Capacity < colors.Length * 2 ) { - MulColors.Capacity = colors.Length * 2 * 2; - } - for ( int i = 0, e = colors.Length; i < e; i += 2 ) { - SwfUtils.UnpackFColorFromUInts( - colors[i+0], colors[i+1], - out MulColor.r, out MulColor.g, - out MulColor.b, out MulColor.a); - MulColors.Add(MulColor); - MulColors.Add(MulColor); - MulColors.Add(MulColor); - MulColors.Add(MulColor); - } - } - } } \ No newline at end of file diff --git a/FTSources/FTRuntime/Sources/Internal/SwfSettings.cs b/FTSources/FTRuntime/Sources/SwfSettings.cs similarity index 98% rename from FTSources/FTRuntime/Sources/Internal/SwfSettings.cs rename to FTSources/FTRuntime/Sources/SwfSettings.cs index 87e2ebe..80590d2 100644 --- a/FTSources/FTRuntime/Sources/Internal/SwfSettings.cs +++ b/FTSources/FTRuntime/Sources/SwfSettings.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace FTRuntime.Internal { +namespace FTRuntime { [System.Serializable] public struct SwfSettingsData { public enum AtlasFilter { @@ -57,6 +57,7 @@ namespace FTRuntime.Internal { public class SwfSettings : ScriptableObject { public SwfSettingsData Settings; + void Reset() { Settings = SwfSettingsData.identity; } diff --git a/FTSources/FTSources.userprefs b/FTSources/FTSources.userprefs index 7be3866..3fb06bd 100644 --- a/FTSources/FTSources.userprefs +++ b/FTSources/FTSources.userprefs @@ -1,5 +1,9 @@  - + + + + + diff --git a/unityflash.userprefs b/unityflash.userprefs index 8a063db..c4ea0c3 100644 --- a/unityflash.userprefs +++ b/unityflash.userprefs @@ -1,6 +1,10 @@ - - - + + + + + + +