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

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

View File

@@ -10,6 +10,8 @@ using FTRuntime;
namespace FTEditor.Postprocessors {
class SwfAssetPostprocessor : AssetPostprocessor {
static List<SwfAsset> _assetsForProcess = new List<SwfAsset>();
static void OnPostprocessAllAssets(
string[] imported_assets,
string[] deleted_assets,
@@ -18,35 +20,38 @@ namespace FTEditor.Postprocessors {
{
var asset_paths = imported_assets
.Where(p => Path.GetExtension(p).ToLower().Equals(".asset"));
foreach ( var asset_path in asset_paths ) {
var asset = AssetDatabase.LoadAssetAtPath<SwfAsset>(asset_path);
if ( asset ) {
SwfAssetProcess(asset);
}
_assetsForProcess = asset_paths
.Select(p => AssetDatabase.LoadAssetAtPath<SwfAsset>(p))
.Where(p => !!p)
.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) {
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,
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 ) {
Debug.LogErrorFormat(
@@ -82,8 +87,8 @@ namespace FTEditor.Postprocessors {
static SwfAssetData ConfigureBitmaps(SwfAsset asset, SwfAssetData data) {
var textures = data.Bitmaps
.Where (p => p.Redirect == 0)
.Select (p => new KeyValuePair<ushort, Texture2D>(
.Where (p => p.Redirect == 0)
.Select(p => new KeyValuePair<ushort, Texture2D>(
p.Id,
LoadTextureFromData(p)))
.ToList();

View File

@@ -14,6 +14,8 @@ using FTSwfTools.SwfTypes;
namespace FTEditor.Postprocessors {
class SwfPostprocessor : AssetPostprocessor {
static List<string> _assetsForProcess = new List<string>();
static void OnPostprocessAllAssets(
string[] imported_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.";
EditorUtility.DisplayDialog(title, message, "Ok");
} else {
foreach ( var swf_path in swf_paths ) {
SwfFileProcess(swf_path);
_assetsForProcess = swf_paths.ToList();
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) {
var swf_asset_path = Path.ChangeExtension(swf_path, ".asset");
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) {
try {
var new_data = LoadSwfAssetData(swf_path);
swf_asset.Data = SwfEditorUtils.CompressAsset(new_data);
swf_asset.Converting = new SwfAsset.ConvertingState();
var new_data = LoadSwfAssetData(swf_path);
swf_asset.Data = SwfEditorUtils.CompressAsset(new_data);
return true;
} catch ( Exception e ) {
Debug.LogErrorFormat(

View File

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

View File

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