From 804d1156dab643574710867f953d89c9fe238b52 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Wed, 5 Feb 2020 20:23:52 +0100 Subject: [PATCH] [unity] Spine Preferences now provide an `Atlas Texture Reference Settings` parameter for applying customizable texture import settings at all newly imported Spine atlas textures. Materials `Straight Alpha Texture` parameter is also configured accordingly. Closes #1410, closes #1524. --- CHANGELOG.md | 2 + .../spine-unity/Editor/ImporterPresets.meta | 9 ++ .../ImporterPresets/PMAPresetTemplate.png | Bin 0 -> 3276 bytes .../PMAPresetTemplate.png.meta | 82 ++++++++++++++++++ .../StraightAlphaPresetTemplate.png | Bin 0 -> 3101 bytes .../StraightAlphaPresetTemplate.png.meta | 82 ++++++++++++++++++ .../Editor/Utility/AssetUtility.cs | 48 ++++++++-- .../spine-unity/Editor/Utility/Preferences.cs | 34 +++++++- .../Editor/Utility/SpineEditorUtilities.cs | 5 +- .../Editor/Windows/SpinePreferences.cs | 13 ++- .../spine-unity/Utility/MaterialChecks.cs | 12 +++ 11 files changed, 278 insertions(+), 9 deletions(-) create mode 100644 spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets.meta create mode 100644 spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png create mode 100644 spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png.meta create mode 100644 spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png create mode 100644 spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png.meta diff --git a/CHANGELOG.md b/CHANGELOG.md index 1670b06eb..dcdb9edc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -214,6 +214,8 @@ The shaders can be assigned to materials as usual and will respect your settings of the assigned `UniversalRenderPipelineAsset` under `Project Settings - Graphics`. * **Restrictions** As all Spine shaders, the URP shaders **do not support `Premultiply alpha` (PMA) atlas textures in Linear color space**. Please export your atlas textures as `straight alpha` textures with disabled `Premultiply alpha` setting when using Linear color space. You can check the current color space via `Project Settings - Player - Other Settings - Color Space.`. * **Example:** You can find an example scene in the package under `com.esotericsoftware.spine.urp-shaders-3.8/Examples/URP Shaders.unity` that demonstrates usage of the URP shaders. + * Spine Preferences now provide an **`Atlas Texture Reference Settings`** parameter for applying customizable texture import settings at all newly imported Spine atlas textures. + When exporting atlas textures from Spine with `Premultiply alpha` enabled (the default), you can leave it at `PMAPresetTemplate`. If you have disabled `Premultiply alpha`, set it to the included `StraightAlphaPresetTemplate` asset. You can also create your own reference `Texture2D` asset and assign it here (include `PMA` or `Straight` in the name). Materials created for imported textures will also have the `Straight Alpha Texture` parameter configured accordingly. * **Changes of default values** * `SkeletonMecanim`'s `Layer Mix Mode` now defaults to `MixMode.MixNext` instead of `MixMode.MixAlways`. diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets.meta b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets.meta new file mode 100644 index 000000000..39eef80bd --- /dev/null +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: a018d561e5df35848bcabbe2809c7549 +folderAsset: yes +timeCreated: 1580402759 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png new file mode 100644 index 0000000000000000000000000000000000000000..b40be5a3e68b50344dc92118d297178dff7bdebe GIT binary patch literal 3276 zcmV;-3^VhIP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmR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(yud_ z4BPjf*6TI5x3|=4H5|v`37gI4*B-+#&~=@3It_s1IB1&2!@~o*t`l}$m+5p0 zz+^JPb=`xT{BN#YE^~2lf$O^1whge;-)^@VjYcGsNzTvDegEw2j8>~fGMOaw_4Res zFJXAGSP%dl6<|J}9~WRYn*|dH0D>I|0D>h9CJ_7&1OP_`_!$78PMl6VAHT2w0000< KMNUMnLSTY3(jJol literal 0 HcmV?d00001 diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png.meta b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png.meta new file mode 100644 index 000000000..8153700c4 --- /dev/null +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/PMAPresetTemplate.png.meta @@ -0,0 +1,82 @@ +fileFormatVersion: 2 +guid: 77f055f38c1115f42a2df16b0428c4e6 +timeCreated: 1580402818 +licenseType: Pro +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png new file mode 100644 index 0000000000000000000000000000000000000000..4db601f8f9f78e72ae2d592dcc43a147c4a5c8aa GIT binary patch literal 3101 zcmV+&4C3>NP)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=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A-YuS64wkBy=9dm`4cXeX z4c}I@?e+FW+b@^RDBHV(wnMq2zdX3SWv9u`%{xC-q*U}&`cyXV(%rRT*Z6MH?i+i& z_B8C(+grT%{XWUQ+f@NoP1R=AW&26{v-dx)iK^-Nmiuj8txj!m?Z*Ss1N{dh4z}01 z)YTo*JycSU)+_5r4#yw9{+;i4Ee$peRgIj+;v;ZGdF1K$3E%e~4LaI(jC-u%2h$&R z9cLXcYC@Xwnns&bn)_Q~Te?roKGD|d-g^8;+aC{{G(1^(O7m37Y1-+6)01cN&y1aw zoqc{T`P^XJqPBbIW6s}d4{z_f5Om?vMgNQEJG?v2T=KYd^0M3I6IZxbny)%vZR&LD zJpPl@Psh8QyPB@KTx+@RdcC!KX7}kEo;S|j^u2lU7XQ}Oo;f|;z4Ll+_r>@1-xl3| zawq-H%e&ckC+@AhPrP6BKT#_XdT7&;F71j}Joy zkC~6lh7E@6o;W@^IpRNZ{ptLtL(gQ-CY~4mqW;US7Zxvm_|@yz&e53Bp_lTPlfP|z zrTyx_>lv@x#=^!PzR7qqF<$gm`|ZJZ+;<)Cqu&ot2z=0000WV@Og>004R=004l4008;_004mL004C`008P>0026e000+nl3&F} z0003fwyt@cb43t`+C^>KZpL94aJ^nZM8$<61bFYOk%bVp zECRqh<zCH0qsFN;(XKGP4qq0#Ihwl+wLbMMRldYhq?~&grr&x-5%!U8h~w6+Y-U zN+~G-6_FnU5Rslvr!9yWW8o`G(Dyy2X+q8!0JaqWrU9LEh%thhk#nw=u>iO=-tl-u z(=_njLqy=5t2W*Z^sBSW<$`rxaXz05f3r`*eG~)uum*Uy26(duc(n$2wgz~y26(at rc-#SYfPW8Q{tWj?Xbxcd9e)l0LLEg+`EvGH00000NkvXXu0mjffW5hn literal 0 HcmV?d00001 diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png.meta b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png.meta new file mode 100644 index 000000000..721d7ca30 --- /dev/null +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/ImporterPresets/StraightAlphaPresetTemplate.png.meta @@ -0,0 +1,82 @@ +fileFormatVersion: 2 +guid: ade885c25e49d7740b5c00d4e10a6197 +timeCreated: 1580402818 +licenseType: Pro +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -1 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs index a16ac3d77..11634e578 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs @@ -492,7 +492,10 @@ namespace Spine.Unity.Editor { Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)); bool textureIsUninitialized = texturesWithoutMetaFile != null && texturesWithoutMetaFile.Contains(texturePath); if (SpineEditorUtilities.Preferences.setTextureImporterSettings && textureIsUninitialized) { - SetDefaultTextureSettings(texturePath, atlasAsset); + if (string.IsNullOrEmpty(SpineEditorUtilities.Preferences.textureSettingsReference)) + SetDefaultTextureSettings(texturePath, atlasAsset); + else + SetReferenceTextureSettings(texturePath, atlasAsset, SpineEditorUtilities.Preferences.textureSettingsReference); } string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]); @@ -506,6 +509,7 @@ namespace Spine.Unity.Editor { if (mat == null) { mat = new Material(Shader.Find(SpineEditorUtilities.Preferences.defaultShader)); + ApplyPMAOrStraightAlphaSettings(mat, SpineEditorUtilities.Preferences.textureSettingsReference); AssetDatabase.CreateAsset(mat, materialPath); } else { vestigialMaterials.Remove(mat); @@ -515,8 +519,7 @@ namespace Spine.Unity.Editor { mat.mainTexture = texture; EditorUtility.SetDirty(mat); - AssetDatabase.SaveAssets(); - + // note: don't call AssetDatabase.SaveAssets() since this would trigger OnPostprocessAllAssets() every time unnecessarily. populatingMaterials.Add(mat); //atlasAsset.materials[i] = mat; } @@ -587,9 +590,44 @@ namespace Spine.Unity.Editor { AssetDatabase.SaveAssets(); return true; } -#endregion -#region Import SkeletonData (json or binary) + static bool SetReferenceTextureSettings (string texturePath, SpineAtlasAsset atlasAsset, string referenceAssetPath) { + TextureImporter reference = TextureImporter.GetAtPath(referenceAssetPath) as TextureImporter; + if (reference == null) + SetDefaultTextureSettings(texturePath, atlasAsset); + + TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath); + if (texImporter == null) { + Debug.LogWarning(string.Format("{0}: Texture asset \"{1}\" not found. Skipping. Please check your atlas file for renamed files.", atlasAsset.name, texturePath), atlasAsset); + return false; + } + + texImporter.sRGBTexture = reference.sRGBTexture; + texImporter.textureCompression = reference.textureCompression; + texImporter.alphaSource = reference.alphaSource; + texImporter.mipmapEnabled = reference.mipmapEnabled; + texImporter.alphaIsTransparency = reference.alphaIsTransparency; + texImporter.spriteImportMode = reference.spriteImportMode; + texImporter.maxTextureSize = reference.maxTextureSize; + texImporter.isReadable = reference.isReadable; + texImporter.filterMode = reference.filterMode; + texImporter.mipmapFilter = reference.mipmapFilter; + + EditorUtility.SetDirty(texImporter); + AssetDatabase.ImportAsset(texturePath); + AssetDatabase.SaveAssets(); + return true; + } + + static void ApplyPMAOrStraightAlphaSettings (Material material, string referenceTextureSettings) { + bool isUsingPMAWorkflow = string.IsNullOrEmpty(referenceTextureSettings) || + (!referenceTextureSettings.ToLower().Contains("straight") && referenceTextureSettings.ToLower().Contains("pma")); + + MaterialChecks.EnablePMAAtMaterial(material, isUsingPMAWorkflow); + } + #endregion + + #region Import SkeletonData (json or binary) internal static string GetSkeletonDataAssetFilePath(TextAsset spineJson) { string primaryName = Path.GetFileNameWithoutExtension(spineJson.name); string assetPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(spineJson)).Replace('\\', '/'); diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs index 7ef2082d6..037f51de1 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/Preferences.cs @@ -121,6 +121,9 @@ namespace Spine.Unity.Editor { const string SET_TEXTUREIMPORTER_SETTINGS_KEY = "SPINE_SET_TEXTUREIMPORTER_SETTINGS"; public static bool setTextureImporterSettings = SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS; + const string TEXTURE_SETTINGS_REFERENCE_KEY = "SPINE_TEXTURE_SETTINGS_REFERENCE"; + public static string textureSettingsReference = SpinePreferences.DEFAULT_TEXTURE_SETTINGS_REFERENCE; + const string ATLASTXT_WARNING_KEY = "SPINE_ATLASTXT_WARNING"; public static bool atlasTxtImportWarning = SpinePreferences.DEFAULT_ATLASTXT_WARNING; @@ -154,6 +157,7 @@ namespace Spine.Unity.Editor { defaultShader = EditorPrefs.GetString(DEFAULT_SHADER_KEY, SpinePreferences.DEFAULT_DEFAULT_SHADER); showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS); setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); + textureSettingsReference = EditorPrefs.GetString(TEXTURE_SETTINGS_REFERENCE_KEY, SpinePreferences.DEFAULT_TEXTURE_SETTINGS_REFERENCE); autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, SpinePreferences.DEFAULT_AUTO_RELOAD_SCENESKELETONS); mecanimEventIncludeFolderName = EditorPrefs.GetBool(MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, SpinePreferences.DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME); atlasTxtImportWarning = EditorPrefs.GetBool(ATLASTXT_WARNING_KEY, SpinePreferences.DEFAULT_ATLASTXT_WARNING); @@ -171,6 +175,7 @@ namespace Spine.Unity.Editor { newPreferences.defaultShader = EditorPrefs.GetString(DEFAULT_SHADER_KEY, SpinePreferences.DEFAULT_DEFAULT_SHADER); newPreferences.showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, SpinePreferences.DEFAULT_SHOW_HIERARCHY_ICONS); newPreferences.setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, SpinePreferences.DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); + newPreferences.textureSettingsReference = EditorPrefs.GetString(TEXTURE_SETTINGS_REFERENCE_KEY, SpinePreferences.DEFAULT_TEXTURE_SETTINGS_REFERENCE); newPreferences.autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, SpinePreferences.DEFAULT_AUTO_RELOAD_SCENESKELETONS); newPreferences.mecanimEventIncludeFolderName = EditorPrefs.GetBool(MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, SpinePreferences.DEFAULT_MECANIM_EVENT_INCLUDE_FOLDERNAME); newPreferences.atlasTxtImportWarning = EditorPrefs.GetBool(ATLASTXT_WARNING_KEY, SpinePreferences.DEFAULT_ATLASTXT_WARNING); @@ -186,6 +191,7 @@ namespace Spine.Unity.Editor { EditorPrefs.SetString(DEFAULT_SHADER_KEY, preferences.defaultShader); EditorPrefs.SetBool(SHOW_HIERARCHY_ICONS_KEY, preferences.showHierarchyIcons); EditorPrefs.SetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, preferences.setTextureImporterSettings); + EditorPrefs.SetString(TEXTURE_SETTINGS_REFERENCE_KEY, preferences.textureSettingsReference); EditorPrefs.SetBool(AUTO_RELOAD_SCENESKELETONS_KEY, preferences.autoReloadSceneSkeletons); EditorPrefs.SetBool(MECANIM_EVENT_INCLUDE_FOLDERNAME_KEY, preferences.mecanimEventIncludeFolderName); EditorPrefs.SetBool(ATLASTXT_WARNING_KEY, preferences.atlasTxtImportWarning); @@ -226,6 +232,14 @@ namespace Spine.Unity.Editor { EditorPrefs.SetString(DEFAULT_SHADER_KEY, defaultShader); SpineEditorUtilities.BoolPrefsField(ref setTextureImporterSettings, SET_TEXTUREIMPORTER_SETTINGS_KEY, new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers.")); + SpineEditorUtilities.Texture2DPrefsField(ref textureSettingsReference, TEXTURE_SETTINGS_REFERENCE_KEY, new GUIContent("Atlas Texture Reference Settings", "Apply the selected reference texture import settings at newly imported atlas textures. When exporting atlas textures from Spine with \"Premultiply alpha\" enabled (the default), you can leave it at \"PMAPresetTemplate\". If you have disabled \"Premultiply alpha\", set it to \"StraightAlphaPresetTemplate\". You can also create your own reference texture asset and assign it here.")); + if (string.IsNullOrEmpty(textureSettingsReference)) { + var pmaTextureSettingsReferenceGUIDS = AssetDatabase.FindAssets("PMAPresetTemplate"); + if (pmaTextureSettingsReferenceGUIDS.Length > 0) { + textureSettingsReference = AssetDatabase.GUIDToAssetPath(pmaTextureSettingsReferenceGUIDS[0]); + EditorPrefs.SetString(TEXTURE_SETTINGS_REFERENCE_KEY, textureSettingsReference); + } + } } EditorGUILayout.Space(); @@ -301,7 +315,17 @@ namespace Spine.Unity.Editor { } } - public static void FloatPropertyField(SerializedProperty property, GUIContent label, float min = float.NegativeInfinity, float max = float.PositiveInfinity) { + static void Texture2DPrefsField (ref string currentValue, string editorPrefsKey, GUIContent label) { + EditorGUI.BeginChangeCheck(); + EditorGUIUtility.wideMode = true; + var texture = (EditorGUILayout.ObjectField(label, AssetDatabase.LoadAssetAtPath(currentValue), typeof(Object), false) as Texture2D); + currentValue = texture != null ? AssetDatabase.GetAssetPath(texture) : ""; + if (EditorGUI.EndChangeCheck()) { + EditorPrefs.SetString(editorPrefsKey, currentValue); + } + } + + public static void FloatPropertyField (SerializedProperty property, GUIContent label, float min = float.NegativeInfinity, float max = float.PositiveInfinity) { EditorGUI.BeginChangeCheck(); property.floatValue = EditorGUILayout.DelayedFloatField(label, property.floatValue); if (EditorGUI.EndChangeCheck()) { @@ -309,9 +333,15 @@ namespace Spine.Unity.Editor { } } - public static void ShaderPropertyField(SerializedProperty property, GUIContent label, string fallbackShaderName) { + public static void ShaderPropertyField (SerializedProperty property, GUIContent label, string fallbackShaderName) { var shader = (EditorGUILayout.ObjectField(label, Shader.Find(property.stringValue), typeof(Shader), false) as Shader); property.stringValue = shader != null ? shader.name : fallbackShaderName; } + + + public static void Texture2DPropertyField (SerializedProperty property, GUIContent label) { + var texture = (EditorGUILayout.ObjectField(label, AssetDatabase.LoadAssetAtPath(property.stringValue), typeof(UnityEngine.Object), false) as Texture2D); + property.stringValue = texture != null ? AssetDatabase.GetAssetPath(texture) : ""; + } } } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs index 49b1c9b10..12abab48e 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/SpineEditorUtilities.cs @@ -84,7 +84,10 @@ namespace Spine.Unity.Editor { if (imported.Length == 0) return; - AssetUtility.HandleOnPostprocessAllAssets(imported, texturesWithoutMetaFile); + // we copy the list here to prevent nested calls to OnPostprocessAllAssets() triggering a Clear() of the list + // in the middle of execution. + var texturesWithoutMetaFileCopy = new List(texturesWithoutMetaFile); + AssetUtility.HandleOnPostprocessAllAssets(imported, texturesWithoutMetaFileCopy); texturesWithoutMetaFile.Clear(); } diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs index 5612d25ad..f715c9bac 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Windows/SpinePreferences.cs @@ -75,6 +75,9 @@ namespace Spine.Unity.Editor { internal const bool DEFAULT_SET_TEXTUREIMPORTER_SETTINGS = true; public bool setTextureImporterSettings = DEFAULT_SET_TEXTUREIMPORTER_SETTINGS; + internal const string DEFAULT_TEXTURE_SETTINGS_REFERENCE = ""; + public string textureSettingsReference = DEFAULT_TEXTURE_SETTINGS_REFERENCE; + internal const bool DEFAULT_ATLASTXT_WARNING = true; public bool atlasTxtImportWarning = DEFAULT_ATLASTXT_WARNING; @@ -146,7 +149,15 @@ namespace Spine.Unity.Editor { SpineEditorUtilities.ShaderPropertyField(settings.FindProperty("defaultShader"), new GUIContent("Default Shader"), SpinePreferences.DEFAULT_DEFAULT_SHADER); - EditorGUILayout.PropertyField(settings.FindProperty("setTextureImporterSettings"), new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers.")); + EditorGUILayout.PropertyField(settings.FindProperty("setTextureImporterSettings"), new GUIContent("Apply Atlas Texture Settings", "Apply reference settings for Texture Importers.")); + var textureSettingsRef = settings.FindProperty("textureSettingsReference"); + SpineEditorUtilities.Texture2DPropertyField(textureSettingsRef, new GUIContent("Atlas Texture Reference Settings", "Apply the selected reference texture import settings at newly imported atlas textures. When exporting atlas textures from Spine with \"Premultiply alpha\" enabled (the default), you can leave it at \"PMAPresetTemplate\". If you have disabled \"Premultiply alpha\", set it to \"StraightAlphaPresetTemplate\". You can also create your own reference texture asset and assign it here.")); + if (string.IsNullOrEmpty(textureSettingsRef.stringValue)) { + var pmaTextureSettingsReferenceGUIDS = AssetDatabase.FindAssets("PMAPresetTemplate"); + if (pmaTextureSettingsReferenceGUIDS.Length > 0) { + textureSettingsRef.stringValue = AssetDatabase.GUIDToAssetPath(pmaTextureSettingsReferenceGUIDS[0]); + } + } } EditorGUILayout.Space(); diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs index 12fa4d239..3d34346d5 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Utility/MaterialChecks.cs @@ -131,6 +131,18 @@ namespace Spine.Unity { return isProblematic; } + public static void EnablePMAAtMaterial (Material material, bool enablePMA) { + if (material.HasProperty(STRAIGHT_ALPHA_PARAM_ID)) { + material.SetInt(STRAIGHT_ALPHA_PARAM_ID, enablePMA ? 0 : 1); + } + else { + if (enablePMA) + material.EnableKeyword(ALPHAPREMULTIPLY_ON_KEYWORD); + else + material.DisableKeyword(ALPHAPREMULTIPLY_ON_KEYWORD); + } + } + static bool IsPMAMaterial (Material material) { return (material.HasProperty(STRAIGHT_ALPHA_PARAM_ID) && material.GetInt(STRAIGHT_ALPHA_PARAM_ID) == 0) || material.IsKeywordEnabled(ALPHAPREMULTIPLY_ON_KEYWORD);