mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2026-01-06 08:26:52 +07:00
ftruntime refactor
This commit is contained in:
@@ -45,16 +45,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfAssocList.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfAttributes.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfList.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfSettings.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfUtils.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" />
|
||||
<Compile Include="Assets\FlashTools\Examples\PlayerController.cs" />
|
||||
<None Include="Assets\FlashTools\Resources\Materials\SwfBaseCG.cginc" />
|
||||
<None Include="Assets\FlashTools\Resources\Materials\SwfDecrMaskShader.shader" />
|
||||
<None Include="Assets\FlashTools\Resources\Materials\SwfSimpleShader.shader" />
|
||||
@@ -68,6 +59,9 @@
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.Networking">
|
||||
<HintPath>/Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/Networking/UnityEngine.Networking.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FTRuntime_Release">
|
||||
<HintPath>/Users/matov/Programming/Projects/unityflash/Assets/FlashTools/Plugins/FTRuntime_Release.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
<Compile Include="Sources\Editors\SwfManagerEditor.cs" />
|
||||
<Compile Include="Sources\Postprocessors\SwfAssetPostprocessor.cs" />
|
||||
<Compile Include="Sources\Postprocessors\SwfPostprocessor.cs" />
|
||||
<Compile Include="Sources\SwfAssetData.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib">
|
||||
|
||||
@@ -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);
|
||||
|
||||
234
FTSources/FTEditor/Sources/SwfAssetData.cs
Normal file
234
FTSources/FTEditor/Sources/SwfAssetData.cs
Normal file
@@ -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<SwfInstanceData> Instances = new List<SwfInstanceData>();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfSymbolData {
|
||||
public string Name = string.Empty;
|
||||
public List<SwfFrameData> Frames = new List<SwfFrameData>();
|
||||
}
|
||||
|
||||
[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<SwfSymbolData> Symbols = new List<SwfSymbolData>();
|
||||
public List<SwfBitmapData> Bitmaps = new List<SwfBitmapData>();
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace FTEditor {
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Functions
|
||||
// Inspector
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@@ -79,6 +79,12 @@ namespace FTEditor {
|
||||
return prop;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Assets
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public static SwfSettings GetSettingsHolder() {
|
||||
var holder = LoadFirstAssetByFilter<SwfSettings>("t:SwfSettings");
|
||||
if ( !holder ) {
|
||||
@@ -143,7 +149,7 @@ namespace FTEditor {
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Internal
|
||||
// Menu
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -34,21 +34,6 @@
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<Folder Include="Sources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Sources\SwfAsset.cs" />
|
||||
<Compile Include="Sources\SwfClip.cs" />
|
||||
<Compile Include="Sources\SwfClipAsset.cs" />
|
||||
<Compile Include="Sources\SwfClipController.cs" />
|
||||
<Compile Include="Sources\SwfManager.cs" />
|
||||
<Compile Include="Sources\Internal\SwfAssocList.cs" />
|
||||
<Compile Include="Sources\Internal\SwfAttributes.cs" />
|
||||
<Compile Include="Sources\Internal\SwfList.cs" />
|
||||
<Compile Include="Sources\Internal\SwfSettings.cs" />
|
||||
<Compile Include="Sources\Internal\SwfUtils.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib">
|
||||
<HintPath>..\DLLs\mscorlib.dll</HintPath>
|
||||
@@ -59,4 +44,19 @@
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Sources\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Sources\SwfAsset.cs" />
|
||||
<Compile Include="Sources\SwfAttributes.cs" />
|
||||
<Compile Include="Sources\SwfClip.cs" />
|
||||
<Compile Include="Sources\SwfClipAsset.cs" />
|
||||
<Compile Include="Sources\SwfClipController.cs" />
|
||||
<Compile Include="Sources\SwfManager.cs" />
|
||||
<Compile Include="Sources\SwfSettings.cs" />
|
||||
<Compile Include="Sources\Internal\SwfAssocList.cs" />
|
||||
<Compile Include="Sources\Internal\SwfList.cs" />
|
||||
<Compile Include="Sources\Internal\SwfUtils.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -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<int> Indices = new List<int>(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<Vector3> Vertices = new List<Vector3>(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<Vector2> UVs = new List<Vector2>(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<Vector4> AddColors = new List<Vector4>(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<Color> MulColors = new List<Color>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<SwfInstanceData> Instances = new List<SwfInstanceData>();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class SwfSymbolData {
|
||||
public string Name = string.Empty;
|
||||
public List<SwfFrameData> Frames = new List<SwfFrameData>();
|
||||
}
|
||||
|
||||
[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<SwfSymbolData> Symbols = new List<SwfSymbolData>();
|
||||
public List<SwfBitmapData> Bitmaps = new List<SwfBitmapData>();
|
||||
}
|
||||
|
||||
public class SwfAsset : ScriptableObject {
|
||||
[System.Serializable]
|
||||
public struct ConvertingState {
|
||||
|
||||
@@ -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) {
|
||||
@@ -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<Sequence>();
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// SwfClipAssetCache
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
static class SwfClipAssetCache {
|
||||
const int PreallocatedVertices = 500;
|
||||
|
||||
public static List<int> Indices = new List<int>(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<Vector3> Vertices = new List<Vector3>(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<Vector2> UVs = new List<Vector2>(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<Vector4> AddColors = new List<Vector4>(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<Color> MulColors = new List<Color>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
<Properties StartupItem="FTEditor/FTEditor.csproj">
|
||||
<MonoDevelop.Ide.Workbench />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="FTRuntime/Sources/SwfAsset.cs">
|
||||
<Files>
|
||||
<File FileName="FTRuntime/Sources/SwfAsset.cs" Line="22" Column="4" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release|x86" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<Properties>
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench />
|
||||
<Properties StartupItem="Assembly-CSharp.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/FlashTools/Examples/PlayerController.cs">
|
||||
<Files>
|
||||
<File FileName="Assets/FlashTools/Examples/PlayerController.cs" Line="10" Column="17" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
<MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
<BreakpointStore />
|
||||
</MonoDevelop.Ide.DebuggingService.Breakpoints>
|
||||
|
||||
Reference in New Issue
Block a user