mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 22:19:31 +07:00
big name refactor continue
This commit is contained in:
@@ -45,8 +45,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfConverterSettings.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfPropertyAttributes.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfAttributes.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\Internal\SwfSettings.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\SwfAsset.cs" />
|
||||
<Compile Include="Assets\FlashTools\Scripts\SwfClip.cs" />
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
-- Version 0.1 --
|
||||
-----------------
|
||||
|
||||
Initial alpha version.
|
||||
Initial alpha version.
|
||||
@@ -9,7 +9,7 @@ MonoBehaviour:
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6da591d87f967451298a275621e1fd5d, type: 3}
|
||||
m_Name: SwfConverterSettings
|
||||
m_Name: SwfSettings
|
||||
m_EditorClassIdentifier:
|
||||
DefaultSettings:
|
||||
MaxAtlasSize: 1024
|
||||
@@ -38,7 +38,7 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static void OverriddenSettingsToDefault(SwfAsset asset) {
|
||||
asset.Overridden = SwfConverterSettings.GetDefaultSettings();
|
||||
asset.Overridden = SwfSettings.GetDefaultSettings();
|
||||
}
|
||||
|
||||
static void ApplyOverriddenSettings(SwfAsset asset) {
|
||||
@@ -135,7 +135,7 @@ namespace FlashTools.Internal {
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.FlexibleSpace();
|
||||
{
|
||||
var default_settings = SwfConverterSettings.GetDefaultSettings();
|
||||
var default_settings = SwfSettings.GetDefaultSettings();
|
||||
SwfEditorUtils.DoWithEnabledGUI(
|
||||
_assets.Any(p => !p.Overridden.CheckEquals(default_settings)), () => {
|
||||
if ( GUILayout.Button("Default") ) {
|
||||
@@ -166,7 +166,7 @@ namespace FlashTools.Internal {
|
||||
.OfType<SwfAsset>()
|
||||
.ToList();
|
||||
_settingsFoldout =
|
||||
_assets.Any(p => !p.Settings.CheckEquals(SwfConverterSettings.GetDefaultSettings()));
|
||||
_assets.Any(p => !p.Settings.CheckEquals(SwfSettings.GetDefaultSettings()));
|
||||
}
|
||||
|
||||
void OnDisable() {
|
||||
|
||||
@@ -96,14 +96,14 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static FilterMode SwfAtlasFilterToImporterFilter(
|
||||
SwfSettings.AtlasFilter filter)
|
||||
SwfSettingsData.AtlasFilter filter)
|
||||
{
|
||||
switch ( filter ) {
|
||||
case SwfSettings.AtlasFilter.Point:
|
||||
case SwfSettingsData.AtlasFilter.Point:
|
||||
return FilterMode.Point;
|
||||
case SwfSettings.AtlasFilter.Bilinear:
|
||||
case SwfSettingsData.AtlasFilter.Bilinear:
|
||||
return FilterMode.Bilinear;
|
||||
case SwfSettings.AtlasFilter.Trilinear:
|
||||
case SwfSettingsData.AtlasFilter.Trilinear:
|
||||
return FilterMode.Trilinear;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
@@ -113,16 +113,16 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static TextureImporterFormat SwfAtlasFormatToImporterFormat(
|
||||
SwfSettings.AtlasFormat format)
|
||||
SwfSettingsData.AtlasFormat format)
|
||||
{
|
||||
switch ( format ) {
|
||||
case SwfSettings.AtlasFormat.AutomaticCompressed:
|
||||
case SwfSettingsData.AtlasFormat.AutomaticCompressed:
|
||||
return TextureImporterFormat.AutomaticCompressed;
|
||||
case SwfSettings.AtlasFormat.Automatic16bit:
|
||||
case SwfSettingsData.AtlasFormat.Automatic16bit:
|
||||
return TextureImporterFormat.Automatic16bit;
|
||||
case SwfSettings.AtlasFormat.AutomaticTruecolor:
|
||||
case SwfSettingsData.AtlasFormat.AutomaticTruecolor:
|
||||
return TextureImporterFormat.AutomaticTruecolor;
|
||||
case SwfSettings.AtlasFormat.AutomaticCrunched:
|
||||
case SwfSettingsData.AtlasFormat.AutomaticCrunched:
|
||||
return TextureImporterFormat.AutomaticCrunched;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
@@ -279,21 +279,21 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
var default_converter = SwfConverterSettings.GetDefaultConverter();
|
||||
var settings_holder = SwfSettings.GetSettingsHolder();
|
||||
for ( var i = 0; i < baked_groups.Count; ++i ) {
|
||||
var group = baked_groups[i];
|
||||
switch ( group.Type ) {
|
||||
case SwfInstanceData.Types.Mask:
|
||||
group.Material = default_converter.GetIncrMaskMaterial();
|
||||
group.Material = settings_holder.GetIncrMaskMaterial();
|
||||
break;
|
||||
case SwfInstanceData.Types.Group:
|
||||
group.Material = default_converter.GetSimpleMaterial();
|
||||
group.Material = settings_holder.GetSimpleMaterial();
|
||||
break;
|
||||
case SwfInstanceData.Types.Masked:
|
||||
group.Material = default_converter.GetMaskedMaterial(group.ClipDepth);
|
||||
group.Material = settings_holder.GetMaskedMaterial(group.ClipDepth);
|
||||
break;
|
||||
case SwfInstanceData.Types.MaskReset:
|
||||
group.Material = default_converter.GetDecrMaskMaterial();
|
||||
group.Material = settings_holder.GetDecrMaskMaterial();
|
||||
break;
|
||||
default:
|
||||
throw new UnityException(string.Format(
|
||||
|
||||
@@ -205,7 +205,7 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static List<SwfBitmapData> LoadBitmaps(
|
||||
string swf_asset, SwfSettings settings, SwfLibrary library)
|
||||
string swf_asset, SwfSettingsData settings, SwfLibrary library)
|
||||
{
|
||||
var bitmap_defines = library.Defines
|
||||
.Where (p => p.Value.Type == SwfLibraryDefineType.Bitmap)
|
||||
@@ -259,7 +259,7 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
|
||||
static Rect[] PackAndSaveBitmapsAtlas(
|
||||
string swf_asset, Texture2D[] textures, SwfSettings settings)
|
||||
string swf_asset, Texture2D[] textures, SwfSettingsData settings)
|
||||
{
|
||||
var atlas_info = PackBitmapsAtlas(textures, settings);
|
||||
var atlas_path = SwfEditorUtils.GetAtlasPathFromSwfPath(swf_asset);
|
||||
@@ -269,7 +269,7 @@ namespace FlashTools.Internal {
|
||||
return atlas_info.Rects;
|
||||
}
|
||||
|
||||
static BitmapsAtlasInfo PackBitmapsAtlas(Texture2D[] textures, SwfSettings settings) {
|
||||
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)
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
#endif
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
public class SwfConverterSettings : ScriptableObject {
|
||||
|
||||
public SwfSettings DefaultSettings;
|
||||
|
||||
[HideInInspector] public Material SimpleMaterial;
|
||||
[HideInInspector] public Material IncrMaskMaterial;
|
||||
[HideInInspector] public Material DecrMaskMaterial;
|
||||
[HideInInspector] public List<Material> MaskedMaterials;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Private
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
const string DefaultSettingsName = "SwfConverterSettings.asset";
|
||||
const string SwfSimpleMatRelativePath = "Materials/SwfSimpleMat.mat";
|
||||
const string SwfIncrMaskMatRelativePath = "Materials/SwfIncrMaskMat.mat";
|
||||
const string SwfDecrMaskMatRelativePath = "Materials/SwfDecrMaskMat.mat";
|
||||
const string SwfMaskedMatRelativePathFmt = "Materials/SwfMaskedMat_{0}.mat";
|
||||
|
||||
void FillMaterialsCache() {
|
||||
var folder = Path.GetDirectoryName(AssetDatabase.GetAssetPath(this));
|
||||
SimpleMaterial = SafeLoadMaterial(Path.Combine(folder, SwfSimpleMatRelativePath), true);
|
||||
IncrMaskMaterial = SafeLoadMaterial(Path.Combine(folder, SwfIncrMaskMatRelativePath), true);
|
||||
DecrMaskMaterial = SafeLoadMaterial(Path.Combine(folder, SwfDecrMaskMatRelativePath), true);
|
||||
MaskedMaterials = new List<Material>();
|
||||
for ( var i = 0; i < int.MaxValue; ++i ) {
|
||||
var relative_path = string.Format(SwfMaskedMatRelativePathFmt, i);
|
||||
var mat = SafeLoadMaterial(Path.Combine(folder, relative_path), false);
|
||||
if ( mat ) {
|
||||
MaskedMaterials.Add(mat);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorUtility.SetDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
Material SafeLoadMaterial(string path, bool exception) {
|
||||
var material = AssetDatabase.LoadAssetAtPath<Material>(path);
|
||||
if ( !material && exception ) {
|
||||
throw new UnityException(string.Format(
|
||||
"SwfConverterSettings. Material not found: {0}",
|
||||
path));
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
Material CheckExistsMaterial(Material material) {
|
||||
if ( !material ) {
|
||||
throw new UnityException("SwfConverterSettings. Material not found");
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public Material GetMaskedMaterial(int stencil_id) {
|
||||
if ( MaskedMaterials == null || stencil_id < MaskedMaterials.Count ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
if ( stencil_id < 0 || stencil_id >= MaskedMaterials.Count ) {
|
||||
throw new UnityException(string.Format(
|
||||
"SwfConverterSettings. Unsupported stencil id: {0}",
|
||||
stencil_id));
|
||||
}
|
||||
return CheckExistsMaterial(MaskedMaterials[stencil_id]);
|
||||
}
|
||||
|
||||
public Material GetSimpleMaterial() {
|
||||
if ( !SimpleMaterial ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
return CheckExistsMaterial(SimpleMaterial);
|
||||
}
|
||||
|
||||
public Material GetIncrMaskMaterial() {
|
||||
if ( !IncrMaskMaterial ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
return CheckExistsMaterial(IncrMaskMaterial);
|
||||
}
|
||||
|
||||
public Material GetDecrMaskMaterial() {
|
||||
if ( !DecrMaskMaterial ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
return CheckExistsMaterial(DecrMaskMaterial);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void Reset() {
|
||||
DefaultSettings = SwfSettings.identity;
|
||||
FillMaterialsCache();
|
||||
}
|
||||
|
||||
public static SwfConverterSettings GetDefaultConverter() {
|
||||
var asset_guids = AssetDatabase.FindAssets("t:SwfConverterSettings");
|
||||
foreach ( var asset_guid in asset_guids ) {
|
||||
var converter_settings = AssetDatabase.LoadAssetAtPath<SwfConverterSettings>(
|
||||
AssetDatabase.GUIDToAssetPath(asset_guid));
|
||||
if ( converter_settings ) {
|
||||
return converter_settings;
|
||||
}
|
||||
}
|
||||
throw new UnityException("SwfConverterSettings asset not found");
|
||||
}
|
||||
|
||||
public static SwfSettings GetDefaultSettings() {
|
||||
return GetDefaultConverter().DefaultSettings;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6da591d87f967451298a275621e1fd5d
|
||||
timeCreated: 1471761453
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +1,13 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace FlashTools.Internal {
|
||||
[System.Serializable]
|
||||
public struct SwfSettings {
|
||||
public struct SwfSettingsData {
|
||||
public enum AtlasFilter {
|
||||
Point,
|
||||
Bilinear,
|
||||
@@ -28,9 +33,9 @@ namespace FlashTools.Internal {
|
||||
public AtlasFilter AtlasTextureFilter;
|
||||
public AtlasFormat AtlasTextureFormat;
|
||||
|
||||
public static SwfSettings identity {
|
||||
public static SwfSettingsData identity {
|
||||
get {
|
||||
return new SwfSettings{
|
||||
return new SwfSettingsData{
|
||||
MaxAtlasSize = 1024,
|
||||
AtlasPadding = 1,
|
||||
PixelsPerUnit = 100.0f,
|
||||
@@ -42,7 +47,7 @@ namespace FlashTools.Internal {
|
||||
}
|
||||
}
|
||||
|
||||
public bool CheckEquals(SwfSettings other) {
|
||||
public bool CheckEquals(SwfSettingsData other) {
|
||||
return
|
||||
MaxAtlasSize == other.MaxAtlasSize &&
|
||||
AtlasPadding == other.AtlasPadding &&
|
||||
@@ -54,4 +59,137 @@ namespace FlashTools.Internal {
|
||||
AtlasTextureFormat == other.AtlasTextureFormat;
|
||||
}
|
||||
}
|
||||
|
||||
public class SwfSettings : ScriptableObject {
|
||||
|
||||
public SwfSettingsData DefaultSettings;
|
||||
|
||||
[HideInInspector] public Material SimpleMaterial;
|
||||
[HideInInspector] public Material IncrMaskMaterial;
|
||||
[HideInInspector] public Material DecrMaskMaterial;
|
||||
[HideInInspector] public List<Material> MaskedMaterials;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Private
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
const string SwfSimpleMatName = "SwfSimpleMat";
|
||||
const string SwfIncrMaskMatName = "SwfIncrMaskMat";
|
||||
const string SwfDecrMaskMatName = "SwfDecrMaskMat";
|
||||
const string SwfMaskedMatNameFmt = "SwfMaskedMat_{0}";
|
||||
|
||||
void FillMaterialsCache() {
|
||||
SimpleMaterial = SafeLoadMaterial(SwfSimpleMatName, true);
|
||||
IncrMaskMaterial = SafeLoadMaterial(SwfIncrMaskMatName, true);
|
||||
DecrMaskMaterial = SafeLoadMaterial(SwfDecrMaskMatName, true);
|
||||
MaskedMaterials = new List<Material>();
|
||||
for ( var i = 0; i < int.MaxValue; ++i ) {
|
||||
var mat = SafeLoadMaterial(string.Format(SwfMaskedMatNameFmt, i), false);
|
||||
if ( mat ) {
|
||||
MaskedMaterials.Add(mat);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorUtility.SetDirty(this);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
Material SafeLoadMaterial(string name, bool exception) {
|
||||
var filter = string.Format("t:Material {0}", name);
|
||||
var material = LoadFirstAssetByFilter<Material>(filter);
|
||||
if ( !material && exception ) {
|
||||
throw new UnityException(string.Format(
|
||||
"SwfSettings. Material not found: {0}",
|
||||
name));
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
Material CheckExistsMaterial(Material material) {
|
||||
if ( !material ) {
|
||||
throw new UnityException("SwfSettings. Material not found");
|
||||
}
|
||||
return material;
|
||||
}
|
||||
|
||||
static T LoadFirstAssetByFilter<T>(string filter) where T : UnityEngine.Object {
|
||||
var guids = AssetDatabase.FindAssets(filter);
|
||||
foreach ( var guid in guids ) {
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var asset = AssetDatabase.LoadAssetAtPath<T>(path);
|
||||
if ( asset ) {
|
||||
return asset;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Functions
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
public Material GetMaskedMaterial(int stencil_id) {
|
||||
if ( MaskedMaterials == null || stencil_id < MaskedMaterials.Count ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
if ( stencil_id < 0 || stencil_id >= MaskedMaterials.Count ) {
|
||||
throw new UnityException(string.Format(
|
||||
"SwfSettings. Unsupported stencil id: {0}",
|
||||
stencil_id));
|
||||
}
|
||||
return CheckExistsMaterial(MaskedMaterials[stencil_id]);
|
||||
}
|
||||
|
||||
public Material GetSimpleMaterial() {
|
||||
if ( !SimpleMaterial ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
return CheckExistsMaterial(SimpleMaterial);
|
||||
}
|
||||
|
||||
public Material GetIncrMaskMaterial() {
|
||||
if ( !IncrMaskMaterial ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
return CheckExistsMaterial(IncrMaskMaterial);
|
||||
}
|
||||
|
||||
public Material GetDecrMaskMaterial() {
|
||||
if ( !DecrMaskMaterial ) {
|
||||
FillMaterialsCache();
|
||||
}
|
||||
return CheckExistsMaterial(DecrMaskMaterial);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
//
|
||||
// Messages
|
||||
//
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
void Reset() {
|
||||
DefaultSettings = SwfSettingsData.identity;
|
||||
FillMaterialsCache();
|
||||
}
|
||||
|
||||
public static SwfSettings GetSettingsHolder() {
|
||||
var settings_holder = LoadFirstAssetByFilter<SwfSettings>("t:SwfSettings");
|
||||
if ( !settings_holder ) {
|
||||
throw new UnityException("SwfSettings asset not found");
|
||||
}
|
||||
return settings_holder;
|
||||
}
|
||||
|
||||
public static SwfSettingsData GetDefaultSettings() {
|
||||
return GetSettingsHolder().DefaultSettings;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1fb47265b4e347af9d738537b50fe18
|
||||
timeCreated: 1472132899
|
||||
guid: 6da591d87f967451298a275621e1fd5d
|
||||
timeCreated: 1471761453
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -78,16 +78,16 @@ namespace FlashTools {
|
||||
public SwfAssetData Data;
|
||||
public Texture2D Atlas;
|
||||
public List<SwfClipAsset> Clips;
|
||||
public SwfSettings Settings;
|
||||
public SwfSettings Overridden;
|
||||
public SwfSettingsData Settings;
|
||||
public SwfSettingsData Overridden;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void Reset() {
|
||||
Data = new SwfAssetData();
|
||||
Atlas = null;
|
||||
Clips = new List<SwfClipAsset>();
|
||||
Settings = SwfConverterSettings.GetDefaultSettings();
|
||||
Overridden = SwfConverterSettings.GetDefaultSettings();
|
||||
Settings = SwfSettings.GetDefaultSettings();
|
||||
Overridden = SwfSettings.GetDefaultSettings();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user