remove multiphased import

This commit is contained in:
2017-02-11 12:25:00 +07:00
parent eed1253aeb
commit a3e9da5c73
6 changed files with 46 additions and 78 deletions

View File

@@ -85,46 +85,6 @@ NavMeshSettings:
cellSize: 0.16666667 cellSize: 0.16666667
manualCellSize: 0 manualCellSize: 0
m_NavMeshData: {fileID: 0} m_NavMeshData: {fileID: 0}
--- !u!1 &41841841
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 4
m_Component:
- 4: {fileID: 41841843}
- 114: {fileID: 41841842}
m_Layer: 0
m_Name: '[SwfManager]'
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &41841842
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 41841841}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f455e092ebcb64c3e94de2e2f2f7a614, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &41841843
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 41841841}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
--- !u!1 &1173114888 --- !u!1 &1173114888
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@@ -42,7 +42,6 @@ namespace FTEditor.Editors {
} }
static void ReconvertAsset(SwfAsset asset) { static void ReconvertAsset(SwfAsset asset) {
asset.Converting = new SwfAsset.ConvertingState();
AssetDatabase.ImportAsset( AssetDatabase.ImportAsset(
AssetDatabase.GetAssetPath(asset)); AssetDatabase.GetAssetPath(asset));
} }

View File

@@ -10,6 +10,8 @@ using FTRuntime;
namespace FTEditor.Postprocessors { namespace FTEditor.Postprocessors {
class SwfAssetPostprocessor : AssetPostprocessor { class SwfAssetPostprocessor : AssetPostprocessor {
static List<SwfAsset> _assetsForProcess = new List<SwfAsset>();
static void OnPostprocessAllAssets( static void OnPostprocessAllAssets(
string[] imported_assets, string[] imported_assets,
string[] deleted_assets, string[] deleted_assets,
@@ -18,35 +20,38 @@ namespace FTEditor.Postprocessors {
{ {
var asset_paths = imported_assets var asset_paths = imported_assets
.Where(p => Path.GetExtension(p).ToLower().Equals(".asset")); .Where(p => Path.GetExtension(p).ToLower().Equals(".asset"));
foreach ( var asset_path in asset_paths ) { _assetsForProcess = asset_paths
var asset = AssetDatabase.LoadAssetAtPath<SwfAsset>(asset_path); .Select(p => AssetDatabase.LoadAssetAtPath<SwfAsset>(p))
if ( asset ) { .Where(p => !!p)
SwfAssetProcess(asset); .Distinct()
} .ToList();
if ( _assetsForProcess.Count > 0 ) {
EditorApplication.update += ProcessAfterImport;
} }
} }
static void ProcessAfterImport() {
EditorApplication.update -= ProcessAfterImport;
var assets = new List<SwfAsset>(_assetsForProcess);
_assetsForProcess.Clear();
foreach ( var asset in assets ) {
SwfAssetProcess(asset);
}
AssetDatabase.SaveAssets();
}
static void SwfAssetProcess(SwfAsset asset) { static void SwfAssetProcess(SwfAsset asset) {
try { try {
if ( asset.Converting.Stage == 0 ) { var new_data = ConfigureBitmaps(
var new_data = ConfigureBitmaps( asset,
SwfEditorUtils.DecompressAsset<SwfAssetData>(asset.Data));
asset.Data = SwfEditorUtils.CompressAsset(new_data);
asset.Atlas = LoadAssetAtlas(asset);
if ( asset.Atlas ) {
ConfigureAtlas(asset);
ConfigureClips(
asset, asset,
SwfEditorUtils.DecompressAsset<SwfAssetData>(asset.Data)); SwfEditorUtils.DecompressAsset<SwfAssetData>(asset.Data));
asset.Data = SwfEditorUtils.CompressAsset(new_data);
++asset.Converting.Stage;
EditorUtility.SetDirty(asset);
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));
} }
} catch ( Exception e ) { } catch ( Exception e ) {
Debug.LogErrorFormat( Debug.LogErrorFormat(
@@ -82,8 +87,8 @@ namespace FTEditor.Postprocessors {
static SwfAssetData ConfigureBitmaps(SwfAsset asset, SwfAssetData data) { static SwfAssetData ConfigureBitmaps(SwfAsset asset, SwfAssetData data) {
var textures = data.Bitmaps var textures = data.Bitmaps
.Where (p => p.Redirect == 0) .Where (p => p.Redirect == 0)
.Select (p => new KeyValuePair<ushort, Texture2D>( .Select(p => new KeyValuePair<ushort, Texture2D>(
p.Id, p.Id,
LoadTextureFromData(p))) LoadTextureFromData(p)))
.ToList(); .ToList();

View File

@@ -14,6 +14,8 @@ using FTSwfTools.SwfTypes;
namespace FTEditor.Postprocessors { namespace FTEditor.Postprocessors {
class SwfPostprocessor : AssetPostprocessor { class SwfPostprocessor : AssetPostprocessor {
static List<string> _assetsForProcess = new List<string>();
static void OnPostprocessAllAssets( static void OnPostprocessAllAssets(
string[] imported_assets, string[] imported_assets,
string[] deleted_assets, string[] deleted_assets,
@@ -29,12 +31,23 @@ namespace FTEditor.Postprocessors {
"It means that you can't have more than 5 animation assets in the project."; "It means that you can't have more than 5 animation assets in the project.";
EditorUtility.DisplayDialog(title, message, "Ok"); EditorUtility.DisplayDialog(title, message, "Ok");
} else { } else {
foreach ( var swf_path in swf_paths ) { _assetsForProcess = swf_paths.ToList();
SwfFileProcess(swf_path); if ( _assetsForProcess.Count > 0 ) {
EditorApplication.update += ProcessAfterImport;
} }
} }
} }
static void ProcessAfterImport() {
EditorApplication.update -= ProcessAfterImport;
var swf_paths = new List<string>(_assetsForProcess);
_assetsForProcess.Clear();
foreach ( var swf_path in swf_paths ) {
SwfFileProcess(swf_path);
}
AssetDatabase.SaveAssets();
}
static void SwfFileProcess(string swf_path) { static void SwfFileProcess(string swf_path) {
var swf_asset_path = Path.ChangeExtension(swf_path, ".asset"); var swf_asset_path = Path.ChangeExtension(swf_path, ".asset");
SwfEditorUtils.LoadOrCreateAsset<SwfAsset>(swf_asset_path, (swf_asset, created) => { SwfEditorUtils.LoadOrCreateAsset<SwfAsset>(swf_asset_path, (swf_asset, created) => {
@@ -49,9 +62,8 @@ namespace FTEditor.Postprocessors {
static bool SafeLoadSwfAsset(string swf_path, SwfAsset swf_asset) { static bool SafeLoadSwfAsset(string swf_path, SwfAsset swf_asset) {
try { try {
var new_data = LoadSwfAssetData(swf_path); var new_data = LoadSwfAssetData(swf_path);
swf_asset.Data = SwfEditorUtils.CompressAsset(new_data); swf_asset.Data = SwfEditorUtils.CompressAsset(new_data);
swf_asset.Converting = new SwfAsset.ConvertingState();
return true; return true;
} catch ( Exception e ) { } catch ( Exception e ) {
Debug.LogErrorFormat( Debug.LogErrorFormat(

View File

@@ -152,7 +152,6 @@ namespace FTEditor {
if ( asset ) { if ( asset ) {
if ( act(asset, false) ) { if ( act(asset, false) ) {
EditorUtility.SetDirty(asset); EditorUtility.SetDirty(asset);
AssetDatabase.ImportAsset(asset_path);
} }
} else { } else {
asset = ScriptableObject.CreateInstance<T>(); asset = ScriptableObject.CreateInstance<T>();

View File

@@ -4,10 +4,6 @@ using System.Collections.Generic;
namespace FTRuntime { namespace FTRuntime {
public class SwfAsset : ScriptableObject { public class SwfAsset : ScriptableObject {
[System.Serializable]
public struct ConvertingState {
public int Stage;
}
[HideInInspector] [HideInInspector]
public byte[] Data; public byte[] Data;
[SwfReadOnly] [SwfReadOnly]
@@ -18,8 +14,6 @@ namespace FTRuntime {
public SwfSettingsData Settings; public SwfSettingsData Settings;
[SwfDisplayName("Settings")] [SwfDisplayName("Settings")]
public SwfSettingsData Overridden; public SwfSettingsData Overridden;
[HideInInspector]
public ConvertingState Converting;
void Reset() { void Reset() {
Data = new byte[0]; Data = new byte[0];
@@ -27,7 +21,6 @@ namespace FTRuntime {
Clips = new List<SwfClipAsset>(); Clips = new List<SwfClipAsset>();
Settings = SwfSettingsData.identity; Settings = SwfSettingsData.identity;
Overridden = SwfSettingsData.identity; Overridden = SwfSettingsData.identity;
Converting = new ConvertingState();
} }
} }
} }