Compare commits

...

44 Commits

Author SHA1 Message Date
8942aceef2 version 0.4 2016-09-22 02:19:15 +07:00
7057cd71a8 clear code 2016-09-22 02:14:58 +07:00
1d402eb91e clip groups 2016-09-21 23:36:32 +07:00
2ce9897d60 compress asset data 2016-09-21 01:16:12 +07:00
63fea79f49 able move containers and assets 2016-09-20 15:19:39 +07:00
5d29da73c7 tint color for clips 2016-09-16 05:08:06 +07:00
0c4efc0111 flash tools log prefix 2016-09-16 04:50:07 +07:00
6474828774 open settings menu button 2016-09-16 04:36:47 +07:00
78758786e6 'reimport all' menu button 2016-09-16 03:25:44 +07:00
7a0940b6a1 pause, resume and rate scale for manger 2016-09-16 03:03:33 +07:00
3d688d1ac2 controller API improvements 2016-09-16 02:33:48 +07:00
6d69b46c2f Added tag versions/0.3 for changeset d2d05072620c 2016-09-14 22:30:25 +07:00
2e6fc73bfe version 0.3 2016-09-14 22:30:09 +07:00
46a340d615 fix empty texture after reimport 2016-09-14 21:14:07 +07:00
e41eae8c72 GotoAndStop, GotoAndPlay 2016-09-14 18:38:07 +07:00
1991da1f6b fill mesh optimizations 2016-09-14 16:17:35 +07:00
14d1088db9 remove vertex coords tricks. skip many fill mesh in one frame 2016-09-14 14:19:51 +07:00
d1777239cd cut invisible geometry 2016-09-14 01:16:50 +07:00
dc539b1e27 style fixes 2016-09-14 00:42:46 +07:00
8108516350 compress mesh wip 2016-09-13 03:03:36 +07:00
c5270a01a7 compress mesh wip 2016-09-13 00:25:32 +07:00
c424a4d507 compress mesh data wip 2016-09-12 20:29:54 +07:00
876859a0e1 color transform range fix 2016-09-12 16:45:18 +07:00
00d66fa94e hide materials in inspector again 2016-09-11 23:04:51 +07:00
e98071f471 chached meshes wip 2016-09-11 22:55:02 +07:00
f068463454 style fixes 2016-09-11 02:25:43 +07:00
8ddb0d2bcb settings fix 2016-09-10 23:21:31 +07:00
6ba10b4875 little optimize asset size of disk 2016-09-10 22:47:31 +07:00
ddacef7275 show frame count for clip asset 2016-09-10 21:15:44 +07:00
6881f46d89 correct inspector for overriden order layer 2016-09-10 19:57:38 +07:00
811bd73fa1 fix prefab current mesh bug 2016-09-10 18:41:50 +07:00
5bce0db290 style fixes 2016-09-10 18:22:59 +07:00
a5c9d21b66 show clips for container asset in editor 2016-09-10 15:04:35 +07:00
fd0fae1590 preview fixes 2016-09-10 14:05:50 +07:00
225ab99153 style fixes 2016-09-10 05:17:18 +07:00
9609e07e5c preview for assets and clips 2016-09-10 01:49:19 +07:00
060594dc29 little style fix 2016-09-09 21:33:49 +07:00
891c1790c3 safe update controllers 2016-09-09 21:16:47 +07:00
b3783f22c4 jpg rasterize fix 2016-09-09 17:15:48 +07:00
205d4aad8c revert documents after export fix 2016-09-08 22:18:25 +07:00
c749b0ca9d multiple sequences edit 2016-09-08 22:08:45 +07:00
d1a992e421 fix empty mesh bug and to 5.3.6f1 2016-09-08 15:23:41 +07:00
950b7b663d DS_Store to ignore 2016-09-08 03:31:10 +07:00
1a3d541771 Added tag versions/0.2 for changeset aa93e17d4cac 2016-09-08 03:28:30 +07:00
44 changed files with 1800 additions and 622 deletions

View File

@@ -1,3 +1,5 @@
glob:obj/*
glob:Temp/*
glob:Library/*
glob:.DS_Store

View File

@@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_5;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_6;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
@@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Editors\SwfAssetEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Editors\SwfClipAssetEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Editors\SwfClipAssetPreview.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Editors\SwfClipControllerEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Editors\SwfClipEditor.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Editors\SwfManagerEditor.cs" />
@@ -102,6 +103,7 @@
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfTypes\SwfShapesWithStyle.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfTypes\SwfShortHeader.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\SwfTools\SwfTypes\SwfSurfaceFilters.cs" />
<Compile Include="Assets\FlashTools\Scripts\Internal\Editor\Tests\SwfUtilsTests.cs" />
<None Include="Assets\FlashTools\Resources\Shaders\SwfDecrMask.shader" />
<None Include="Assets\FlashTools\Resources\Shaders\SwfSimple.shader" />
<None Include="Assets\FlashTools\CHANGELOG.txt" />
@@ -143,21 +145,9 @@
<Reference Include="UnityEditor.iOS.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.AppleTV.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/AppleTVSupport/UnityEditor.AppleTV.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.Tizen.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/TizenPlayer/UnityEditor.Tizen.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.SamsungTV.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/STVPlayer/UnityEditor.SamsungTV.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.WebGL.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/WebGLSupport/UnityEditor.WebGL.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.LinuxStandalone.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/LinuxStandaloneSupport/UnityEditor.LinuxStandalone.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.WindowsStandalone.Extensions">
<HintPath>/Applications/Unity/PlaybackEngines/WindowsStandaloneSupport/UnityEditor.WindowsStandalone.Extensions.dll</HintPath>
</Reference>
@@ -165,12 +155,6 @@
<HintPath>/Applications/Unity/PlaybackEngines/MacStandaloneSupport/UnityEditor.OSXStandalone.Extensions.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>/Applications/Unity/PlaybackEngines/AppleTVSupport/UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Common">
<HintPath>/Applications/Unity/PlaybackEngines/AppleTVSupport/UnityEditor.iOS.Extensions.Common.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Xcode">
<HintPath>/Applications/Unity/PlaybackEngines/iOSSupport/UnityEditor.iOS.Extensions.Xcode.dll</HintPath>
</Reference>
<Reference Include="UnityEditor.iOS.Extensions.Common">

View File

@@ -19,7 +19,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_5;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_5_3_OR_NEWER;UNITY_5_3_6;UNITY_5_3;UNITY_5;ENABLE_NEW_BUGREPORTER;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_DUCK_TYPING;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_PHYSICS;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITERENDERER_FLIPPING;ENABLE_SPRITES;ENABLE_SPRITE_POLYGON;ENABLE_TERRAIN;ENABLE_RAKNET;ENABLE_UNET;ENABLE_UNITYEVENTS;ENABLE_VR;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_CLOUD_SERVICES;ENABLE_CLOUD_SERVICES_ADS;ENABLE_CLOUD_HUB;ENABLE_CLOUD_PROJECT_ID;ENABLE_CLOUD_SERVICES_PURCHASING;ENABLE_CLOUD_SERVICES_ANALYTICS;ENABLE_CLOUD_SERVICES_UNET;ENABLE_CLOUD_SERVICES_BUILD;ENABLE_CLOUD_LICENSE;ENABLE_EDITOR_METRICS;ENABLE_EDITOR_METRICS_CACHING;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;INCLUDE_DIRECTX12;PLATFORM_SUPPORTS_MONO;RENDER_SOFTWARE_CURSOR;ENABLE_LOCALIZATION;ENABLE_ANDROID_ATLAS_ETC1_COMPRESSION;ENABLE_EDITOR_TESTS_RUNNER;UNITY_STANDALONE_OSX;UNITY_STANDALONE;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_TEXTUREID_MAP;ENABLE_RUNTIME_GI;ENABLE_MOVIES;ENABLE_NETWORK;ENABLE_CRUNCH_TEXTURE_COMPRESSION;ENABLE_LOG_MIXED_STACKTRACE;ENABLE_UNITYWEBREQUEST;ENABLE_CLUSTERINPUT;ENABLE_WEBSOCKET_HOST;ENABLE_MONO;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_ASSERTIONS;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>0169</NoWarn>
@@ -49,6 +49,7 @@
<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" />

View File

@@ -1,3 +1,20 @@
-----------------
-- Version 0.4 --
-----------------
Clip groups
Fix move assets bug
Tint color for clips
Animation API improvements
-----------------
-- Version 0.3 --
-----------------
Preview for animation assets and clips
Animation API improvements
Memory optimizations
-----------------
-- Version 0.2 --
-----------------
@@ -9,4 +26,4 @@ Export clips with export names
-- Version 0.1 --
-----------------
Initial alpha version.
Initial alpha version

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 075eada96ece147de8eeee4710c5ab0f
timeCreated: 1474360714
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -145,7 +145,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 3
orthographic size: 23
m_Depth: 0
m_CullingMask:
serializedVersion: 2

View File

@@ -1,6 +1,7 @@
Shader "FlashTools/SwfMasked" {
Properties {
[PerRendererData] _MainTex("Main Texture", 2D) = "white" {}
[PerRendererData] _MainTex("Main Texture", 2D ) = "white" {}
[PerRendererData] _Color ("Tint" , Color) = (1,1,1,1)
_StencilID ("Stencil ID", Int) = 0
}
@@ -42,11 +43,13 @@ Shader "FlashTools/SwfMasked" {
fixed4 addcolor : TEXCOORD1;
};
fixed4 _Color;
v2f vert(appdata_t IN) {
v2f OUT;
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
OUT.uv = IN.uv;
OUT.mulcolor = IN.mulcolor;
OUT.mulcolor = IN.mulcolor * _Color;
OUT.addcolor = IN.addcolor;
return OUT;
}

View File

@@ -1,6 +1,7 @@
Shader "FlashTools/SwfSimple" {
Properties {
[PerRendererData] _MainTex("Main Texture", 2D) = "white" {}
[PerRendererData] _MainTex("Main Texture", 2D ) = "white" {}
[PerRendererData] _Color ("Tint" , Color) = (1,1,1,1)
}
SubShader {
@@ -37,11 +38,13 @@ Shader "FlashTools/SwfSimple" {
fixed4 addcolor : TEXCOORD1;
};
fixed4 _Color;
v2f vert(appdata_t IN) {
v2f OUT;
OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex);
OUT.uv = IN.uv;
OUT.mulcolor = IN.mulcolor;
OUT.mulcolor = IN.mulcolor * _Color;
OUT.addcolor = IN.addcolor;
return OUT;
}

View File

@@ -1,7 +1,6 @@
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
@@ -9,24 +8,18 @@ using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfAsset)), CanEditMultipleObjects]
public class SwfAssetEditor : Editor {
List<SwfAsset> _assets = new List<SwfAsset>();
bool _settingsFoldout = false;
List<SwfAsset> _assets = new List<SwfAsset>();
//
//
//
static string GetAssetPath(SwfAsset asset) {
return asset
? AssetDatabase.GetAssetPath(asset)
: string.Empty;
}
static string GetSwfPath(SwfAsset asset) {
var asset_path = GetAssetPath(asset);
return string.IsNullOrEmpty(asset_path)
? string.Empty
: Path.ChangeExtension(asset_path, ".swf");
static SwfSettings _defaultSettingsCache = null;
static SwfSettings GetDefaultSettings() {
if ( !_defaultSettingsCache ) {
_defaultSettingsCache = SwfSettings.GetHolder();
}
return _defaultSettingsCache;
}
//
@@ -38,30 +31,25 @@ namespace FlashTools.Internal {
}
static void OverriddenSettingsToDefault(SwfAsset asset) {
asset.Overridden = SwfSettings.GetDefault();
asset.Overridden = GetDefaultSettings().Settings;
}
static void ApplyOverriddenSettings(SwfAsset asset) {
if ( File.Exists(GetSwfPath(asset)) ) {
asset.Settings = asset.Overridden;
ReconvertAsset(asset);
} else {
Debug.LogErrorFormat(
"Swf source for asset not found: '{0}'",
GetSwfPath(asset));
RevertOverriddenSettings(asset);
}
asset.Settings = asset.Overridden;
ReconvertAsset(asset);
}
static void ReconvertAsset(SwfAsset asset) {
AssetDatabase.ImportAsset(GetSwfPath(asset));
asset.Converting = new SwfAsset.ConvertingState();
AssetDatabase.ImportAsset(
AssetDatabase.GetAssetPath(asset));
}
//
//
//
void AllAssetsForeach(Action<SwfAsset> act) {
void AllAssetsForeach(System.Action<SwfAsset> act) {
foreach ( var asset in _assets ) {
act(asset);
}
@@ -105,39 +93,28 @@ namespace FlashTools.Internal {
}
}
void DrawGUISettings() {
_settingsFoldout = EditorGUILayout.Foldout(_settingsFoldout, "Settings");
if ( _settingsFoldout ) {
var it = SwfEditorUtils.GetPropertyByName(serializedObject, "Overridden");
while ( it.Next(true) ) {
EditorGUILayout.PropertyField(it, true);
}
DrawGUISettingsControls();
}
}
void DrawGUISettingsControls() {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
var default_settings = SwfSettings.GetDefault();
SwfEditorUtils.DoWithEnabledGUI(
_assets.Any(p => !p.Overridden.CheckEquals(default_settings)), () => {
if ( GUILayout.Button("Default") ) {
AllOverriddenSettingsToDefault();
}
});
SwfEditorUtils.DoWithEnabledGUI(
_assets.Any(p => !p.Overridden.CheckEquals(p.Settings)), () => {
if ( GUILayout.Button("Revert") ) {
RevertAllOverriddenSettings();
}
if ( GUILayout.Button("Apply") ) {
ApplyAllOverriddenSettings();
}
});
var prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Overridden");
if ( prop.isExpanded ) {
SwfEditorUtils.DoRightHorizontalGUI(() => {
var default_settings = GetDefaultSettings().Settings;
SwfEditorUtils.DoWithEnabledGUI(
_assets.Any(p => !p.Overridden.CheckEquals(default_settings)), () => {
if ( GUILayout.Button("Default") ) {
AllOverriddenSettingsToDefault();
}
});
SwfEditorUtils.DoWithEnabledGUI(
_assets.Any(p => !p.Overridden.CheckEquals(p.Settings)), () => {
if ( GUILayout.Button("Revert") ) {
RevertAllOverriddenSettings();
}
if ( GUILayout.Button("Apply") ) {
ApplyAllOverriddenSettings();
}
});
});
}
GUILayout.EndHorizontal();
}
// ---------------------------------------------------------------------
@@ -147,8 +124,7 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
void OnEnable() {
_assets = targets.OfType<SwfAsset>().ToList();
_settingsFoldout = true;
_assets = targets.OfType<SwfAsset>().ToList();
}
void OnDisable() {
@@ -158,7 +134,7 @@ namespace FlashTools.Internal {
public override void OnInspectorGUI() {
serializedObject.Update();
DrawDefaultInspector();
DrawGUISettings();
DrawGUISettingsControls();
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();
}

View File

@@ -1,7 +1,6 @@
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
@@ -24,6 +23,12 @@ namespace FlashTools.Internal {
: Path.ChangeExtension(clip_path, ".prefab");
}
static int GetFrameCount(SwfClipAsset clip) {
return clip != null ? clip.Sequences.Aggregate(0, (acc, seq) => {
return seq.Frames.Count + acc;
}) : 0;
}
//
//
//
@@ -90,9 +95,21 @@ namespace FlashTools.Internal {
//
//
void DrawGUIFrameCount() {
var counts = _clips.Select(p => GetFrameCount(p));
var mixed_value = counts.GroupBy(p => p).Count() > 1;
SwfEditorUtils.DoWithEnabledGUI(false, () => {
SwfEditorUtils.DoWithMixedValue(
mixed_value, () => {
EditorGUILayout.IntField("Frame count", counts.First());
});
});
}
void DrawGUISequences() {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
var sequences_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "Sequences");
var sequences_prop = SwfEditorUtils.GetPropertyByName(
serializedObject, "Sequences");
if ( sequences_prop.isArray ) {
SwfEditorUtils.DoWithMixedValue(
sequences_prop.hasMultipleDifferentValues, () => {
@@ -103,16 +120,14 @@ namespace FlashTools.Internal {
}
void DrawGUIControls() {
GUILayout.BeginHorizontal();
{
SwfEditorUtils.DoHorizontalGUI(() => {
if ( GUILayout.Button("Create prefab") ) {
CreateAllClipsPrefabs();
}
if ( GUILayout.Button("Instance to scene") ) {
CreateAllClipsOnScene();
}
}
GUILayout.EndHorizontal();
});
}
// ---------------------------------------------------------------------
@@ -122,19 +137,22 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
void OnEnable() {
_clips = targets
.OfType<SwfClipAsset>()
.ToList();
_clips = targets.OfType<SwfClipAsset>().ToList();
}
public override void OnInspectorGUI() {
serializedObject.Update();
DrawDefaultInspector();
DrawGUIFrameCount();
DrawGUISequences();
DrawGUIControls();
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();
}
}
public override bool RequiresConstantRepaint() {
return true;
}
}
}

View File

@@ -0,0 +1,179 @@
using UnityEngine;
using UnityEditor;
using System.Linq;
namespace FlashTools.Internal {
[CustomPreview(typeof(SwfClipAsset))]
public class SwfClipAssetPreview : ObjectPreview {
int _sequence = 0;
static MaterialPropertyBlock _matPropBlock = null;
static PreviewRenderUtility _previewUtils = null;
Texture2D targetAtlas {
get {
var clip = target as SwfClipAsset;
return clip.Atlas;
}
}
int targetSequenceCount {
get {
var clip = target as SwfClipAsset;
return clip && clip.Sequences != null
? clip.Sequences.Count
: 0;
}
}
SwfClipAsset.Frame targetFrame {
get {
var clip = target as SwfClipAsset;
return GetFrameForClip(clip, _sequence);
}
}
SwfClipAsset.Sequence targetSequence {
get {
var clip = target as SwfClipAsset;
return GetSequenceForClip(clip, _sequence);
}
}
bool isTargetValidForPreview {
get {
var atlas = targetAtlas;
var frame = targetFrame;
var sequence = targetSequence;
return
atlas &&
frame != null &&
sequence != null &&
frame.CachedMesh && frame.CachedMesh.vertexCount > 0;
}
}
static SwfClipAsset.Frame GetFrameForClip(SwfClipAsset clip, int sequence_index) {
var sequence = GetSequenceForClip(clip, sequence_index);
var frames = sequence != null && sequence.Frames != null && sequence.Frames.Count > 0
? sequence.Frames
: null;
var frame_time = (float)(EditorApplication.timeSinceStartup * clip.FrameRate);
return frames != null
? frames[Mathf.FloorToInt(frame_time) % frames.Count]
: null;
}
static SwfClipAsset.Sequence GetSequenceForClip(SwfClipAsset clip, int sequence_index) {
return clip && clip.Sequences != null && clip.Sequences.Count > 0
? clip.Sequences[Mathf.Abs(sequence_index) % clip.Sequences.Count]
: null;
}
static Bounds CalculateBoundsForSequence(SwfClipAsset.Sequence sequence) {
var bounds = sequence != null && sequence.Frames != null && sequence.Frames.Count > 0
? sequence.Frames
.Where (p => !!p.CachedMesh)
.Select(p => p.CachedMesh.bounds)
: new Bounds[0];
var result = bounds.Any() ? bounds.First() : new Bounds();
foreach ( var bound in bounds ) {
result.Encapsulate(bound);
}
return result;
}
static void ConfigureCameraForSequence(Camera camera, SwfClipAsset.Sequence sequence) {
var bounds = CalculateBoundsForSequence(sequence);
camera.orthographic = true;
camera.orthographicSize = Mathf.Max(
Mathf.Abs(bounds.extents.x),
Mathf.Abs(bounds.extents.y));
camera.transform.position = new Vector3(
bounds.center.x,
bounds.center.y,
-10.0f);
}
// ---------------------------------------------------------------------
//
// Functions
//
// ---------------------------------------------------------------------
public void SetCurrentSequence(string sequence_name) {
var clip = target as SwfClipAsset;
_sequence = clip && clip.Sequences != null
? Mathf.Max(0, clip.Sequences.FindIndex(p => p.Name == sequence_name))
: 0;
}
// ---------------------------------------------------------------------
//
// Messages
//
// ---------------------------------------------------------------------
public override void Initialize(Object[] targets) {
base.Initialize(targets);
if ( _matPropBlock == null ) {
_matPropBlock = new MaterialPropertyBlock();
}
if ( _previewUtils == null ) {
_previewUtils = new PreviewRenderUtility();
}
}
public override bool HasPreviewGUI() {
return true;
}
public override void OnPreviewSettings() {
var any_multi_sequences = m_Targets
.OfType<SwfClipAsset>()
.Any(p => p.Sequences != null && p.Sequences.Count > 1);
if ( any_multi_sequences && GUILayout.Button("<", EditorStyles.miniButton) ) {
--_sequence;
}
var sequence_names = m_Targets
.OfType<SwfClipAsset>()
.Select (p => GetSequenceForClip(p, _sequence))
.Where (p => p != null && !string.IsNullOrEmpty(p.Name))
.Select (p => p.Name)
.ToArray();
var label_text = string.Empty;
for ( int i = 0, e = sequence_names.Length; i < e; ++i ) {
label_text += string.Format(
i < e - 1 ? "{0}, " : "{0}",
sequence_names[i]);
}
GUILayout.Label(label_text, EditorStyles.whiteLabel);
if ( any_multi_sequences && GUILayout.Button(">", EditorStyles.miniButton) ) {
++_sequence;
}
}
public override void OnPreviewGUI(Rect r, GUIStyle background) {
if ( Event.current.type == EventType.Repaint ) {
if ( isTargetValidForPreview ) {
_previewUtils.BeginPreview(r, background);
{
_matPropBlock.SetTexture("_MainTex", targetAtlas);
ConfigureCameraForSequence(_previewUtils.m_Camera, targetSequence);
var frame = targetFrame;
for ( var i = 0; i < frame.Materials.Length; ++i ) {
_previewUtils.DrawMesh(
frame.CachedMesh,
Matrix4x4.identity,
frame.Materials[i],
i,
_matPropBlock);
}
_previewUtils.m_Camera.Render();
}
_previewUtils.EndAndDrawPreview(r);
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 61493c5b6491d4432a831d25914ed92a
timeCreated: 1473360782
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +1,6 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Linq;
using System.Collections.Generic;
@@ -10,30 +9,21 @@ namespace FlashTools.Internal {
public class SwfClipControllerEditor : Editor {
List<SwfClipController> _controllers = new List<SwfClipController>();
void AllControllersForeach(Action<SwfClipController> act) {
void AllControllersForeach(System.Action<SwfClipController> act) {
foreach ( var controller in _controllers ) {
act(controller);
}
}
void DrawClipControls() {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
SwfEditorUtils.DoRightHorizontalGUI(() => {
if ( GUILayout.Button("Stop") ) {
AllControllersForeach(p => p.Stop());
}
if ( GUILayout.Button("Pause") ) {
AllControllersForeach(p => p.Pause());
}
if ( GUILayout.Button("Resume") ) {
AllControllersForeach(p => p.Resume());
AllControllersForeach(ctrl => ctrl.Stop(ctrl.isStopped));
}
if ( GUILayout.Button("Play") ) {
AllControllersForeach(p => p.Play());
AllControllersForeach(ctrl => ctrl.Play(ctrl.isPlaying));
}
}
GUILayout.EndHorizontal();
});
}
// ---------------------------------------------------------------------
@@ -43,9 +33,7 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
void OnEnable() {
_controllers = targets
.OfType<SwfClipController>()
.ToList();
_controllers = targets.OfType<SwfClipController>().ToList();
}
public override void OnInspectorGUI() {

View File

@@ -1,19 +1,17 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Linq;
using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfClip)), CanEditMultipleObjects]
public class SwfClipEditor : Editor {
List<SwfClip> _clips = new List<SwfClip>();
List<SwfClip> _clips = new List<SwfClip>();
Dictionary<SwfClip, SwfClipAssetPreview> _previews = new Dictionary<SwfClip, SwfClipAssetPreview>();
void AllClipsForeachWithUndo(Action<SwfClip> act) {
Undo.RecordObjects(
_clips.ToArray(),
"Inspector");
void AllClipsForeachWithUndo(System.Action<SwfClip> act) {
Undo.RecordObjects(_clips.ToArray(), "Inspector");
foreach ( var clip in _clips ) {
act(clip);
EditorUtility.SetDirty(clip);
@@ -46,48 +44,52 @@ namespace FlashTools.Internal {
});
}
bool IsAllClipsHasOneClip() {
foreach ( var clip in _clips ) {
if ( !clip.clip ) {
return false;
}
if ( clip.clip != _clips.First().clip ) {
return false;
}
}
return true;
}
List<string> GetAllSequences(bool include_empty) {
var seq_set = new HashSet<string>(_clips
.Where(p => p.clip)
.SelectMany(p => p.clip.Sequences)
.Select(p => p.Name));
if ( include_empty ) {
seq_set.Add(string.Empty);
var result = new List<string>();
var result_clips = _clips
.Where (p => p.clip && p.clip.Sequences.Count > 0)
.Select(p => p.clip.Sequences)
.Where (p => p.All(s => !string.IsNullOrEmpty(s.Name)))
.ToList();
if ( result_clips.Count > 0 ) {
result = result_clips.First()
.Select(p => p.Name)
.ToList();
var sequences_enum = result_clips
.Select(p => p.Select(s => s.Name));
foreach ( var sequences in sequences_enum ) {
result = result
.Where(p => sequences.Contains(p))
.ToList();
}
if ( include_empty ) {
result.Add(string.Empty);
}
}
return seq_set.ToList();
return result;
}
void DrawSequence() {
if ( IsAllClipsHasOneClip() ) {
var all_sequences = GetAllSequences(true);
if ( all_sequences.Count > 0 ) {
var sequence_prop = SwfEditorUtils.GetPropertyByName(serializedObject, "_sequence");
SwfEditorUtils.DoWithMixedValue(
sequence_prop.hasMultipleDifferentValues, () => {
var all_sequences = GetAllSequences(true);
var sequence_index = EditorGUILayout.Popup(
"Sequence",
sequence_prop.hasMultipleDifferentValues
? all_sequences.FindIndex(p => string.IsNullOrEmpty(p))
: all_sequences.FindIndex(p => p == sequence_prop.stringValue),
all_sequences.ToArray());
var new_sequence = all_sequences[sequence_index];
if ( !string.IsNullOrEmpty(new_sequence) ) {
if ( sequence_prop.hasMultipleDifferentValues ) {
sequence_prop.stringValue = string.Empty;
if ( sequence_index >= 0 && sequence_index < all_sequences.Count ) {
var new_sequence = all_sequences[sequence_index];
if ( !string.IsNullOrEmpty(new_sequence) ) {
if ( sequence_prop.hasMultipleDifferentValues ) {
sequence_prop.stringValue = string.Empty;
}
sequence_prop.stringValue = new_sequence;
sequence_prop.serializedObject.ApplyModifiedProperties();
}
sequence_prop.stringValue = new_sequence;
sequence_prop.serializedObject.ApplyModifiedProperties();
}
});
}
@@ -107,9 +109,7 @@ namespace FlashTools.Internal {
void DrawClipControls() {
EditorGUILayout.Space();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
{
SwfEditorUtils.DoCenterHorizontalGUI(() => {
if ( GUILayout.Button(new GUIContent("<<", "to begin frame")) ) {
AllClipsForeachWithUndo(p => p.ToBeginFrame());
}
@@ -125,9 +125,26 @@ namespace FlashTools.Internal {
if ( GUILayout.Button(new GUIContent(">>", "to end frame")) ) {
AllClipsForeachWithUndo(p => p.ToEndFrame());
}
});
}
void HideMaterials() {
var settings_holder = SwfSettings.GetHolder();
settings_holder.SimpleMaterial .hideFlags = HideFlags.HideInInspector;
settings_holder.IncrMaskMaterial.hideFlags = HideFlags.HideInInspector;
settings_holder.DecrMaskMaterial.hideFlags = HideFlags.HideInInspector;
foreach ( var masked_material in settings_holder.MaskedMaterials ) {
masked_material.hideFlags = HideFlags.HideInInspector;
}
}
void SetupPreviews() {
_previews.Clear();
foreach ( var clip in _clips.Where(p => !!p.clip) ) {
var preview = new SwfClipAssetPreview();
preview.Initialize(new Object[]{clip.clip});
_previews.Add(clip, preview);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
// ---------------------------------------------------------------------
@@ -137,9 +154,9 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
void OnEnable() {
_clips = targets
.OfType<SwfClip>()
.ToList();
_clips = targets.OfType<SwfClip>().ToList();
HideMaterials();
SetupPreviews();
}
public override void OnInspectorGUI() {
@@ -149,6 +166,26 @@ namespace FlashTools.Internal {
DrawCurrentFrame();
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();
SetupPreviews();
}
}
public override bool RequiresConstantRepaint() {
return _previews.Count > 0;
}
public override bool HasPreviewGUI() {
return _previews.Count > 0;
}
public override void OnPreviewGUI(Rect r, GUIStyle background) {
if ( Event.current.type == EventType.Repaint ) {
SwfClipAssetPreview preview;
var clip = target as SwfClip;
if ( _previews.TryGetValue(clip, out preview) ) {
preview.SetCurrentSequence(clip.sequence);
preview.DrawPreview(r);
}
}
}
}

View File

@@ -1,19 +1,76 @@
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace FlashTools.Internal {
[CustomEditor(typeof(SwfManager))]
public class SwfManagerEditor : Editor {
SwfManager _manager = null;
SwfManager _manager = null;
SwfList<SwfClipController> _controllers = new SwfList<SwfClipController>();
bool _groupsFoldout = true;
void DrawAnimationCount() {
void DrawCounts() {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
EditorGUILayout.IntField(
"Clip count",
_manager.AllClipCount);
_manager.clipCount);
EditorGUILayout.IntField(
"Controller count",
_manager.controllerCount);
});
}
void DrawControls() {
SwfEditorUtils.DoRightHorizontalGUI(() => {
if ( _manager.isPaused && GUILayout.Button("Resume") ) {
_manager.Resume();
}
if ( _manager.isPlaying && GUILayout.Button("Pause") ) {
_manager.Pause();
}
});
}
void DrawGroupControls() {
var group_names = GetAllGroupNames();
if ( group_names.Count > 0 ) {
_groupsFoldout = EditorGUILayout.Foldout(_groupsFoldout, "Groups");
if ( _groupsFoldout ) {
foreach ( var group_name in group_names ) {
SwfEditorUtils.DoWithEnabledGUI(false, () => {
EditorGUILayout.TextField("Name", group_name);
});
EditorGUI.BeginChangeCheck();
var new_rate_scale = EditorGUILayout.FloatField(
"Rate Scale", _manager.GetGroupRateScale(group_name));
if ( EditorGUI.EndChangeCheck() ) {
_manager.SetGroupRateScale(group_name, new_rate_scale);
}
SwfEditorUtils.DoRightHorizontalGUI(() => {
if ( _manager.IsGroupPaused(group_name) && GUILayout.Button("Resume") ) {
_manager.ResumeGroup(group_name);
}
if ( _manager.IsGroupPlaying(group_name) && GUILayout.Button("Pause") ) {
_manager.PauseGroup(group_name);
}
});
}
}
}
}
HashSet<string> GetAllGroupNames() {
var result = new HashSet<string>();
for ( int i = 0, e = _controllers.Count; i < e; ++i ) {
var ctrl = _controllers[i];
if ( !string.IsNullOrEmpty(ctrl.groupName) ) {
result.Add(ctrl.groupName);
}
}
return result;
}
// ---------------------------------------------------------------------
//
// Messages
@@ -22,11 +79,20 @@ namespace FlashTools.Internal {
void OnEnable() {
_manager = target as SwfManager;
_manager.GetAllControllers(_controllers);
}
public override void OnInspectorGUI() {
serializedObject.Update();
DrawDefaultInspector();
DrawAnimationCount();
DrawCounts();
if ( Application.isPlaying ) {
DrawControls();
DrawGroupControls();
}
if ( GUI.changed ) {
serializedObject.ApplyModifiedProperties();
}
}
}
}

View File

@@ -26,26 +26,157 @@ namespace FlashTools.Internal {
static void SwfAssetProcess(SwfAsset asset) {
try {
var atlas_asset = LoadAtlasAsset(asset);
if ( atlas_asset != asset.Atlas ) {
asset.Atlas = atlas_asset;
ConfigureAtlas(asset);
ConfigureClips(asset);
if ( asset.Converting.Stage == 0 ) {
var new_data = ConfigureBitmaps(
asset,
SwfEditorUtils.DecompressAsset<SwfAssetData>(asset.Data));
asset.Data = SwfEditorUtils.CompressAsset(new_data);
++asset.Converting.Stage;
EditorUtility.SetDirty(asset);
AssetDatabase.SaveAssets();
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(asset));
} else if ( asset.Converting.Stage == 1 ) {
asset.Atlas = LoadAssetAtlas(asset);
if ( asset.Atlas ) {
ConfigureAtlas(asset);
ConfigureClips(
asset,
SwfEditorUtils.DecompressAsset<SwfAssetData>(asset.Data));
}
++asset.Converting.Stage;
EditorUtility.SetDirty(asset);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(asset));
}
ConfigureAssetClips(asset);
} catch ( Exception e ) {
Debug.LogErrorFormat(
"Postprocess swf asset error: {0}",
"<b>[FlashTools]</b> Postprocess swf asset error: {0}",
e.Message);
SwfEditorUtils.DeleteAssetWithDepends(asset);
AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(asset));
} finally {
if ( asset ) {
UpdateAssetClips(asset);
}
}
}
static Texture2D LoadAtlasAsset(SwfAsset asset) {
static Texture2D LoadAssetAtlas(SwfAsset asset) {
return AssetDatabase.LoadAssetAtPath<Texture2D>(
SwfEditorUtils.GetAtlasPathFromAsset(asset));
GetAtlasPath(asset));
}
static string GetAtlasPath(SwfAsset asset) {
if ( asset.Atlas ) {
return AssetDatabase.GetAssetPath(asset.Atlas);
} else {
var asset_path = AssetDatabase.GetAssetPath(asset);
return Path.ChangeExtension(asset_path, "._Atlas_.png");
}
}
// ---------------------------------------------------------------------
//
// ConfigureBitmaps
//
// ---------------------------------------------------------------------
static SwfAssetData ConfigureBitmaps(SwfAsset asset, SwfAssetData data) {
var textures = data.Bitmaps
.Where (p => p.Redirect == 0)
.Select (p => new KeyValuePair<ushort, Texture2D>(
p.Id,
LoadTextureFromData(p)))
.ToList();
var rects = PackAndSaveBitmapsAtlas(
GetAtlasPath(asset),
textures.Select(p => p.Value).ToArray(),
asset.Settings);
for ( var i = 0; i < data.Bitmaps.Count; ++i ) {
var bitmap = data.Bitmaps[i];
var texture_key = bitmap.Redirect > 0 ? bitmap.Redirect : bitmap.Id;
bitmap.SourceRect = SwfRectData.FromURect(
rects[textures.FindIndex(p => p.Key == texture_key)]);
}
return data;
}
static Texture2D LoadTextureFromData(SwfBitmapData bitmap) {
var texture = new Texture2D(
bitmap.RealWidth, bitmap.RealHeight,
TextureFormat.ARGB32, false);
texture.LoadRawTextureData(bitmap.ARGB32);
return texture;
}
struct BitmapsAtlasInfo {
public Texture2D Atlas;
public Rect[] Rects;
}
static Rect[] PackAndSaveBitmapsAtlas(
string atlas_path, Texture2D[] textures, SwfSettingsData settings)
{
var atlas_info = PackBitmapsAtlas(textures, settings);
RevertTexturePremultipliedAlpha(atlas_info.Atlas);
File.WriteAllBytes(atlas_path, atlas_info.Atlas.EncodeToPNG());
GameObject.DestroyImmediate(atlas_info.Atlas, true);
AssetDatabase.ImportAsset(atlas_path);
return atlas_info.Rects;
}
static BitmapsAtlasInfo PackBitmapsAtlas(
Texture2D[] textures, SwfSettingsData settings)
{
var atlas_padding = Mathf.Max(0, settings.AtlasPadding);
var max_atlas_size = Mathf.Max(32, settings.AtlasPowerOfTwo
? Mathf.ClosestPowerOfTwo(settings.MaxAtlasSize)
: settings.MaxAtlasSize);
var atlas = new Texture2D(0, 0);
var rects = atlas.PackTextures(textures, atlas_padding, max_atlas_size);
while ( rects == null ) {
max_atlas_size = Mathf.NextPowerOfTwo(max_atlas_size + 1);
rects = atlas.PackTextures(textures, atlas_padding, max_atlas_size);
}
return settings.AtlasForceSquare && atlas.width != atlas.height
? BitmapsAtlasToSquare(atlas, rects)
: new BitmapsAtlasInfo{Atlas = atlas, Rects = rects};
}
static BitmapsAtlasInfo BitmapsAtlasToSquare(Texture2D atlas, Rect[] rects) {
var atlas_size = Mathf.Max(atlas.width, atlas.height);
var atlas_scale = new Vector2(atlas.width, atlas.height) / atlas_size;
var new_atlas = new Texture2D(atlas_size, atlas_size, TextureFormat.ARGB32, false);
for ( var i = 0; i < rects.Length; ++i ) {
var new_position = rects[i].position;
new_position.Scale(atlas_scale);
var new_size = rects[i].size;
new_size.Scale(atlas_scale);
rects[i] = new Rect(new_position, new_size);
}
var fill_pixels = new Color32[atlas_size * atlas_size];
for ( var i = 0; i < atlas_size * atlas_size; ++i ) {
fill_pixels[i] = new Color(1,1,1,0);
}
new_atlas.SetPixels32(fill_pixels);
new_atlas.SetPixels32(0, 0, atlas.width, atlas.height, atlas.GetPixels32());
new_atlas.Apply();
GameObject.DestroyImmediate(atlas, true);
return new BitmapsAtlasInfo{
Atlas = new_atlas,
Rects = rects};
}
static void RevertTexturePremultipliedAlpha(Texture2D texture) {
var pixels = texture.GetPixels();
for ( var i = 0; i < pixels.Length; ++i ) {
var c = pixels[i];
if ( c.a > 0 ) {
c.r /= c.a;
c.g /= c.a;
c.b /= c.a;
}
pixels[i] = c;
}
texture.SetPixels(pixels);
texture.Apply();
}
// ---------------------------------------------------------------------
@@ -55,28 +186,21 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
static void ConfigureAtlas(SwfAsset asset) {
var atlas_importer = GetBitmapsAtlasImporter(asset);
var atlas_importer_size = GetSizeFromTextureImporter(atlas_importer);
atlas_importer.spritesheet = asset.Data.Bitmaps
.Select(bitmap => new SpriteMetaData{
name = bitmap.Id.ToString(),
rect = new Rect(
bitmap.SourceRect.xMin * atlas_importer_size.x,
bitmap.SourceRect.yMin * atlas_importer_size.y,
bitmap.SourceRect.width * atlas_importer_size.x,
bitmap.SourceRect.height * atlas_importer_size.y)})
.ToArray();
var atlas_path = AssetDatabase.GetAssetPath(asset.Atlas);
var atlas_importer = GetBitmapsAtlasImporter(asset);
atlas_importer.spritesheet = new SpriteMetaData[0];
atlas_importer.textureType = TextureImporterType.Sprite;
atlas_importer.spriteImportMode = SpriteImportMode.Multiple;
atlas_importer.spritePixelsPerUnit = asset.Settings.PixelsPerUnit;
atlas_importer.mipmapEnabled = asset.Settings.GenerateMipMaps;
atlas_importer.filterMode = SwfAtlasFilterToImporterFilter(asset.Settings.AtlasTextureFilter);
atlas_importer.textureFormat = SwfAtlasFormatToImporterFormat(asset.Settings.AtlasTextureFormat);
AssetDatabase.ImportAsset(SwfEditorUtils.GetAtlasPathFromAsset(asset));
AssetDatabase.WriteImportSettingsIfDirty(atlas_path);
AssetDatabase.ImportAsset(atlas_path);
}
static TextureImporter GetBitmapsAtlasImporter(SwfAsset asset) {
var atlas_path = SwfEditorUtils.GetAtlasPathFromAsset(asset);
var atlas_path = AssetDatabase.GetAssetPath(asset.Atlas);
var atlas_importer = AssetImporter.GetAtPath(atlas_path) as TextureImporter;
if ( !atlas_importer ) {
throw new UnityException(string.Format(
@@ -86,14 +210,6 @@ namespace FlashTools.Internal {
return atlas_importer;
}
static Vector2 GetSizeFromTextureImporter(TextureImporter importer) {
var method_args = new object[2]{0,0};
typeof(TextureImporter)
.GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(importer, method_args);
return new Vector2((int)method_args[0], (int)method_args[1]);
}
static FilterMode SwfAtlasFilterToImporterFilter(
SwfSettingsData.AtlasFilter filter)
{
@@ -136,44 +252,45 @@ namespace FlashTools.Internal {
//
// ---------------------------------------------------------------------
static void ConfigureClips(SwfAsset asset) {
foreach ( var symbol in asset.Data.Symbols ) {
ConfigureClip(asset, symbol);
static SwfAssetData ConfigureClips(SwfAsset asset, SwfAssetData data) {
asset.Clips = asset.Clips.Where(p => !!p).ToList();
foreach ( var symbol in data.Symbols ) {
ConfigureClip(asset, data, symbol);
}
return data;
}
static void ConfigureClip(SwfAsset asset, SwfAssetData data, SwfSymbolData symbol) {
var clip_asset = asset.Clips.FirstOrDefault(p => p.Name == symbol.Name);
if ( clip_asset ) {
ConfigureClipAsset(clip_asset, asset, data, symbol);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(clip_asset));
} else {
var asset_path = AssetDatabase.GetAssetPath(asset);
var clip_asset_path = Path.ChangeExtension(asset_path, symbol.Name + ".asset");
SwfEditorUtils.LoadOrCreateAsset<SwfClipAsset>(clip_asset_path, new_clip_asset => {
ConfigureClipAsset(new_clip_asset, asset, data, symbol);
asset.Clips.Add(new_clip_asset);
});
}
}
static void ConfigureClip(SwfAsset asset, SwfSymbolData symbol) {
var clip_asset_path = Path.ChangeExtension(
AssetDatabase.GetAssetPath(asset),
symbol.Name + ".asset");
var clip_asset = SwfEditorUtils
.LoadOrCreateAsset<SwfClipAsset>(clip_asset_path);
static void ConfigureClipAsset(
SwfClipAsset clip_asset, SwfAsset asset, SwfAssetData data, SwfSymbolData symbol)
{
clip_asset.Name = symbol.Name;
clip_asset.Atlas = asset.Atlas;
clip_asset.FrameRate = asset.Data.FrameRate;
clip_asset.Sequences = LoadClipSequences(asset, symbol);
ConfigureClipSubAssets(clip_asset);
asset.Clips.Add(clip_asset);
}
static void ConfigureClipSubAssets(SwfClipAsset clip_asset) {
SwfEditorUtils.RemoveAllSubAssets(
AssetDatabase.GetAssetPath(clip_asset));
foreach ( var sequence in clip_asset.Sequences ) {
for ( var i = 0; i < sequence.Frames.Count; ++i ) {
var mesh = sequence.Frames[i].Mesh;
mesh.name = string.Format("{0}_{1}", sequence.Name, i);
AssetDatabase.AddObjectToAsset(mesh, clip_asset);
}
}
clip_asset.FrameRate = data.FrameRate;
clip_asset.Sequences = LoadClipSequences(asset, data, symbol);
}
static List<SwfClipAsset.Sequence> LoadClipSequences(
SwfAsset asset, SwfSymbolData symbol)
SwfAsset asset, SwfAssetData data, SwfSymbolData symbol)
{
var sequences = new List<SwfClipAsset.Sequence>();
if ( IsValidAssetsForFrame(asset, symbol) ) {
foreach ( var frame in symbol.Frames ) {
var baked_frame = BakeClipFrame(asset, frame);
var baked_frame = BakeClipFrame(asset, data, frame);
if ( !string.IsNullOrEmpty(frame.Name) &&
(sequences.Count < 1 || sequences.Last().Name != frame.Name) )
{
@@ -198,39 +315,39 @@ namespace FlashTools.Internal {
class BakedGroup {
public SwfInstanceData.Types Type;
public int ClipDepth;
public List<int> Triangles;
public int StartVertex;
public int TriangleCount;
public Material Material;
}
static SwfClipAsset.Frame BakeClipFrame(
SwfAsset asset, SwfFrameData frame)
SwfAsset asset, SwfAssetData data, SwfFrameData frame)
{
List<Vector2> baked_uvs = new List<Vector2>();
List<Color> baked_mulcolors = new List<Color>();
List<Vector4> baked_addcolors = new List<Vector4>();
List<Vector3> baked_vertices = new List<Vector3>();
List<uint> baked_uvs = new List<uint>();
List<uint> baked_mulcolors = new List<uint>();
List<uint> baked_addcolors = new List<uint>();
List<Vector2> baked_vertices = new List<Vector2>();
List<BakedGroup> baked_groups = new List<BakedGroup>();
List<Material> baked_materials = new List<Material>();
foreach ( var inst in frame.Instances ) {
var bitmap = inst != null
? FindBitmapFromAssetData(asset.Data, inst.Bitmap)
? FindBitmapFromAssetData(data, inst.Bitmap)
: null;
if ( bitmap != null ) {
var width = bitmap.RealSize.x / 20.0f;
var height = bitmap.RealSize.y / 20.0f;
if ( bitmap != null && IsVisibleInstance(inst) ) {
var width = bitmap.RealWidth / 20.0f;
var height = bitmap.RealHeight / 20.0f;
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);
var v0 = new Vector2( 0, 0);
var v1 = new Vector2(width, 0);
var v2 = new Vector2(width, height);
var v3 = new Vector2( 0, height);
var matrix =
Matrix4x4.Scale(new Vector3(
+1.0f / asset.Settings.PixelsPerUnit,
-1.0f / asset.Settings.PixelsPerUnit,
+1.0f / asset.Settings.PixelsPerUnit)) *
inst.Matrix;
Matrix4x4.Scale(
new Vector3(1.0f, -1.0f, 1.0f) /
asset.Settings.PixelsPerUnit) *
inst.Matrix.ToUMatrix();
baked_vertices.Add(matrix.MultiplyPoint3x4(v0));
baked_vertices.Add(matrix.MultiplyPoint3x4(v1));
@@ -238,39 +355,37 @@ namespace FlashTools.Internal {
baked_vertices.Add(matrix.MultiplyPoint3x4(v3));
var source_rect = bitmap.SourceRect;
baked_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMin));
baked_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMin));
baked_uvs.Add(new Vector2(source_rect.xMax, source_rect.yMax));
baked_uvs.Add(new Vector2(source_rect.xMin, source_rect.yMax));
baked_uvs.Add(SwfUtils.PackUV(source_rect.xMin, source_rect.yMin));
baked_uvs.Add(SwfUtils.PackUV(source_rect.xMax, source_rect.yMax));
baked_mulcolors.Add(inst.ColorTrans.Mul);
baked_mulcolors.Add(inst.ColorTrans.Mul);
baked_mulcolors.Add(inst.ColorTrans.Mul);
baked_mulcolors.Add(inst.ColorTrans.Mul);
uint mul_pack0, mul_pack1;
SwfUtils.PackFColorToUInts(
inst.ColorTrans.mulColor,
out mul_pack0, out mul_pack1);
baked_mulcolors.Add(mul_pack0);
baked_mulcolors.Add(mul_pack1);
baked_addcolors.Add(inst.ColorTrans.Add);
baked_addcolors.Add(inst.ColorTrans.Add);
baked_addcolors.Add(inst.ColorTrans.Add);
baked_addcolors.Add(inst.ColorTrans.Add);
uint add_pack0, add_pack1;
SwfUtils.PackFColorToUInts(
inst.ColorTrans.addColor,
out add_pack0, out add_pack1);
baked_addcolors.Add(add_pack0);
baked_addcolors.Add(add_pack1);
if ( baked_groups.Count == 0 ||
baked_groups[baked_groups.Count - 1].Type != inst.Type ||
baked_groups[baked_groups.Count - 1].ClipDepth != inst.ClipDepth )
{
baked_groups.Add(new BakedGroup{
Type = inst.Type,
ClipDepth = inst.ClipDepth,
Triangles = new List<int>(),
Material = null
Type = inst.Type,
ClipDepth = inst.ClipDepth,
StartVertex = baked_vertices.Count - 4,
TriangleCount = 0,
Material = null
});
}
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 2);
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 1);
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 0);
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 0);
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 3);
baked_groups.Last().Triangles.Add(baked_vertices.Count - 4 + 2);
baked_groups.Last().TriangleCount += 6;
}
}
@@ -296,7 +411,6 @@ namespace FlashTools.Internal {
group.Type));
}
if ( group.Material ) {
group.Material.hideFlags = HideFlags.HideInInspector;
baked_materials.Add(group.Material);
} else {
throw new UnityException(string.Format(
@@ -305,20 +419,20 @@ namespace FlashTools.Internal {
}
}
var mesh = new Mesh();
mesh.subMeshCount = baked_groups.Count;
mesh.SetVertices(baked_vertices);
for ( var i = 0; i < baked_groups.Count; ++i ) {
mesh.SetTriangles(baked_groups[i].Triangles, i);
}
mesh.SetUVs(0, baked_uvs);
mesh.SetUVs(1, baked_addcolors);
mesh.SetColors(baked_mulcolors);
mesh.RecalculateNormals();
var mesh_data = new SwfClipAsset.MeshData{
SubMeshes = baked_groups
.Select(p => new SwfClipAsset.SubMeshData{
StartVertex = p.StartVertex,
IndexCount = p.TriangleCount})
.ToArray(),
Vertices = baked_vertices .ToArray(),
UVs = baked_uvs .ToArray(),
AddColors = baked_addcolors.ToArray(),
MulColors = baked_mulcolors.ToArray()};
return new SwfClipAsset.Frame{
Mesh = mesh,
Materials = baked_materials.ToArray()};
return new SwfClipAsset.Frame(
mesh_data,
baked_materials.ToArray());
}
static SwfBitmapData FindBitmapFromAssetData(SwfAssetData data, int bitmap_id) {
@@ -331,14 +445,19 @@ namespace FlashTools.Internal {
return null;
}
static bool IsVisibleInstance(SwfInstanceData inst) {
var result_color = inst.ColorTrans.ApplyToColor(Color.white);
return result_color.a >= 0.01f;
}
// ---------------------------------------------------------------------
//
// ConfigureAssetClips
// UpdateAssetClips
//
// ---------------------------------------------------------------------
static void ConfigureAssetClips(SwfAsset asset) {
var clips = GameObject.FindObjectsOfType<SwfClip>();
static void UpdateAssetClips(SwfAsset asset) {
var clips = Resources.FindObjectsOfTypeAll<SwfClip>();
foreach ( var clip in clips ) {
if ( clip && clip.clip && asset.Clips.Contains(clip.clip) ) {
clip.UpdateAllProperties();

View File

@@ -26,46 +26,38 @@ namespace FlashTools.Internal {
static void SwfFileProcess(string swf_path) {
var swf_asset_path = Path.ChangeExtension(swf_path, ".asset");
var swf_asset = AssetDatabase.LoadAssetAtPath<SwfAsset>(swf_asset_path);
if ( !swf_asset ) {
swf_asset = ScriptableObject.CreateInstance<SwfAsset>();
AssetDatabase.CreateAsset(swf_asset, swf_asset_path);
}
if ( LoadSwfAsset(swf_path, swf_asset) ) {
EditorUtility.SetDirty(swf_asset);
AssetDatabase.SaveAssets();
} else {
SwfEditorUtils.DeleteAssetWithDepends(swf_asset);
}
SwfEditorUtils.LoadOrCreateAsset<SwfAsset>(swf_asset_path, swf_asset => {
SafeLoadSwfAsset(swf_path, swf_asset);
});
}
static bool LoadSwfAsset(string swf_path, SwfAsset swf_asset) {
static void SafeLoadSwfAsset(string swf_path, SwfAsset swf_asset) {
try {
if ( swf_asset.Atlas ) {
AssetDatabase.DeleteAsset(
AssetDatabase.GetAssetPath(swf_asset.Atlas));
swf_asset.Atlas = null;
}
swf_asset.Data = LoadSwfAssetData(
swf_asset,
new SwfDecoder(swf_path));
return true;
var new_data = LoadSwfAssetData(swf_path);
swf_asset.Data = SwfEditorUtils.CompressAsset(new_data);
swf_asset.Converting = new SwfAsset.ConvertingState();
} catch ( Exception e ) {
Debug.LogErrorFormat("Parsing swf error: {0}", e.Message);
return false;
Debug.LogErrorFormat(
"<b>[FlashTools]</b> Parsing swf error: {0}",
e.Message);
}
}
static SwfAssetData LoadSwfAssetData(
SwfAsset swf_asset, SwfDecoder swf_decoder)
{
static SwfAssetData LoadSwfAssetData(string swf_path) {
var library = new SwfLibrary();
var decoder = new SwfDecoder(swf_path);
return new SwfAssetData{
FrameRate = swf_decoder.UncompressedHeader.FrameRate,
Symbols = LoadSymbols(library, swf_decoder),
Bitmaps = LoadBitmaps(library, swf_asset)};
FrameRate = decoder.UncompressedHeader.FrameRate,
Symbols = LoadSymbols(library, decoder),
Bitmaps = LoadBitmaps(library)};
}
// ---------------------------------------------------------------------
//
// LoadSymbols
//
// ---------------------------------------------------------------------
static List<SwfSymbolData> LoadSymbols(
SwfLibrary library, SwfDecoder decoder)
{
@@ -125,7 +117,7 @@ namespace FlashTools.Internal {
var self_masks = new List<SwfInstanceData>();
foreach ( var inst in display_list.Instances.Values.Where(p => p.Visible) ) {
CheckSelfMasks(self_masks, inst.Depth, frame);
var child_matrix = parent_matrix * inst.Matrix.ToUnityMatrix();
var child_matrix = parent_matrix * inst.Matrix.ToUMatrix();
var child_color_transform = parent_color_transform * inst.ColorTransform.ToColorTransData();
switch ( inst.Type ) {
case SwfDisplayInstanceType.Shape:
@@ -152,7 +144,7 @@ namespace FlashTools.Internal {
Type = frame_inst_type,
ClipDepth = (ushort)frame_inst_clip_depth,
Bitmap = bitmap_id,
Matrix = child_matrix * bitmap_matrix.ToUnityMatrix(),
Matrix = SwfMatrixData.FromUMatrix(child_matrix * bitmap_matrix.ToUMatrix()),
ColorTrans = child_color_transform});
if ( parent_mask > 0 ) {
parent_masks.Add(frame.Instances[frame.Instances.Count - 1]);
@@ -180,7 +172,7 @@ namespace FlashTools.Internal {
break;
default:
throw new UnityException(string.Format(
"Unsupported SwfDisplayInstanceType: {0}", inst.Type));
"unsupported SwfDisplayInstanceType: {0}", inst.Type));
}
}
CheckSelfMasks(self_masks, ushort.MaxValue, frame);
@@ -203,105 +195,23 @@ namespace FlashTools.Internal {
masks.RemoveAll(p => p.ClipDepth < depth);
}
static List<SwfBitmapData> LoadBitmaps(
SwfLibrary library, SwfAsset asset)
{
var bitmap_defines = library.Defines
// ---------------------------------------------------------------------
//
// LoadBitmaps
//
// ---------------------------------------------------------------------
static List<SwfBitmapData> LoadBitmaps(SwfLibrary library) {
return library.Defines
.Where (p => p.Value.Type == SwfLibraryDefineType.Bitmap)
.ToDictionary(p => p.Key, p => p.Value as SwfLibraryBitmapDefine);
var textures = bitmap_defines
.Where (p => p.Value.Redirect == 0)
.Select (p => new KeyValuePair<int, Texture2D>(
p.Key, LoadTextureFromBitmapDefine(p.Value)))
.ToDictionary(p => p.Key, p => p.Value as SwfLibraryBitmapDefine)
.Select (p => new SwfBitmapData{
Id = p.Key,
ARGB32 = p.Value.ARGB32,
Redirect = p.Value.Redirect,
RealWidth = p.Value.Width,
RealHeight = p.Value.Height})
.ToList();
var rects = PackAndSaveBitmapsAtlas(asset, textures.Select(p => p.Value).ToArray());
var bitmaps = new List<SwfBitmapData>(bitmap_defines.Count);
foreach ( var bitmap_define in bitmap_defines ) {
var texture_key = bitmap_define.Value.Redirect > 0
? bitmap_define.Value.Redirect
: bitmap_define.Key;
var bitmap_data = new SwfBitmapData{
Id = bitmap_define.Key,
RealSize = new Vector2(bitmap_define.Value.Width, bitmap_define.Value.Height),
SourceRect = rects[textures.FindIndex(p => p.Key == texture_key)]};
bitmaps.Add(bitmap_data);
}
return bitmaps;
}
static Texture2D LoadTextureFromBitmapDefine(SwfLibraryBitmapDefine bitmap) {
var texture = new Texture2D(
bitmap.Width, bitmap.Height,
TextureFormat.ARGB32, false);
texture.LoadRawTextureData(bitmap.ARGB32);
RevertTexturePremultipliedAlpha(texture);
return texture;
}
static void RevertTexturePremultipliedAlpha(Texture2D texture) {
for ( int y = 0; y < texture.height; ++y ) {
for ( int x = 0; x < texture.width; ++x ) {
var c = texture.GetPixel(x, y);
if ( c.a > 0 ) {
c.r /= c.a;
c.g /= c.a;
c.b /= c.a;
}
texture.SetPixel(x, y, c);
}
}
texture.Apply();
}
struct BitmapsAtlasInfo {
public Texture2D Atlas;
public Rect[] Rects;
}
static Rect[] PackAndSaveBitmapsAtlas(SwfAsset asset, Texture2D[] textures) {
var atlas_info = PackBitmapsAtlas(textures, asset.Settings);
var atlas_path = SwfEditorUtils.GetAtlasPathFromAsset(asset);
File.WriteAllBytes(atlas_path, atlas_info.Atlas.EncodeToPNG());
GameObject.DestroyImmediate(atlas_info.Atlas, true);
AssetDatabase.ImportAsset(atlas_path);
return atlas_info.Rects;
}
static BitmapsAtlasInfo PackBitmapsAtlas(Texture2D[] textures, SwfSettingsData settings) {
var atlas_padding = Mathf.Max(0, settings.AtlasPadding);
var max_atlas_size = Mathf.Max(32, settings.AtlasPowerOfTwo
? Mathf.ClosestPowerOfTwo(settings.MaxAtlasSize)
: settings.MaxAtlasSize);
var atlas = new Texture2D(0, 0);
var rects = atlas.PackTextures(textures, atlas_padding, max_atlas_size);
if ( rects == null ) {
throw new UnityException("Pack textures to atlas error");
}
return settings.AtlasForceSquare && atlas.width != atlas.height
? BitmapsAtlasToSquare(atlas, rects)
: new BitmapsAtlasInfo{Atlas = atlas, Rects = rects};
}
static BitmapsAtlasInfo BitmapsAtlasToSquare(Texture2D atlas, Rect[] rects) {
var atlas_size = Mathf.Max(atlas.width, atlas.height);
var atlas_scale = new Vector2(atlas.width, atlas.height) / atlas_size;
var new_atlas = new Texture2D(atlas_size, atlas_size, TextureFormat.ARGB32, false);
for ( var i = 0; i < rects.Length; ++i ) {
var new_position = rects[i].position;
new_position.Scale(atlas_scale);
var new_size = rects[i].size;
new_size.Scale(atlas_scale);
rects[i] = new Rect(new_position, new_size);
}
var fill_pixels = new Color32[atlas_size * atlas_size];
for ( var i = 0; i < atlas_size * atlas_size; ++i ) {
fill_pixels[i] = new Color(1,1,1,0);
}
new_atlas.SetPixels32(fill_pixels);
new_atlas.SetPixels32(0, 0, atlas.width, atlas.height, atlas.GetPixels32());
new_atlas.Apply();
GameObject.DestroyImmediate(atlas, true);
return new BitmapsAtlasInfo{Atlas = new_atlas, Rects = rects};
}
}
}

View File

@@ -2,10 +2,21 @@
using UnityEditor;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using Ionic.Zlib;
namespace FlashTools.Internal {
public static class SwfEditorUtils {
// ---------------------------------------------------------------------
//
// Functions
//
// ---------------------------------------------------------------------
public static void DoWithMixedValue(bool mixed, System.Action act) {
var last_show_mixed_value = EditorGUI.showMixedValue;
EditorGUI.showMixedValue = mixed;
@@ -17,12 +28,41 @@ namespace FlashTools.Internal {
}
public static void DoWithEnabledGUI(bool enabled, System.Action act) {
var last_gui_enabled = GUI.enabled;
GUI.enabled = enabled;
EditorGUI.BeginDisabledGroup(true);
try {
act();
} finally {
GUI.enabled = last_gui_enabled;
EditorGUI.EndDisabledGroup();
}
}
public static void DoHorizontalGUI(System.Action act) {
GUILayout.BeginHorizontal();
try {
act();
} finally {
GUILayout.EndHorizontal();
}
}
public static void DoRightHorizontalGUI(System.Action act) {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
try {
act();
} finally {
GUILayout.EndHorizontal();
}
}
public static void DoCenterHorizontalGUI(System.Action act) {
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
try {
act();
} finally {
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
@@ -36,17 +76,6 @@ namespace FlashTools.Internal {
return prop;
}
public static void DeleteAssetWithDepends(SwfAsset asset) {
if ( asset ) {
if ( asset.Atlas ) {
AssetDatabase.DeleteAsset(
AssetDatabase.GetAssetPath(asset.Atlas));
}
AssetDatabase.DeleteAsset(
AssetDatabase.GetAssetPath(asset));
}
}
public static void RemoveAllSubAssets(string asset_path) {
var assets = AssetDatabase.LoadAllAssetsAtPath(asset_path);
foreach ( var asset in assets ) {
@@ -56,18 +85,76 @@ namespace FlashTools.Internal {
}
}
public static T LoadOrCreateAsset<T>(string asset_path) where T : ScriptableObject {
public static T LoadOrCreateAsset<T>(string asset_path, System.Action<T> act) where T : ScriptableObject {
var asset = AssetDatabase.LoadAssetAtPath<T>(asset_path);
if ( !asset ) {
if ( asset ) {
act(asset);
} else {
asset = ScriptableObject.CreateInstance<T>();
act(asset);
AssetDatabase.CreateAsset(asset, asset_path);
}
AssetDatabase.ImportAsset(asset_path);
return asset;
}
public static string GetAtlasPathFromAsset(SwfAsset asset) {
var asset_path = AssetDatabase.GetAssetPath(asset);
return Path.ChangeExtension(asset_path, "._Atlas_.png");
public static byte[] CompressAsset<T>(T asset) {
var bytes = AssetToBytes(asset);
var result = ZlibStream.CompressBuffer(bytes);
return result;
}
public static T DecompressAsset<T>(byte[] data) {
var bytes = ZlibStream.UncompressBuffer(data);
var result = BytesToAsset<T>(bytes);
return result;
}
static byte[] AssetToBytes<T>(T asset) {
var formatter = new BinaryFormatter();
using ( var stream = new MemoryStream() ) {
formatter.Serialize(stream, asset);
return stream.ToArray();
}
}
static T BytesToAsset<T>(byte[] bytes) {
var formatter = new BinaryFormatter();
using ( var stream = new MemoryStream(bytes) ) {
return (T)formatter.Deserialize(stream);
}
}
// ---------------------------------------------------------------------
//
// Internal
//
// ---------------------------------------------------------------------
[MenuItem("Tools/FlashTools/Open settings...")]
static void Tools_FlashTools_OpenSettings() {
var settings_holder = SwfSettings.GetHolder();
Selection.objects = new Object[]{settings_holder};
}
[MenuItem("Tools/FlashTools/Reimport all swf files")]
static void Tools_FlashTools_ReimportAllSwfFiles() {
var swf_paths = GetAllSwfFilePaths();
var title = "Reimport";
var message = string.Format(
"Do you really want to reimport all ({0}) swf files?",
swf_paths.Length);
if ( EditorUtility.DisplayDialog(title, message, "Ok", "Cancel") ) {
foreach ( var swf_path in swf_paths ) {
AssetDatabase.ImportAsset(swf_path);
}
}
}
static string[] GetAllSwfFilePaths() {
return AssetDatabase.GetAllAssetPaths()
.Where(p => Path.GetExtension(p).ToLower().Equals(".swf"))
.ToArray();
}
}
}

View File

@@ -4,7 +4,7 @@ using UnityEditor;
using System.Linq;
using System.Collections.Generic;
namespace FlashTools.Internal.SwfEditorTools {
namespace FlashTools.Internal {
//
// SwfIntRange
@@ -103,6 +103,7 @@ namespace FlashTools.Internal.SwfEditorTools {
if ( property.propertyType == SerializedPropertyType.String ) {
var all_sorting_layers = GetAllSortingLayers(false);
if ( !all_sorting_layers.Contains(property.stringValue) ) {
property.stringValue = string.Empty;
property.stringValue = DefaultLayerName;
property.serializedObject.ApplyModifiedProperties();
}
@@ -117,6 +118,8 @@ namespace FlashTools.Internal.SwfEditorTools {
ValidateProperty(property);
SwfEditorUtils.DoWithMixedValue(
property.hasMultipleDifferentValues, () => {
label = EditorGUI.BeginProperty(position, label, property);
EditorGUI.BeginChangeCheck();
var all_sorting_layers = GetAllSortingLayers(true);
var sorting_layer_index = EditorGUI.Popup(
position,
@@ -125,14 +128,20 @@ namespace FlashTools.Internal.SwfEditorTools {
? all_sorting_layers.FindIndex(p => string.IsNullOrEmpty(p))
: all_sorting_layers.FindIndex(p => p == property.stringValue),
all_sorting_layers.Select(p => new GUIContent(p)).ToArray());
var new_value = all_sorting_layers[sorting_layer_index];
if ( !string.IsNullOrEmpty(new_value) ) {
if ( property.hasMultipleDifferentValues ) {
property.stringValue = string.Empty;
if ( EditorGUI.EndChangeCheck() ) {
if ( sorting_layer_index >= 0 && sorting_layer_index < all_sorting_layers.Count ) {
var new_value = all_sorting_layers[sorting_layer_index];
if ( !string.IsNullOrEmpty(new_value) ) {
if ( property.hasMultipleDifferentValues ) {
property.stringValue = string.Empty;
}
property.stringValue = new_value;
property.serializedObject.ApplyModifiedProperties();
}
}
property.stringValue = new_value;
property.serializedObject.ApplyModifiedProperties();
}});
}
EditorGUI.EndProperty();
});
} else {
EditorGUI.LabelField(position, label.text, "Use SwfSortingLayer with string attribute.");
}
@@ -203,7 +212,8 @@ namespace FlashTools.Internal.SwfEditorTools {
EditorGUI.IntPopup(position, property, vnames, values, label);
} else {
EditorGUI.PropertyField(position, property, label, true);
}});
}
});
} else {
EditorGUI.LabelField(position, label.text, "Use SwfPowerOfTwoIf with integer attribute.");
}
@@ -239,6 +249,7 @@ namespace FlashTools.Internal.SwfEditorTools {
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);
@@ -252,6 +263,7 @@ namespace FlashTools.Internal.SwfEditorTools {
property.stringValue = AssetDatabase.AssetPathToGUID(new_asset_path);
property.serializedObject.ApplyModifiedProperties();
}
EditorGUI.EndProperty();
});
});
} else {
@@ -259,4 +271,23 @@ namespace FlashTools.Internal.SwfEditorTools {
}
}
}
//
// SwfDisplayNameDrawer
//
[CustomPropertyDrawer(typeof(SwfDisplayNameAttribute))]
public class SwfDisplayNameDrawer : PropertyDrawer {
public override void OnGUI(
Rect position, SerializedProperty property, GUIContent label)
{
var new_label = new GUIContent(label);
new_label.text = (attribute as SwfDisplayNameAttribute).DisplayName;
if ( EditorGUI.PropertyField(position, property, new_label) ) {
foreach ( SerializedProperty child in property ) {
EditorGUILayout.PropertyField(child);
}
}
}
}
}

View File

@@ -364,7 +364,9 @@ namespace FlashTools.Internal.SwfTools {
void TagToDebugLog(SwfTagBase tag) {
if ( tag is UnsupportedTag || tag is UnknownTag ) {
Debug.LogWarningFormat("SwfContextExecuter. {0}", tag);
Debug.LogWarningFormat(
"<b>[FlashTools]</b> SwfContextExecuter. {0}",
tag);
}
}
}

View File

@@ -34,21 +34,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
"SwfColor. R: {0}, G: {1}, B: {2}, A: {3}",
R, G, B, A);
}
public Color ToUnityColor() {
return new Color(
R / 255.0f,
G / 255.0f,
B / 255.0f,
A / 255.0f);
}
public Color32 ToUnityColor32() {
return new Color32(
R,
G,
B,
A);
}
}
}

View File

@@ -62,18 +62,18 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
public SwfColorTransData ToColorTransData() {
var trans = SwfColorTransData.identity;
if ( HasAdd ) {
trans.Add = new Vector4(
RAdd / 255.0f,
GAdd / 255.0f,
BAdd / 255.0f,
AAdd / 255.0f);
trans.addColor = new SwfVec4Data(
RAdd / 256.0f,
GAdd / 256.0f,
BAdd / 256.0f,
AAdd / 256.0f);
}
if ( HasMul ) {
trans.Mul = new Vector4(
RMul / 255.0f,
GMul / 255.0f,
BMul / 255.0f,
AMul / 255.0f);
trans.mulColor = new SwfVec4Data(
RMul / 256.0f,
GMul / 256.0f,
BMul / 256.0f,
AMul / 256.0f);
}
return trans;
}

View File

@@ -59,7 +59,7 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
TranslateX, TranslateY);
}
public Matrix4x4 ToUnityMatrix() {
public Matrix4x4 ToUMatrix() {
var mat = Matrix4x4.identity;
mat.m00 = ScaleX;
mat.m10 = RotateSkew0;

View File

@@ -37,11 +37,5 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
"XMin: {0}, XMax: {1}, YMin: {2}, YMax: {3}",
XMin, XMax, YMin, YMax);
}
public Rect ToUnityRect() {
return Rect.MinMaxRect(
XMin, YMin,
XMax, YMax);
}
}
}

View File

@@ -114,7 +114,7 @@ namespace FlashTools.Internal.SwfTools.SwfTypes {
fill_style.BitmapMatrix = SwfMatrix.Read(reader, true);
} else {
Debug.LogError(
"imported .swf file contains vector graphics. " +
"<b>[FlashTools]</b> Imported .swf file contains vector graphics. " +
"You should use Tools/FlashExport.jsfl script for prepare .fla file");
}
return fill_style;

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8e21e87290a7a4488ac2343d6defe08f
folderAsset: yes
timeCreated: 1473785847
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using UnityEngine;
using NUnit.Framework;
namespace FlashTools.Internal.Tests {
public static class SwfUtilsTests {
static void AssertAreEqualVectors(Vector2 v0, Vector2 v1, float delta) {
Assert.AreEqual(v0.x, v1.x, delta);
Assert.AreEqual(v0.y, v1.y, delta);
}
static void AssertAreEqualVectors(Vector4 v0, Vector4 v1, float delta) {
Assert.AreEqual(v0.x, v1.x, delta);
Assert.AreEqual(v0.y, v1.y, delta);
Assert.AreEqual(v0.z, v1.z, delta);
Assert.AreEqual(v0.w, v1.w, delta);
}
//
//
//
[Test]
public static void PackUShortsToUIntTests() {
ushort v0 = 11, v1 = 99;
ushort o0, o1;
SwfUtils.UnpackUShortsFromUInt(
SwfUtils.PackUShortsToUInt(v0, v1), out o0, out o1);
Assert.AreEqual(v0, o0);
Assert.AreEqual(v1, o1);
ushort v2 = 16789, v3 = 31234;
ushort o2, o3;
SwfUtils.UnpackUShortsFromUInt(
SwfUtils.PackUShortsToUInt(v2, v3), out o2, out o3);
Assert.AreEqual(v2, o2);
Assert.AreEqual(v3, o3);
}
[Test]
public static void PackUVTests() {
var v0 = new Vector2(0.9999f, 0.1111f);
float u0, u1;
SwfUtils.UnpackUV(SwfUtils.PackUV(v0.x, v0.y), out u0, out u1);
AssertAreEqualVectors(v0, new Vector2(u0, u1), SwfUtils.UVPrecision);
var v1 = new Vector2(0.0987f, 0.0123f);
float u2, u3;
SwfUtils.UnpackUV(SwfUtils.PackUV(v1.x, v1.y), out u2, out u3);
AssertAreEqualVectors(v1, new Vector2(u2, u3), SwfUtils.UVPrecision);
var v2 = new Vector2(1.0f, 0.0f);
float u4, u5;
SwfUtils.UnpackUV(SwfUtils.PackUV(v2.x, v2.y), out u4, out u5);
AssertAreEqualVectors(v2, new Vector2(u4, u5), SwfUtils.UVPrecision);
}
[Test]
public static void PackFloatColorToUShortTests() {
float v0 = -5.678f;
Assert.AreEqual(
v0,
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v0)),
SwfUtils.FColorPrecision);
float v1 = 60.678f;
Assert.AreEqual(
v1,
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v1)),
SwfUtils.FColorPrecision);
float v2 = 0.678f;
Assert.AreEqual(
v2,
SwfUtils.UnpackFloatColorFromUShort(SwfUtils.PackFloatColorToUShort(v2)),
SwfUtils.FColorPrecision);
}
[Test]
public static void PackColorToUIntsTests() {
var v0 = new Color(0.01f, 0.02f, 0.33f, 1.0f);
uint u0, u1;
SwfUtils.PackFColorToUInts(v0, out u0, out u1);
Color c0;
SwfUtils.UnpackFColorFromUInts(
u0, u1,
out c0.r, out c0.g, out c0.b, out c0.a);
AssertAreEqualVectors(
v0, c0, SwfUtils.FColorPrecision);
var v1 = new Vector4(0.01f, 0.02f, 0.33f, 1.0f);
uint u2, u3;
SwfUtils.PackFColorToUInts(v1, out u2, out u3);
Vector4 c1;
SwfUtils.UnpackFColorFromUInts(
u2, u3,
out c1.x, out c1.y, out c1.z, out c1.w);
AssertAreEqualVectors(
v1, c1, SwfUtils.FColorPrecision);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 56c243ac3822b44ffa1520cfc5471e75
timeCreated: 1473785856
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -62,5 +62,9 @@ namespace FlashTools.Internal {
_list.Clear();
_dict.Clear();
}
public void AssignTo(SwfList<T> list) {
_list.AssignTo(list);
}
}
}

View File

@@ -42,4 +42,11 @@ namespace FlashTools.Internal {
ReadOnly = read_only;
}
}
public class SwfDisplayNameAttribute : PropertyAttribute {
public string DisplayName;
public SwfDisplayNameAttribute(string display_name) {
DisplayName = display_name;
}
}
}

View File

@@ -106,5 +106,22 @@ namespace FlashTools.Internal {
}
}
}
public void AssignTo(SwfList<T> list) {
if ( list._data.Length < _size ) {
var new_data = new T[_size * 2];
Array.Copy(_data, new_data, _size);
list._data = new_data;
list._size = _size;
} else {
if ( _size < list._size ) {
Array.Clear(list._data, _size, list._size - _size);
}
if ( _size > 0 ) {
Array.Copy(_data, list._data, _size);
}
list._size = _size;
}
}
}
}

View File

@@ -73,7 +73,7 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
//
// Private
// Internal
//
// ---------------------------------------------------------------------
@@ -136,7 +136,7 @@ namespace FlashTools.Internal {
// ---------------------------------------------------------------------
public Material GetMaskedMaterial(int stencil_id) {
if ( MaskedMaterials == null || stencil_id < MaskedMaterials.Count ) {
if ( MaskedMaterials == null || stencil_id >= MaskedMaterials.Count ) {
FillMaterialsCache();
}
if ( stencil_id < 0 || stencil_id >= MaskedMaterials.Count ) {

View File

@@ -0,0 +1,100 @@
using UnityEngine;
namespace FlashTools.Internal {
public static class SwfUtils {
public const float UVPrecision = 1.0f / 16384.0f;
public const float FColorPrecision = 1.0f / 512.0f;
const ushort UShortMax = ushort.MaxValue;
const float InvFColorPrecision = 1.0f / FColorPrecision;
//
//
//
public static uint PackUShortsToUInt(ushort x, ushort y) {
var xx = (uint)x;
var yy = (uint)y;
return (xx << 16) + yy;
}
public static void UnpackUShortsFromUInt(
uint pack,
out ushort x, out ushort y)
{
x = (ushort)((pack >> 16) & 0xFFFF);
y = (ushort)((pack ) & 0xFFFF);
}
//
//
//
public static uint PackUV(float u, float v) {
var uu = (uint)(Mathf.Clamp01(u) * UShortMax);
var vv = (uint)(Mathf.Clamp01(v) * UShortMax);
return (uu << 16) + vv;
}
public static void UnpackUV(uint pack, out float u, out float v) {
u = (float)((pack >> 16) & 0xFFFF) / UShortMax;
v = (float)((pack ) & 0xFFFF) / UShortMax;
}
//
//
//
public static ushort PackFloatColorToUShort(float v) {
return (ushort)Mathf.Clamp(
v * (1.0f / FColorPrecision),
short.MinValue,
short.MaxValue);
}
public static float UnpackFloatColorFromUShort(ushort pack) {
return (short)pack / InvFColorPrecision;
}
//
//
//
public static void PackFColorToUInts(
Color v,
out uint pack0, out uint pack1)
{
PackFColorToUInts(v.r, v.g, v.b, v.a, out pack0, out pack1);
}
public static void PackFColorToUInts(
SwfVec4Data v,
out uint pack0, out uint pack1)
{
PackFColorToUInts(v.x, v.y, v.z, v.w, out pack0, out pack1);
}
public static void PackFColorToUInts(
float v0, float v1, float v2, float v3,
out uint pack0, out uint pack1)
{
pack0 = PackUShortsToUInt(
PackFloatColorToUShort(v0),
PackFloatColorToUShort(v1));
pack1 = PackUShortsToUInt(
PackFloatColorToUShort(v2),
PackFloatColorToUShort(v3));
}
public static void UnpackFColorFromUInts(
uint pack0, uint pack1,
out float c0, out float c1, out float c2, out float c3)
{
c0 = (short)((pack0 >> 16) & 0xFFFF) / InvFColorPrecision;
c1 = (short)((pack0 ) & 0xFFFF) / InvFColorPrecision;
c2 = (short)((pack1 >> 16) & 0xFFFF) / InvFColorPrecision;
c3 = (short)((pack1 ) & 0xFFFF) / InvFColorPrecision;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7403812bd90474c01b689738c58fd8dc
timeCreated: 1473684950
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,16 +3,126 @@ using FlashTools.Internal;
using System.Collections.Generic;
namespace FlashTools {
[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 SwfColorTransData {
public Vector4 Mul;
public Vector4 Add;
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{
Mul = Vector4.one,
Add = Vector4.zero};
mulColor = SwfVec4Data.one,
addColor = SwfVec4Data.zero};
}
}
@@ -20,16 +130,16 @@ namespace FlashTools {
SwfColorTransData a, SwfColorTransData b)
{
return new SwfColorTransData{
Mul = new Vector4(
b.Mul.x * a.Mul.x,
b.Mul.y * a.Mul.y,
b.Mul.z * a.Mul.z,
b.Mul.w * a.Mul.w),
Add = new Vector4(
b.Add.x * a.Mul.x + a.Add.x,
b.Add.y * a.Mul.y + a.Add.y,
b.Add.z * a.Mul.z + a.Add.z,
b.Add.w * a.Mul.w + a.Add.w)};
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)};
}
}
@@ -44,7 +154,7 @@ namespace FlashTools {
public Types Type = Types.Group;
public ushort ClipDepth = 0;
public ushort Bitmap = 0;
public Matrix4x4 Matrix = Matrix4x4.identity;
public SwfMatrixData Matrix = SwfMatrixData.identity;
public SwfColorTransData ColorTrans = SwfColorTransData.identity;
}
@@ -62,9 +172,12 @@ namespace FlashTools {
[System.Serializable]
public class SwfBitmapData {
public int Id = 0;
public Vector2 RealSize = Vector2.zero;
public Rect SourceRect = new Rect();
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]
@@ -75,24 +188,31 @@ namespace FlashTools {
}
public class SwfAsset : ScriptableObject {
[System.Serializable]
public struct ConvertingState {
public int Stage;
}
[HideInInspector]
public SwfAssetData Data;
public byte[] Data;
[SwfReadOnly]
public Texture2D Atlas;
[HideInInspector]
public List<SwfClipAsset> Clips;
[HideInInspector]
public SwfSettingsData Settings;
[HideInInspector]
[SwfDisplayName("Settings")]
public SwfSettingsData Overridden;
[HideInInspector]
public ConvertingState Converting;
#if UNITY_EDITOR
void Reset() {
Data = new SwfAssetData();
Data = new byte[0];
Atlas = null;
Clips = new List<SwfClipAsset>();
Settings = SwfSettings.GetDefault();
Overridden = SwfSettings.GetDefault();
Converting = new ConvertingState();
}
#endif
}

View File

@@ -1,6 +1,10 @@
using UnityEngine;
using FlashTools.Internal;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace FlashTools {
[ExecuteInEditMode, DisallowMultipleComponent]
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
@@ -9,6 +13,7 @@ namespace FlashTools {
MeshFilter _meshFilter = null;
MeshRenderer _meshRenderer = null;
bool _dirtyMesh = true;
SwfClipAsset.Sequence _curSequence = null;
MaterialPropertyBlock _curPropBlock = null;
@@ -20,7 +25,7 @@ namespace FlashTools {
[Header("Sorting")]
[SerializeField][SwfSortingLayer]
public string _sortingLayer = "Default";
public string _sortingLayer = string.Empty;
public string sortingLayer {
get { return _sortingLayer; }
set {
@@ -40,22 +45,35 @@ namespace FlashTools {
}
[Header("Animation")]
[SerializeField]
Color _tint = Color.white;
public Color tint {
get { return _tint; }
set {
_tint = value;
ChangeTint();
}
}
[SerializeField]
SwfClipAsset _clip = null;
public SwfClipAsset clip {
get { return _clip; }
set {
_clip = value;
_clip = value;
_sequence = string.Empty;
_currentFrame = 0;
ChangeClip();
}
}
[SerializeField][HideInInspector]
string _sequence = "Default";
string _sequence = string.Empty;
public string sequence {
get { return _sequence; }
set {
_sequence = value;
_sequence = value;
_currentFrame = 0;
ChangeSequence();
}
}
@@ -80,7 +98,9 @@ namespace FlashTools {
public float frameRate {
get {
return clip ? clip.FrameRate : 1.0f;
return clip
? clip.FrameRate
: 1.0f;
}
}
@@ -95,7 +115,9 @@ namespace FlashTools {
}
public void ToEndFrame() {
currentFrame = frameCount - 1;
currentFrame = frameCount > 0
? frameCount - 1
: 0;
}
public bool ToPrevFrame() {
@@ -116,16 +138,42 @@ namespace FlashTools {
// ---------------------------------------------------------------------
//
// Private
// Internal
//
// ---------------------------------------------------------------------
public void InternalLateUpdate() {
if ( _meshFilter && _meshRenderer && _dirtyMesh ) {
var baked_frame = GetCurrentBakedFrame();
if ( baked_frame != null ) {
_meshFilter .sharedMesh = baked_frame.CachedMesh;
_meshRenderer.sharedMaterials = baked_frame.Materials;
} else {
_meshFilter .sharedMesh = null;
_meshRenderer.sharedMaterials = new Material[0];
}
}
}
public void UpdateAllProperties() {
clip = _clip;
sequence = _sequence;
currentFrame = _currentFrame;
sortingLayer = _sortingLayer;
sortingOrder = _sortingOrder;
ClearCache();
ChangeTint();
ChangeClip();
ChangeSequence();
ChangeCurrentFrame();
ChangeSortingProperties();
}
void ClearCache() {
_meshFilter = GetComponent<MeshFilter>();
_meshRenderer = GetComponent<MeshRenderer>();
_dirtyMesh = true;
_curSequence = null;
_curPropBlock = null;
}
void ChangeTint() {
UpdatePropBlock();
}
void ChangeClip() {
@@ -139,10 +187,18 @@ namespace FlashTools {
void ChangeSequence() {
_curSequence = null;
if ( clip && clip.Sequences != null ) {
for ( int i = 0, e = clip.Sequences.Count; i < e; ++i ) {
var clip_sequence = clip.Sequences[i];
if ( clip_sequence != null && clip_sequence.Name == sequence ) {
_curSequence = clip_sequence;
if ( !string.IsNullOrEmpty(sequence) ) {
for ( int i = 0, e = clip.Sequences.Count; i < e; ++i ) {
var clip_sequence = clip.Sequences[i];
if ( clip_sequence != null && clip_sequence.Name == sequence ) {
_curSequence = clip_sequence;
break;
}
}
if ( _curSequence == null ) {
Debug.LogWarningFormat(this,
"<b>[FlashTools]</b> Sequence '{0}' not found",
sequence);
}
}
if ( _curSequence == null ) {
@@ -163,7 +219,7 @@ namespace FlashTools {
_currentFrame = frameCount > 0
? Mathf.Clamp(currentFrame, 0, frameCount - 1)
: 0;
UpdateCurrentMesh();
SetDirtyCurrentMesh();
}
void ChangeSortingProperties() {
@@ -179,6 +235,9 @@ namespace FlashTools {
_curPropBlock = new MaterialPropertyBlock();
}
_meshRenderer.GetPropertyBlock(_curPropBlock);
_curPropBlock.SetColor(
"_Color",
tint);
_curPropBlock.SetTexture(
"_MainTex",
clip && clip.Atlas ? clip.Atlas : Texture2D.whiteTexture);
@@ -186,22 +245,18 @@ namespace FlashTools {
}
}
void UpdateCurrentMesh() {
if ( _meshFilter && _meshRenderer ) {
var baked_frame = GetCurrentBakedFrame();
_meshFilter.sharedMesh = baked_frame.Mesh;
_meshRenderer.sharedMaterials = baked_frame.Materials;
}
void SetDirtyCurrentMesh() {
_dirtyMesh = true;
#if UNITY_EDITOR
EditorUtility.SetDirty(this);
#endif
}
SwfClipAsset.Frame GetCurrentBakedFrame() {
var frames = _curSequence != null ? _curSequence.Frames : null;
var frame = frames != null && currentFrame >= 0 && currentFrame < frames.Count
return frames != null && currentFrame >= 0 && currentFrame < frames.Count
? frames[currentFrame]
: new SwfClipAsset.Frame();
return frame != null
? frame
: new SwfClipAsset.Frame();
: null;
}
// ---------------------------------------------------------------------
@@ -211,24 +266,20 @@ namespace FlashTools {
// ---------------------------------------------------------------------
void Awake() {
_meshFilter = GetComponent<MeshFilter>();
_meshRenderer = GetComponent<MeshRenderer>();
_curSequence = null;
_curPropBlock = null;
UpdateAllProperties();
}
void OnEnable() {
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfClip(this);
swf_manager.AddClip(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfClip(this);
swf_manager.RemoveClip(this);
}
}

View File

@@ -5,16 +5,80 @@ using System.Collections.Generic;
namespace FlashTools {
public class SwfClipAsset : ScriptableObject {
[System.Serializable]
public class Frame {
public Mesh Mesh = new Mesh();
public Material[] Materials = new Material[0];
}
[System.Serializable]
public class Sequence {
public string Name = string.Empty;
public List<Frame> Frames = new List<Frame>();
public class SubMeshData {
public int StartVertex;
public int IndexCount;
}
[System.Serializable]
public class MeshData {
public SubMeshData[] SubMeshes = new SubMeshData[0];
public Vector2[] Vertices = new Vector2[0];
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]
public class Frame {
public MeshData MeshData = new MeshData();
public Material[] Materials = new Material[0];
public Frame() {
MeshData = new MeshData();
Materials = new Material[0];
}
public Frame(MeshData mesh_data, Material[] materials) {
MeshData = mesh_data;
Materials = materials;
}
Mesh _cachedMesh = null;
public Mesh CachedMesh {
get {
if ( !_cachedMesh ) {
_cachedMesh = new Mesh();
MeshData.FillMesh(_cachedMesh);
}
return _cachedMesh;
}
}
}
[System.Serializable]
public class Sequence {
public string Name = string.Empty;
public List<Frame> Frames = new List<Frame>();
}
[SwfReadOnly]
public string Name;
[SwfReadOnly]
public Texture2D Atlas;
[SwfReadOnly]
@@ -24,10 +88,118 @@ namespace FlashTools {
#if UNITY_EDITOR
void Reset() {
Name = string.Empty;
Atlas = null;
FrameRate = 1.0f;
Sequences = new List<Sequence>();
}
#endif
}
// ---------------------------------------------------------------------
//
// 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);
}
}
}
}

View File

@@ -6,8 +6,9 @@ namespace FlashTools {
[RequireComponent(typeof(SwfClip))]
public class SwfClipController : MonoBehaviour {
SwfClip _clip = null;
float _timer = 0.0f;
SwfClip _clip = null;
bool _isPlaying = false;
float _tickTimer = 0.0f;
// ---------------------------------------------------------------------
//
@@ -16,11 +17,9 @@ namespace FlashTools {
// ---------------------------------------------------------------------
public event System.Action<SwfClipController> OnStopPlayingEvent;
public event System.Action<SwfClipController> OnPlayStoppedEvent;
public event System.Action<SwfClipController> OnRewindPlayingEvent;
public event System.Action<SwfClipController> OnPausePlayingEvent;
public event System.Action<SwfClipController> OnResumePausedEvent;
// ---------------------------------------------------------------------
//
// Properties
@@ -37,12 +36,6 @@ namespace FlashTools {
Loop
}
public enum States {
Stopped,
Paused,
Playing
}
[SerializeField]
bool _autoPlay = false;
public bool autoPlay {
@@ -58,6 +51,13 @@ namespace FlashTools {
set { _rateScale = Mathf.Clamp(value, 0.0f, float.MaxValue); }
}
[SerializeField]
string _groupName = string.Empty;
public string groupName {
get { return _groupName; }
set { _groupName = value; }
}
[SerializeField]
PlayModes _playMode = PlayModes.Forward;
public PlayModes playMode {
@@ -72,21 +72,16 @@ namespace FlashTools {
set { _loopMode = value; }
}
States _state = States.Stopped;
public States state {
get { return _state; }
}
public bool isStopped {
get { return state == States.Stopped; }
}
public bool isPaused {
get { return state == States.Paused; }
public SwfClip clip {
get { return _clip; }
}
public bool isPlaying {
get { return state == States.Playing; }
get { return _isPlaying; }
}
public bool isStopped {
get { return !isPlaying; }
}
// ---------------------------------------------------------------------
@@ -95,14 +90,48 @@ namespace FlashTools {
//
// ---------------------------------------------------------------------
public void Stop() {
Stop(true);
public void GotoAndStop(int frame) {
if ( clip ) {
clip.currentFrame = frame;
}
Stop(false);
}
public void GotoAndStop(string sequence, int frame) {
if ( clip ) {
clip.sequence = sequence;
}
GotoAndStop(frame);
}
//
//
//
public void GotoAndPlay(int frame) {
if ( clip ) {
clip.currentFrame = frame;
}
Play(false);
}
public void GotoAndPlay(string sequence, int frame) {
if ( clip ) {
clip.sequence = sequence;
}
GotoAndPlay(frame);
}
//
//
//
public void Stop(bool rewind) {
var is_playing = isPlaying;
_timer = 0.0f;
_state = States.Stopped;
if ( is_playing ) {
_isPlaying = false;
_tickTimer = 0.0f;
}
if ( rewind ) {
Rewind();
}
@@ -111,40 +140,52 @@ namespace FlashTools {
}
}
public void Pause() {
if ( isPlaying ) {
_state = States.Paused;
if ( OnPausePlayingEvent != null ) {
OnPausePlayingEvent(this);
}
public void Stop(string sequence) {
if ( clip ) {
clip.sequence = sequence;
}
Stop(true);
}
//
//
//
public void Play(bool rewind) {
var is_stopped = isStopped;
if ( is_stopped ) {
_isPlaying = true;
_tickTimer = 0.0f;
}
if ( rewind ) {
Rewind();
}
if ( is_stopped && OnPlayStoppedEvent != null ) {
OnPlayStoppedEvent(this);
}
}
public void Resume() {
if ( isPaused ) {
_state = States.Playing;
if ( OnResumePausedEvent != null ) {
OnResumePausedEvent(this);
}
public void Play(string sequence) {
if ( clip ) {
clip.sequence = sequence;
}
Play(true);
}
public void Play() {
Rewind();
_timer = 0.0f;
_state = States.Playing;
}
//
//
//
public void Rewind() {
switch ( playMode ) {
case PlayModes.Forward:
if ( _clip ) {
_clip.ToBeginFrame();
if ( clip ) {
clip.ToBeginFrame();
}
break;
case PlayModes.Backward:
if ( _clip ) {
_clip.ToEndFrame();
if ( clip ) {
clip.ToEndFrame();
}
break;
default:
@@ -170,10 +211,10 @@ namespace FlashTools {
}
void UpdateTimer(float dt) {
var frame_rate = _clip ? _clip.frameRate : 1.0f;
_timer += frame_rate * rateScale * dt;
while ( _timer > 1.0f ) {
_timer -= 1.0f;
var frame_rate = clip ? clip.frameRate : 1.0f;
_tickTimer += frame_rate * rateScale * dt;
while ( _tickTimer > 1.0f ) {
_tickTimer -= 1.0f;
TimerTick();
}
}
@@ -198,9 +239,9 @@ namespace FlashTools {
bool NextClipFrame() {
switch ( playMode ) {
case PlayModes.Forward:
return _clip ? _clip.ToNextFrame() : false;
return clip ? clip.ToNextFrame() : false;
case PlayModes.Backward:
return _clip ? _clip.ToPrevFrame() : false;
return clip ? clip.ToPrevFrame() : false;
default:
throw new UnityException(string.Format(
"SwfClipController. Incorrect play mode: {0}",
@@ -216,22 +257,22 @@ namespace FlashTools {
void Awake() {
_clip = GetComponent<SwfClip>();
if ( autoPlay ) {
Play();
if ( autoPlay && Application.isPlaying ) {
Play(false);
}
}
void OnEnable() {
var swf_manager = SwfManager.GetInstance(true);
if ( swf_manager ) {
swf_manager.AddSwfClipController(this);
swf_manager.AddController(this);
}
}
void OnDisable() {
var swf_manager = SwfManager.GetInstance(false);
if ( swf_manager ) {
swf_manager.RemoveSwfClipController(this);
swf_manager.RemoveController(this);
}
}
}

View File

@@ -1,12 +1,18 @@
using UnityEngine;
using FlashTools.Internal;
using System.Collections.Generic;
namespace FlashTools {
[ExecuteInEditMode, DisallowMultipleComponent]
public class SwfManager : MonoBehaviour {
SwfAssocList<SwfClip> _clips = new SwfAssocList<SwfClip>();
SwfAssocList<SwfClipController> _controllers = new SwfAssocList<SwfClipController>();
SwfList<SwfClipController> _safeUpdates = new SwfList<SwfClipController>();
SwfAssocList<SwfClip> _clips = new SwfAssocList<SwfClip>();
SwfAssocList<SwfClipController> _controllers = new SwfAssocList<SwfClipController>();
bool _isPaused = false;
float _rateScale = 1.0f;
HashSet<string> _groupPauses = new HashSet<string>();
Dictionary<string, float> _groupRateScales = new Dictionary<string, float>();
// ---------------------------------------------------------------------
//
@@ -26,46 +32,114 @@ namespace FlashTools {
return _instance;
}
// ---------------------------------------------------------------------
//
// Properties
//
// ---------------------------------------------------------------------
public int clipCount {
get { return _clips.Count; }
}
public int controllerCount {
get { return _controllers.Count; }
}
public bool isPaused {
get { return _isPaused; }
}
public bool isPlaying {
get { return !isPaused; }
}
public float rateScale {
get { return _rateScale; }
set { _rateScale = Mathf.Clamp(value, 0.0f, float.MaxValue); }
}
// ---------------------------------------------------------------------
//
// Functions
//
// ---------------------------------------------------------------------
public void Pause() {
_isPaused = true;
}
public void Resume() {
_isPaused = false;
}
public void PauseGroup(string group_name) {
if ( !string.IsNullOrEmpty(group_name) ) {
_groupPauses.Add(group_name);
}
}
public void ResumeGroup(string group_name) {
if ( !string.IsNullOrEmpty(group_name) ) {
_groupPauses.Remove(group_name);
}
}
public bool IsGroupPaused(string group_name) {
return _groupPauses.Contains(group_name);
}
public bool IsGroupPlaying(string group_name) {
return !IsGroupPaused(group_name);
}
public void SetGroupRateScale(string group_name, float rate_scale) {
if ( !string.IsNullOrEmpty(group_name) ) {
_groupRateScales[group_name] = Mathf.Clamp(rate_scale, 0.0f, float.MaxValue);
}
}
public float GetGroupRateScale(string group_name) {
float rate_scale;
return _groupRateScales.TryGetValue(group_name, out rate_scale)
? rate_scale
: 1.0f;
}
// ---------------------------------------------------------------------
//
// Internal
//
// ---------------------------------------------------------------------
public int AllClipCount {
get { return _clips.Count; }
}
public void AddSwfClip(SwfClip clip) {
public void AddClip(SwfClip clip) {
_clips.Add(clip);
}
public void RemoveSwfClip(SwfClip clip) {
public void RemoveClip(SwfClip clip) {
_clips.Remove(clip);
}
public int AllClipControllerCount {
get { return _controllers.Count; }
public void GetAllClips(SwfList<SwfClip> clips) {
_clips.AssignTo(clips);
}
public void AddSwfClipController(SwfClipController controller) {
public void AddController(SwfClipController controller) {
_controllers.Add(controller);
}
public void RemoveSwfClipController(SwfClipController controller) {
public void RemoveController(SwfClipController controller) {
_controllers.Remove(controller);
}
// ---------------------------------------------------------------------
//
// Private
//
// ---------------------------------------------------------------------
public void GetAllControllers(SwfList<SwfClipController> controllers) {
_controllers.AssignTo(controllers);
}
void GrabEnabledClips() {
var all_clips = FindObjectsOfType<SwfClip>();
for ( int i = 0, e = all_clips.Length; i < e; ++i ) {
var clip = all_clips[i];
var clips = FindObjectsOfType<SwfClip>();
for ( int i = 0, e = clips.Length; i < e; ++i ) {
var clip = clips[i];
if ( clip.enabled ) {
_clips.Add(clip);
}
@@ -73,9 +147,9 @@ namespace FlashTools {
}
void GrabEnabledControllers() {
var all_controllers = FindObjectsOfType<SwfClipController>();
for ( int i = 0, e = all_controllers.Length; i < e; ++i ) {
var controller = all_controllers[i];
var controllers = FindObjectsOfType<SwfClipController>();
for ( int i = 0, e = controllers.Length; i < e; ++i ) {
var controller = controllers[i];
if ( controller.enabled ) {
_controllers.Add(controller);
}
@@ -90,10 +164,29 @@ namespace FlashTools {
_controllers.Clear();
}
void UpdateControllers() {
var dt = Time.deltaTime;
for ( int i = 0, e = _controllers.Count; i < e; ++i ) {
_controllers[i].InternalUpdate(dt);
void UpdateControllers(float dt) {
_controllers.AssignTo(_safeUpdates);
for ( int i = 0, e = _safeUpdates.Count; i < e; ++i ) {
var ctrl = _safeUpdates[i];
if ( ctrl ) {
var group_name = ctrl.groupName;
if ( string.IsNullOrEmpty(group_name) ) {
ctrl.InternalUpdate(dt);
} else if ( !IsGroupPaused(group_name) ) {
var group_rate_scale = GetGroupRateScale(group_name);
ctrl.InternalUpdate(group_rate_scale * dt);
}
}
}
_safeUpdates.Clear();
}
void LateUpdateClips() {
for ( int i = 0, e = _clips.Count; i < e; ++i ) {
var clip = _clips[i];
if ( clip ) {
clip.InternalLateUpdate();
}
}
}
@@ -114,7 +207,14 @@ namespace FlashTools {
}
void Update() {
UpdateControllers();
if ( isPlaying ) {
var dt = Time.deltaTime;
UpdateControllers(rateScale * dt);
}
}
void LateUpdate() {
LateUpdateClips();
}
}
}

View File

@@ -220,10 +220,10 @@ if (!Function.prototype.bind) {
ft.type_assert(doc, Document);
ft.profile_function(function() { ftdoc.prepare_folders(doc); }, "Prepare folders");
ft.profile_function(function() { ftdoc.full_exit_edit_mode(doc); }, "Full exit edit mode");
ft.profile_function(function() { ftdoc.prepare_all_bitmaps(doc); }, "Prepare all bitmaps");
ft.profile_function(function() { ftdoc.unlock_all_timelines(doc); }, "Unlock all timelines");
ft.profile_function(function() { ftdoc.optimize_all_timelines(doc); }, "Optimize all timelines");
ft.profile_function(function() { ftdoc.rasterize_all_shapes(doc); }, "Rasterize all shapes");
ft.profile_function(function() { ftdoc.prepare_all_bitmaps(doc); }, "Prepare all bitmaps");
ft.profile_function(function() { ftdoc.export_swf(doc); }, "Export swf");
};
@@ -576,7 +576,7 @@ if (!Function.prototype.bind) {
ft.profile_function(function() {
ft.array_foreach(fl.documents, function (doc) {
if ( doc.canRevert() ) {
fl.revertDocument(document);
fl.revertDocument(doc);
}
});
}, "Revert documents");

View File

@@ -64,12 +64,14 @@ PlayerSettings:
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0
xboxEnablePIXSampling: 0
xboxEnableEnableRenderThreadRunsJobs: 0
n3dsDisableStereoscopicView: 0
n3dsEnableSharedListOpt: 1
n3dsEnableVSync: 0
uiUse16BitDepthBuffer: 0
ignoreAlphaClear: 0
xboxOneResolution: 0
xboxOneMonoLoggingLevel: 0
ps3SplashScreen: {fileID: 0}
videoMemoryForVertexBuffers: 0
psp2PowerMode: 0
@@ -258,6 +260,7 @@ PlayerSettings:
ps4NPtitleDatPath:
ps4RemotePlayKeyAssignment: -1
ps4RemotePlayKeyMappingDir:
ps4PlayTogetherPlayerCount: 0
ps4EnterButtonAssignment: 1
ps4ApplicationParam1: 0
ps4ApplicationParam2: 0
@@ -284,6 +287,8 @@ PlayerSettings:
ps4attribMoveSupport: 0
ps4attrib3DSupport: 0
ps4attribShareSupport: 0
ps4attribExclusiveVR: 0
ps4disableAutoHideSplash: 0
ps4IncludedModules: []
monoEnv:
psp2Splashimage: {fileID: 0}

View File

@@ -1,2 +1,2 @@
m_EditorVersion: 5.3.5f1
m_EditorVersion: 5.3.6f1
m_StandardAssetsVersion: 0

View File

@@ -1,6 +1,11 @@
<Properties StartupItem="Assembly-CSharp.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
<MonoDevelop.Ide.Workbench />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets/FlashTools/Scripts/Internal/Editor/Postprocessors/SwfAssetPostprocessor.cs">
<Files>
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/Postprocessors/SwfAssetPostprocessor.cs" Line="160" Column="33" />
<File FileName="Assets/FlashTools/Scripts/Internal/Editor/Editors/SwfAssetEditor.cs" Line="1" Column="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>