mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
Remove excess animation reimports
This commit is contained in:
@@ -42,22 +42,26 @@ namespace FTEditor.Postprocessors {
|
||||
}
|
||||
|
||||
static void SwfFileProcess(string swf_path) {
|
||||
var swf_hash = SwfEditorUtils.GetFileHash(swf_path);
|
||||
var swf_asset_path = Path.ChangeExtension(swf_path, ".asset");
|
||||
SwfEditorUtils.LoadOrCreateAsset<SwfAsset>(swf_asset_path, (swf_asset, created) => {
|
||||
if ( created ) {
|
||||
if ( !string.IsNullOrEmpty(swf_asset.Hash) && swf_asset.Hash == swf_hash ) {
|
||||
return true;
|
||||
} else if ( created ) {
|
||||
var default_settings = SwfEditorUtils.GetSettingsHolder().Settings;
|
||||
swf_asset.Settings = default_settings;
|
||||
swf_asset.Overridden = default_settings;
|
||||
}
|
||||
return SafeLoadSwfAsset(swf_path, swf_asset);
|
||||
return SafeLoadSwfAsset(swf_path, swf_hash, swf_asset);
|
||||
});
|
||||
}
|
||||
|
||||
static bool SafeLoadSwfAsset(string swf_path, SwfAsset swf_asset) {
|
||||
static bool SafeLoadSwfAsset(string swf_path, string swf_hash, SwfAsset swf_asset) {
|
||||
try {
|
||||
_progressBar.UpdateTitle(Path.GetFileName(swf_path));
|
||||
var new_data = LoadSwfAssetData(swf_path);
|
||||
swf_asset.Data = SwfEditorUtils.CompressAsset(new_data);
|
||||
swf_asset.Hash = swf_hash;
|
||||
swf_asset.Atlas = null;
|
||||
EditorUtility.SetDirty(swf_asset);
|
||||
return true;
|
||||
|
||||
@@ -4,6 +4,7 @@ using UnityEditor;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
using Ionic.Zlib;
|
||||
@@ -259,6 +260,24 @@ namespace FTEditor {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// FileHash
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public static string GetFileHash(string path) {
|
||||
try {
|
||||
using ( var sha256 = SHA256.Create() ) {
|
||||
var file_bytes = File.ReadAllBytes(path);
|
||||
var hash_bytes = sha256.ComputeHash(file_bytes);
|
||||
return System.Convert.ToBase64String(hash_bytes) + file_bytes.LongLength.ToString();
|
||||
}
|
||||
} catch ( System.Exception ) {
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Menu
|
||||
@@ -286,6 +305,17 @@ namespace FTEditor {
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/FlashTools/Reconvert all swf assets")]
|
||||
static void Tools_FlashTools_ReconvertAllSwfAssets() {
|
||||
Tools_FlashTools_ReimportAllSwfFiles();
|
||||
var swf_assets = GetAllSwfAssets();
|
||||
foreach ( var swf_asset in swf_assets ) {
|
||||
swf_asset.Atlas = null;
|
||||
EditorUtility.SetDirty(swf_asset);
|
||||
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(swf_asset));
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Tools/FlashTools/Pregenerate all materials")]
|
||||
static void PregenerateAllMaterials() {
|
||||
var blend_modes = System.Enum.GetValues(typeof(SwfBlendModeData.Types));
|
||||
@@ -299,6 +329,10 @@ namespace FTEditor {
|
||||
SwfMaterialCache.GetDecrMaskMaterial();
|
||||
}
|
||||
|
||||
static SwfAsset[] GetAllSwfAssets() {
|
||||
return SwfEditorUtils.LoadAllAssetsDBByFilter<SwfAsset>("t:SwfAsset");
|
||||
}
|
||||
|
||||
static string[] GetAllSwfFilePaths() {
|
||||
return AssetDatabase.GetAllAssetPaths()
|
||||
.Where(p => Path.GetExtension(p).ToLower().Equals(".swf"))
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace FTRuntime {
|
||||
public class SwfAsset : ScriptableObject {
|
||||
[HideInInspector]
|
||||
public byte[] Data;
|
||||
[HideInInspector]
|
||||
public string Hash;
|
||||
[SwfReadOnly]
|
||||
public Texture2D Atlas;
|
||||
[HideInInspector]
|
||||
@@ -15,6 +17,7 @@ namespace FTRuntime {
|
||||
|
||||
void Reset() {
|
||||
Data = new byte[0];
|
||||
Hash = string.Empty;
|
||||
Atlas = null;
|
||||
Settings = SwfSettingsData.identity;
|
||||
Overridden = SwfSettingsData.identity;
|
||||
|
||||
Reference in New Issue
Block a user