From 4d0a94dc4d59277547e8ed5bd4a0f4196a7444cd Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Thu, 25 Aug 2016 23:04:27 +0700 Subject: [PATCH] baked materials and animations wip --- .../Resources/SwfConverterSettings.asset | 14 ++ .../Resources/SwfConverterSettings.asset.meta | 2 +- .../Editor/SwfAnimationAssetEditor.cs | 3 +- .../Editor/SwfAnimationAssetPostprocessor.cs | 28 ++-- .../Internal/Editor/SwfPostprocessor.cs | 10 +- .../Internal/Editor/SwfPropertyDrawers.cs | 48 ++++++ .../Scripts/Internal/SwfConverterSettings.cs | 153 +++++++++++------- .../Scripts/Internal/SwfPropertyAttributes.cs | 18 +++ .../Scripts/Internal/SwfSettings.cs | 57 +++++++ .../Scripts/Internal/SwfSettings.cs.meta | 12 ++ Assets/FlashTools/Scripts/SwfAnimation.cs | 19 +-- .../FlashTools/Scripts/SwfAnimationAsset.cs | 16 +- Assets/FlashTools/Scripts/SwfManager.cs | 124 -------------- 13 files changed, 284 insertions(+), 220 deletions(-) create mode 100644 Assets/FlashTools/Scripts/Internal/SwfSettings.cs create mode 100644 Assets/FlashTools/Scripts/Internal/SwfSettings.cs.meta diff --git a/Assets/FlashTools/Resources/SwfConverterSettings.asset b/Assets/FlashTools/Resources/SwfConverterSettings.asset index df7ce67..8e4be68 100644 --- a/Assets/FlashTools/Resources/SwfConverterSettings.asset +++ b/Assets/FlashTools/Resources/SwfConverterSettings.asset @@ -20,3 +20,17 @@ MonoBehaviour: AtlasForceSquare: 0 AtlasTextureFilter: 1 AtlasTextureFormat: 2 + SimpleMaterial: {fileID: 2100000, guid: e92fbe00d5b6d4a3aa9355a4b23f107d, type: 2} + IncrMaskMaterial: {fileID: 2100000, guid: e62e8efca5cac42c9a323961b58d05d6, type: 2} + DecrMaskMaterial: {fileID: 2100000, guid: d63a68532164d470d887fd2603e79ffa, type: 2} + MaskedMaterials: + - {fileID: 2100000, guid: 3902e0561ba6046079e975f4b8340dbd, type: 2} + - {fileID: 2100000, guid: 362db403211244f70830b07296318936, type: 2} + - {fileID: 2100000, guid: 43234b460d10f41088cbd327c045074b, type: 2} + - {fileID: 2100000, guid: f9e8b8b157ffa4866812a11237c48758, type: 2} + - {fileID: 2100000, guid: 04597a59523be4b939c0a5dfd05b973e, type: 2} + - {fileID: 2100000, guid: 502586963b8c243d48808238fb1210ef, type: 2} + - {fileID: 2100000, guid: dfbc0da8152b047b58270d40b138b36c, type: 2} + - {fileID: 2100000, guid: efeaba40d10a4417eb27036131ba80b1, type: 2} + - {fileID: 2100000, guid: 0f131b0532a4e4feaba67826153a42b7, type: 2} + - {fileID: 2100000, guid: ccd8fc1b2c96543ff9dc43ed384704a2, type: 2} diff --git a/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta b/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta index 34f7f50..9e8688b 100644 --- a/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta +++ b/Assets/FlashTools/Resources/SwfConverterSettings.asset.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 guid: ea1dd488b8903439b90ce209ff82574c -timeCreated: 1472013183 +timeCreated: 1472140695 licenseType: Free NativeFormatImporter: userData: diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs index 27eb22b..1f16e64 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetEditor.cs @@ -64,8 +64,7 @@ namespace FlashTools.Internal { var anim_go = new GameObject(_asset.name); anim_go.AddComponent(); anim_go.AddComponent(); - anim_go.AddComponent().Asset = _asset; - anim_go.GetComponent().InitStuff(); //FIXME + anim_go.AddComponent().InitWithAsset(_asset); return anim_go; } return null; diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs index 4d1a40d..5b69e04 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfAnimationAssetPostprocessor.cs @@ -100,14 +100,14 @@ namespace FlashTools.Internal { } static FilterMode SwfAtlasFilterToImporterFilter( - SwfConverterSettings.SwfAtlasFilter filter) + SwfSettings.AtlasFilter filter) { switch ( filter ) { - case SwfConverterSettings.SwfAtlasFilter.Point: + case SwfSettings.AtlasFilter.Point: return FilterMode.Point; - case SwfConverterSettings.SwfAtlasFilter.Bilinear: + case SwfSettings.AtlasFilter.Bilinear: return FilterMode.Bilinear; - case SwfConverterSettings.SwfAtlasFilter.Trilinear: + case SwfSettings.AtlasFilter.Trilinear: return FilterMode.Trilinear; default: throw new UnityException(string.Format( @@ -117,16 +117,16 @@ namespace FlashTools.Internal { } static TextureImporterFormat SwfAtlasFormatToImporterFormat( - SwfConverterSettings.SwfAtlasFormat format) + SwfSettings.AtlasFormat format) { switch ( format ) { - case SwfConverterSettings.SwfAtlasFormat.AutomaticCompressed: + case SwfSettings.AtlasFormat.AutomaticCompressed: return TextureImporterFormat.AutomaticCompressed; - case SwfConverterSettings.SwfAtlasFormat.Automatic16bit: + case SwfSettings.AtlasFormat.Automatic16bit: return TextureImporterFormat.Automatic16bit; - case SwfConverterSettings.SwfAtlasFormat.AutomaticTruecolor: + case SwfSettings.AtlasFormat.AutomaticTruecolor: return TextureImporterFormat.AutomaticTruecolor; - case SwfConverterSettings.SwfAtlasFormat.AutomaticCrunched: + case SwfSettings.AtlasFormat.AutomaticCrunched: return TextureImporterFormat.AutomaticCrunched; default: throw new UnityException(string.Format( @@ -228,21 +228,21 @@ namespace FlashTools.Internal { } } - var swf_manager = SwfManager.GetInstance(true); + var default_converter = SwfConverterSettings.GetDefaultConverter(); for ( var i = 0; i < _groups.Count; ++i ) { var group = _groups[i]; switch ( group.Type ) { case SwfAnimationInstanceType.Mask: - group.Material = swf_manager.GetIncrMaskMaterial(); + group.Material = default_converter.GetIncrMaskMaterial(); break; case SwfAnimationInstanceType.Group: - group.Material = swf_manager.GetSimpleMaterial(); + group.Material = default_converter.GetSimpleMaterial(); break; case SwfAnimationInstanceType.Masked: - group.Material = swf_manager.GetMaskedMaterial(group.ClipDepth); + group.Material = default_converter.GetMaskedMaterial(group.ClipDepth); break; case SwfAnimationInstanceType.MaskReset: - group.Material = swf_manager.GetDecrMaskMaterial(); + group.Material = default_converter.GetDecrMaskMaterial(); break; } } diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs index 0b8182a..76f6436 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfPostprocessor.cs @@ -238,9 +238,9 @@ namespace FlashTools.Internal { } static Rect[] PackAndSaveBitmapsAtlas( - string swf_asset, - Texture2D[] textures, - SwfConverterSettings.Settings settings) + string swf_asset, + Texture2D[] textures, + SwfSettings settings) { var atlas_info = PackBitmapsAtlas(textures, settings); File.WriteAllBytes( @@ -254,8 +254,8 @@ namespace FlashTools.Internal { } static BitmapsAtlasInfo PackBitmapsAtlas( - Texture2D[] textures, - SwfConverterSettings.Settings settings) + Texture2D[] textures, + SwfSettings settings) { var atlas_padding = Mathf.Max(0, settings.AtlasPadding); var max_atlas_size = Mathf.Max(32, settings.AtlasPowerOfTwo diff --git a/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs b/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs index f702ef9..dbb299b 100644 --- a/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs +++ b/Assets/FlashTools/Scripts/Internal/Editor/SwfPropertyDrawers.cs @@ -5,6 +5,54 @@ using System.Collections.Generic; namespace FlashTools.Internal.SwfEditorTools { + // + // SwfIntRange + // + + [CustomPropertyDrawer(typeof(SwfIntRangeAttribute))] + public class SwfIntRangeDrawer : PropertyDrawer { + static void ValidateProperty(SerializedProperty property, int min, int max) { + if ( property.propertyType == SerializedPropertyType.Integer ) { + var clamp = Mathf.Clamp(property.intValue, min, max); + if ( clamp != property.intValue ) { + property.intValue = clamp; + property.serializedObject.ApplyModifiedProperties(); + } + } + } + public override void OnGUI( + Rect position, SerializedProperty property, GUIContent label) + { + var attr = attribute as SwfIntRangeAttribute; + ValidateProperty(property, attr.Min, attr.Max); + EditorGUI.PropertyField(position, property, label, true); + } + } + + // + // SwfFloatRange + // + + [CustomPropertyDrawer(typeof(SwfFloatRangeAttribute))] + public class SwfFloatRangeDrawer : PropertyDrawer { + static void ValidateProperty(SerializedProperty property, float min, float max) { + if ( property.propertyType == SerializedPropertyType.Float ) { + var clamp = Mathf.Clamp(property.floatValue, min, max); + if ( clamp != property.floatValue ) { + property.floatValue = clamp; + property.serializedObject.ApplyModifiedProperties(); + } + } + } + public override void OnGUI( + Rect position, SerializedProperty property, GUIContent label) + { + var attr = attribute as SwfFloatRangeAttribute; + ValidateProperty(property, attr.Min, attr.Max); + EditorGUI.PropertyField(position, property, label, true); + } + } + // // SwfSortingLayerDrawer // diff --git a/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs b/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs index 79ec58d..6e26c4a 100644 --- a/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs +++ b/Assets/FlashTools/Scripts/Internal/SwfConverterSettings.cs @@ -1,4 +1,5 @@ using UnityEngine; +using System.Collections.Generic; #if UNITY_EDITOR using UnityEditor; @@ -7,65 +8,107 @@ using System.IO; namespace FlashTools.Internal { public class SwfConverterSettings : ScriptableObject { - public enum SwfAtlasFilter { - Point, - Bilinear, - Trilinear - } - public enum SwfAtlasFormat { - AutomaticCompressed, - Automatic16bit, - AutomaticTruecolor, - AutomaticCrunched - } + // --------------------------------------------------------------------- + // + // Constants + // + // --------------------------------------------------------------------- - [System.Serializable] - public struct Settings { - [SwfPowerOfTwoIfAttribute(5, 13, "AtlasPowerOfTwo")] - public int MaxAtlasSize; - public int AtlasPadding; - public int PixelsPerUnit; - public bool GenerateMipMaps; - public bool AtlasPowerOfTwo; - public bool AtlasForceSquare; - public SwfAtlasFilter AtlasTextureFilter; - public SwfAtlasFormat AtlasTextureFormat; + const string DefaultBasePath = "Assets/FlashTools/Resources/"; + const string DefaultSettingsPath = DefaultBasePath + "SwfConverterSettings.asset"; + const string SwfSimpleMatPath = DefaultBasePath + "Materials/SwfSimpleMat.mat"; + const string SwfIncrMaskMatPath = DefaultBasePath + "Materials/SwfIncrMaskMat.mat"; + const string SwfDecrMaskMatPath = DefaultBasePath + "Materials/SwfDecrMaskMat.mat"; + const string SwfMaskedMatPathFmt = DefaultBasePath + "Materials/SwfMaskedMat_{0}.mat"; - public static Settings identity { - get { - return new Settings{ - MaxAtlasSize = 1024, - AtlasPadding = 1, - PixelsPerUnit = 100, - GenerateMipMaps = true, - AtlasPowerOfTwo = true, - AtlasForceSquare = false, - AtlasTextureFilter = SwfAtlasFilter.Bilinear, - AtlasTextureFormat = SwfAtlasFormat.AutomaticTruecolor}; - } - } + // --------------------------------------------------------------------- + // + // Properties + // + // --------------------------------------------------------------------- - public bool CheckEquals(Settings other) { - return - MaxAtlasSize == other.MaxAtlasSize && - AtlasPadding == other.AtlasPadding && - PixelsPerUnit == other.PixelsPerUnit && - GenerateMipMaps == other.GenerateMipMaps && - AtlasPowerOfTwo == other.AtlasPowerOfTwo && - AtlasForceSquare == other.AtlasForceSquare && - AtlasTextureFilter == other.AtlasTextureFilter && - AtlasTextureFormat == other.AtlasTextureFormat; - } - } - public Settings DefaultSettings; + [Header("Settings")] + public SwfSettings DefaultSettings; + + [Header("Materials cache")] + public Material SimpleMaterial; + public Material IncrMaskMaterial; + public Material DecrMaskMaterial; + public List MaskedMaterials; #if UNITY_EDITOR - void Reset() { - DefaultSettings = Settings.identity; + + // --------------------------------------------------------------------- + // + // Private + // + // --------------------------------------------------------------------- + + void FillMaterialsCache() { + SimpleMaterial = SafeLoadMaterial(SwfSimpleMatPath, true); + IncrMaskMaterial = SafeLoadMaterial(SwfIncrMaskMatPath, true); + DecrMaskMaterial = SafeLoadMaterial(SwfDecrMaskMatPath, true); + MaskedMaterials = new List(); + for ( var i = 0; i < int.MaxValue; ++i ) { + var mat = SafeLoadMaterial(string.Format(SwfMaskedMatPathFmt, i), false); + if ( mat ) { + MaskedMaterials.Add(mat); + } else { + break; + } + } } - public static Settings GetDefaultSettings() { + Material SafeLoadMaterial(string path, bool exception) { + var material = AssetDatabase.LoadAssetAtPath(path); + if ( !material && exception ) { + throw new UnityException(string.Format( + "SwfManager. Material not found: {0}", + path)); + } + return material; + } + + // --------------------------------------------------------------------- + // + // Functions + // + // --------------------------------------------------------------------- + + public Material GetMaskedMaterial(int stencil_id) { + if ( stencil_id < 0 || stencil_id >= MaskedMaterials.Count ) { + throw new UnityException(string.Format( + "SwfConverterSettings. Unsupported stencil id: {0}", + stencil_id)); + } + return MaskedMaterials[stencil_id]; + } + + public Material GetSimpleMaterial() { + return SimpleMaterial; + } + + public Material GetIncrMaskMaterial() { + return IncrMaskMaterial; + } + + public Material GetDecrMaskMaterial() { + return DecrMaskMaterial; + } + + // --------------------------------------------------------------------- + // + // Messages + // + // --------------------------------------------------------------------- + + void Reset() { + DefaultSettings = SwfSettings.identity; + FillMaterialsCache(); + } + + public static SwfConverterSettings GetDefaultConverter() { var settings_path = DefaultSettingsPath; var settings = AssetDatabase.LoadAssetAtPath(settings_path); if ( !settings ) { @@ -74,13 +117,11 @@ namespace FlashTools.Internal { AssetDatabase.CreateAsset(settings, settings_path); AssetDatabase.SaveAssets(); } - return settings.DefaultSettings; + return settings; } - static string DefaultSettingsPath { - get { - return "Assets/FlashTools/Resources/SwfConverterSettings.asset"; - } + public static SwfSettings GetDefaultSettings() { + return GetDefaultConverter().DefaultSettings; } static void CreateAssetDatabaseFolders(string path) { diff --git a/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs b/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs index 0586a46..704ee19 100644 --- a/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs +++ b/Assets/FlashTools/Scripts/Internal/SwfPropertyAttributes.cs @@ -1,6 +1,24 @@ using UnityEngine; namespace FlashTools.Internal { + public class SwfIntRangeAttribute : PropertyAttribute { + public int Min; + public int Max; + public SwfIntRangeAttribute(int min, int max) { + Min = min; + Max = max; + } + } + + public class SwfFloatRangeAttribute : PropertyAttribute { + public float Min; + public float Max; + public SwfFloatRangeAttribute(float min, float max) { + Min = min; + Max = max; + } + } + public class SwfSortingLayerAttribute : PropertyAttribute { } diff --git a/Assets/FlashTools/Scripts/Internal/SwfSettings.cs b/Assets/FlashTools/Scripts/Internal/SwfSettings.cs new file mode 100644 index 0000000..8acccb7 --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/SwfSettings.cs @@ -0,0 +1,57 @@ +using UnityEngine; + +namespace FlashTools.Internal { + [System.Serializable] + public struct SwfSettings { + public enum AtlasFilter { + Point, + Bilinear, + Trilinear + } + + public enum AtlasFormat { + AutomaticCompressed, + Automatic16bit, + AutomaticTruecolor, + AutomaticCrunched + } + + [SwfPowerOfTwoIfAttribute(5, 13, "AtlasPowerOfTwo")] + public int MaxAtlasSize; + [SwfIntRange(0, int.MaxValue)] + public int AtlasPadding; + [SwfFloatRange(float.Epsilon, float.MaxValue)] + public float PixelsPerUnit; + public bool GenerateMipMaps; + public bool AtlasPowerOfTwo; + public bool AtlasForceSquare; + public AtlasFilter AtlasTextureFilter; + public AtlasFormat AtlasTextureFormat; + + public static SwfSettings identity { + get { + return new SwfSettings{ + MaxAtlasSize = 1024, + AtlasPadding = 1, + PixelsPerUnit = 100.0f, + GenerateMipMaps = true, + AtlasPowerOfTwo = true, + AtlasForceSquare = false, + AtlasTextureFilter = AtlasFilter.Bilinear, + AtlasTextureFormat = AtlasFormat.AutomaticTruecolor}; + } + } + + public bool CheckEquals(SwfSettings other) { + return + MaxAtlasSize == other.MaxAtlasSize && + AtlasPadding == other.AtlasPadding && + Mathf.Approximately(PixelsPerUnit, other.PixelsPerUnit) && + GenerateMipMaps == other.GenerateMipMaps && + AtlasPowerOfTwo == other.AtlasPowerOfTwo && + AtlasForceSquare == other.AtlasForceSquare && + AtlasTextureFilter == other.AtlasTextureFilter && + AtlasTextureFormat == other.AtlasTextureFormat; + } + } +} \ No newline at end of file diff --git a/Assets/FlashTools/Scripts/Internal/SwfSettings.cs.meta b/Assets/FlashTools/Scripts/Internal/SwfSettings.cs.meta new file mode 100644 index 0000000..07dc11f --- /dev/null +++ b/Assets/FlashTools/Scripts/Internal/SwfSettings.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b1fb47265b4e347af9d738537b50fe18 +timeCreated: 1472132899 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/FlashTools/Scripts/SwfAnimation.cs b/Assets/FlashTools/Scripts/SwfAnimation.cs index 2f97692..4c7027a 100644 --- a/Assets/FlashTools/Scripts/SwfAnimation.cs +++ b/Assets/FlashTools/Scripts/SwfAnimation.cs @@ -6,16 +6,16 @@ namespace FlashTools { [ExecuteInEditMode] [RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))] public class SwfAnimation : MonoBehaviour { - public SwfAnimationAsset Asset = null; + public SwfAnimationAsset Asset = null; [SwfSortingLayer] - public string SortingLayer = "Default"; - public int SortingOrder = 0; + public string SortingLayer = "Default"; + public int SortingOrder = 0; - MeshFilter _meshFilter = null; - MeshRenderer _meshRenderer = null; + bool _inited = false; + MaterialPropertyBlock _matPropBlock = null; - bool _inited = false; - MaterialPropertyBlock _matPropBlock = null; + MeshFilter _meshFilter = null; + MeshRenderer _meshRenderer = null; int _current_frame = 0; float _frame_timer = 0.0f; @@ -38,7 +38,8 @@ namespace FlashTools { // // ------------------------------------------------------------------------ - public void InitStuff() { + public void InitWithAsset(SwfAnimationAsset asset) { + Asset = asset; if ( Asset && !_inited ) { _inited = true; _matPropBlock = new MaterialPropertyBlock(); @@ -91,7 +92,7 @@ namespace FlashTools { void Awake() { _meshFilter = GetComponent(); _meshRenderer = GetComponent(); - InitStuff(); + InitWithAsset(Asset); } void OnEnable() { diff --git a/Assets/FlashTools/Scripts/SwfAnimationAsset.cs b/Assets/FlashTools/Scripts/SwfAnimationAsset.cs index 67faea8..46faab9 100644 --- a/Assets/FlashTools/Scripts/SwfAnimationAsset.cs +++ b/Assets/FlashTools/Scripts/SwfAnimationAsset.cs @@ -72,16 +72,14 @@ namespace FlashTools { public class SwfAnimationAsset : ScriptableObject { [System.Serializable] public class BakedFrame { - public Mesh Mesh = null; - public Material[] Materials = new Material[0]; + public Mesh Mesh; + public Material[] Materials; } - public SwfAnimationData Data; - public Texture2D Atlas; - public List BakedFrames; - #if UNITY_EDITOR - public SwfConverterSettings.Settings Settings; - public SwfConverterSettings.Settings Overridden; - #endif + public SwfAnimationData Data; + public Texture2D Atlas; + public List BakedFrames; + public SwfSettings Settings; + public SwfSettings Overridden; #if UNITY_EDITOR void Reset() { diff --git a/Assets/FlashTools/Scripts/SwfManager.cs b/Assets/FlashTools/Scripts/SwfManager.cs index 7def9b4..231fcb1 100644 --- a/Assets/FlashTools/Scripts/SwfManager.cs +++ b/Assets/FlashTools/Scripts/SwfManager.cs @@ -1,35 +1,15 @@ using UnityEngine; using System.Collections.Generic; -#if UNITY_EDITOR -using UnityEditor; -#endif - namespace FlashTools { [ExecuteInEditMode] public class SwfManager : MonoBehaviour { - // --------------------------------------------------------------------- - // - // Constants - // - // --------------------------------------------------------------------- - - const string SwfSimpleMatPath = "Assets/FlashTools/Resources/Materials/SwfSimpleMat.mat"; - const string SwfIncrMaskMatPath = "Assets/FlashTools/Resources/Materials/SwfIncrMaskMat.mat"; - const string SwfDecrMaskMatPath = "Assets/FlashTools/Resources/Materials/SwfDecrMaskMat.mat"; - const string SwfMaskedMatPathFmt = "Assets/FlashTools/Resources/Materials/SwfMaskedMat_{0}.mat"; - // --------------------------------------------------------------------- // // Properties // // --------------------------------------------------------------------- - [SerializeField] [HideInInspector] Material _simpleMaterial = null; - [SerializeField] [HideInInspector] Material _incrMaskMaterial = null; - [SerializeField] [HideInInspector] Material _decrMaskMaterial = null; - [SerializeField] [HideInInspector] List _maskedMaterials = null; - HashSet _animations = new HashSet(); // --------------------------------------------------------------------- @@ -70,79 +50,6 @@ namespace FlashTools { // // --------------------------------------------------------------------- - void FillMaterialsCache() { - /* - if ( !_maskedShader ) { - _maskedShader = SafeLoadShader(SwfMaskedShaderPath); - } - if ( _maskedMaterials == null ) { - _maskedMaterials = new List(SwfStencilIdCount); - for ( var i = 0; i < _maskedMaterials.Capacity; ++i ) { - var material = new Material(_maskedShader); - material.SetInt("_StencilID", i); - _maskedMaterials.Add(material); - } - } - if ( !_simpleMaterial ) { - _simpleMaterial = new Material(SafeLoadShader(SwfSimpleShaderPath)); - } - if ( !_incrMaskMaterial ) { - _incrMaskMaterial = new Material(SafeLoadShader(SwfIncrMaskShaderPath)); - } - if ( !_decrMaskMaterial ) { - _decrMaskMaterial = new Material(SafeLoadShader(SwfDecrMaskShaderPath)); - }*/ - - if ( !_simpleMaterial ) { - _simpleMaterial = SafeLoadMaterial(SwfSimpleMatPath, true); - } - - if ( !_incrMaskMaterial ) { - _incrMaskMaterial = SafeLoadMaterial(SwfIncrMaskMatPath, true); - } - - if ( !_decrMaskMaterial ) { - _decrMaskMaterial = SafeLoadMaterial(SwfDecrMaskMatPath, true); - } - - if ( _maskedMaterials == null ) { - _maskedMaterials = new List(); - for ( var i = 0; i < 100; ++i ) { - var mat = SafeLoadMaterial(string.Format(SwfMaskedMatPathFmt, i), false); - if ( mat ) { - _maskedMaterials.Add(mat); - } else { - break; - } - } - } - } - - Material SafeLoadMaterial(string path, bool exception) { - #if UNITY_EDITOR - var material = AssetDatabase.LoadAssetAtPath(path); - if ( !material && exception ) { - throw new UnityException(string.Format( - "SwfManager. Material not found: {0}", - path)); - } - return material; - #else - throw new UnityException("IMPLME!"); - #endif - } - - /* - Shader SafeLoadShader(string path) { - var shader = Shader.Find(path); - if ( !shader ) { - throw new UnityException(string.Format( - "SwfManager. Shader not found: {0}", - path)); - } - return shader; - }*/ - void GrabEnabledAnimations() { var all_animations = FindObjectsOfType(); for ( int i = 0, e = all_animations.Length; i < e; ++i ) { @@ -164,43 +71,12 @@ namespace FlashTools { } } - // --------------------------------------------------------------------- - // - // Functions - // - // --------------------------------------------------------------------- - - public Material GetMaskedMaterial(int stencil_id) { - if ( stencil_id < 0 || stencil_id >= _maskedMaterials.Count ) { - throw new UnityException(string.Format( - "SwfManager. Unsupported stencil id: {0}", - stencil_id)); - } - return _maskedMaterials[stencil_id]; - } - - public Material GetSimpleMaterial() { - return _simpleMaterial; - } - - public Material GetIncrMaskMaterial() { - return _incrMaskMaterial; - } - - public Material GetDecrMaskMaterial() { - return _decrMaskMaterial; - } - // --------------------------------------------------------------------- // // Messages // // --------------------------------------------------------------------- - void Awake() { - FillMaterialsCache(); - } - void OnEnable() { GrabEnabledAnimations(); }