From e39dbc4795d783827bd782aee138773c13b22ddc Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 28 Jan 2019 16:28:28 +0100 Subject: [PATCH 1/3] [unity] Fixed SkeletonGraphic's 'Starting Animation' property being cleared upon saving under some circumstances, closes #1252. --- .../spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs index 620d2d940..bb666e21f 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Modules/SkeletonGraphic/SkeletonGraphic.cs @@ -72,7 +72,6 @@ namespace Spine.Unity { } else if (skeletonDataAsset.GetSkeletonData(true) != skeleton.data) { Clear(); Initialize(true); - startingAnimation = ""; if (skeletonDataAsset.atlasAssets.Length > 1 || skeletonDataAsset.atlasAssets[0].MaterialCount > 1) Debug.LogError("Unity UI does not support multiple textures per Renderer. Your skeleton will not be rendered correctly. Recommend using SkeletonAnimation instead. This requires the use of a Screen space camera canvas."); } else { @@ -275,6 +274,9 @@ namespace Spine.Unity { } #endif } + else { + startingAnimation = string.Empty; + } } } From dc676cb25a6619b8dd7d81f193e2850f2f97582c Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 28 Jan 2019 19:54:06 +0100 Subject: [PATCH 2/3] [unity] Changed default texture settings and added warning to prevent border artifacts when mip maps are enabled on PMA textures. Closes #1266. --- .../Editor/SpineEditorUtilities.cs | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index 89b2aaa77..5c66ba6d7 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -228,6 +228,10 @@ namespace Spine.Unity.Editor { DataReloadHandler.OnPlaymodeStateChanged(); #endif + if (SpineEditorUtilities.Preferences.textureImporterWarning) { + IssueWarningsForUnrecommendedTextureSettings(); + } + initialized = true; } @@ -235,7 +239,40 @@ namespace Spine.Unity.Editor { if (!initialized || Icons.skeleton == null) Initialize(); } -#endregion + + public static void IssueWarningsForUnrecommendedTextureSettings() { + + string[] atlasDescriptionGUIDs = AssetDatabase.FindAssets("t:textasset .atlas"); // Note: finds .atlas.txt files + for (int i = 0; i < atlasDescriptionGUIDs.Length; ++i) { + string atlasDescriptionPath = AssetDatabase.GUIDToAssetPath(atlasDescriptionGUIDs[i]); + string texturePath = atlasDescriptionPath.Replace(".atlas.txt", ".png"); + + bool textureExists = IssueWarningsForUnrecommendedTextureSettings(texturePath); + if (!textureExists) { + texturePath = texturePath.Replace(".png", ".jpg"); + textureExists = IssueWarningsForUnrecommendedTextureSettings(texturePath); + } + if (!textureExists) { + continue; + } + } + } + + public static bool IssueWarningsForUnrecommendedTextureSettings(string texturePath) + { + TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath); + if (texImporter == null) { + return false; + } + + // 'sRGBTexture = true' generates incorrectly weighted mipmaps at PMA textures, + // causing white borders due to undesired custom weighting. + if (texImporter.sRGBTexture && texImporter.mipmapEnabled) { + Debug.LogWarningFormat("`{0}` : Incorrect Texture Settings found: When enabling `Generate Mip Maps`, it is strongly recommended to disable `sRGB (Color Texture)`. Otherwise you will receive white border artifacts on an atlas exported with default `Premultiply alpha` settings.\n(You can disable this warning in `Edit - Preferences - Spine`)", texturePath); + } + return true; + } + #endregion public static class Preferences { #if SPINE_TK2D @@ -272,7 +309,11 @@ namespace Spine.Unity.Editor { const bool DEFAULT_ATLASTXT_WARNING = true; const string ATLASTXT_WARNING_KEY = "SPINE_ATLASTXT_WARNING"; - public static bool atlasTxtImportWarning = DEFAULT_SET_TEXTUREIMPORTER_SETTINGS; + public static bool atlasTxtImportWarning = DEFAULT_ATLASTXT_WARNING; + + const bool DEFAULT_TEXTUREIMPORTER_WARNING = true; + const string TEXTUREIMPORTER_WARNING_KEY = "SPINE_TEXTUREIMPORTER_WARNING"; + public static bool textureImporterWarning = DEFAULT_TEXTUREIMPORTER_WARNING; internal const float DEFAULT_MIPMAPBIAS = -0.5f; @@ -297,6 +338,7 @@ namespace Spine.Unity.Editor { setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, DEFAULT_SET_TEXTUREIMPORTER_SETTINGS); autoReloadSceneSkeletons = EditorPrefs.GetBool(AUTO_RELOAD_SCENESKELETONS_KEY, DEFAULT_AUTO_RELOAD_SCENESKELETONS); atlasTxtImportWarning = EditorPrefs.GetBool(ATLASTXT_WARNING_KEY, DEFAULT_ATLASTXT_WARNING); + textureImporterWarning = EditorPrefs.GetBool(TEXTUREIMPORTER_WARNING_KEY, DEFAULT_TEXTUREIMPORTER_WARNING); SpineHandles.handleScale = EditorPrefs.GetFloat(SCENE_ICONS_SCALE_KEY, DEFAULT_SCENE_ICONS_SCALE); preferencesLoaded = true; @@ -332,7 +374,13 @@ 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.")); + } + + EditorGUILayout.Space(); + EditorGUILayout.LabelField("Warnings", EditorStyles.boldLabel); + { SpineEditorUtilities.BoolPrefsField(ref atlasTxtImportWarning, ATLASTXT_WARNING_KEY, new GUIContent("Atlas Extension Warning", "Log a warning and recommendation whenever a `.atlas` file is found.")); + SpineEditorUtilities.BoolPrefsField(ref textureImporterWarning, TEXTUREIMPORTER_WARNING_KEY, new GUIContent("Texture Settings Warning", "Log a warning and recommendation whenever Texture Import Settings are detected that could lead to undesired effects, e.g. white border artifacts.")); } EditorGUILayout.Space(); @@ -841,6 +889,10 @@ namespace Spine.Unity.Editor { continue; } + // Note: 'sRGBTexture = false' below might seem counter-intuitive, but prevents mipmaps from being + // generated incorrectly (causing white borders due to undesired custom weighting) for PMA textures + // when mipmaps are enabled later. + texImporter.sRGBTexture = false; texImporter.textureCompression = TextureImporterCompression.Uncompressed; texImporter.alphaSource = TextureImporterAlphaSource.FromInput; texImporter.mipmapEnabled = false; @@ -1740,6 +1792,24 @@ namespace Spine.Unity.Editor { } } + public class TextureModificationWarningProcessor : UnityEditor.AssetModificationProcessor + { + static string[] OnWillSaveAssets(string[] paths) + { + if (SpineEditorUtilities.Preferences.textureImporterWarning) { + foreach (string path in paths) { + if (path.EndsWith(".png.meta", System.StringComparison.Ordinal) || + path.EndsWith(".jpg.meta", System.StringComparison.Ordinal)) { + + string texturePath = System.IO.Path.ChangeExtension(path, null); + SpineEditorUtilities.IssueWarningsForUnrecommendedTextureSettings(texturePath); + } + } + } + return paths; + } + } + public static class SpineHandles { internal static float handleScale = 1f; public static Color BoneColor { get { return new Color(0.8f, 0.8f, 0.8f, 0.4f); } } From c612c8143550b2c310e52d455deb271cba7380e1 Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Mon, 28 Jan 2019 20:08:48 +0100 Subject: [PATCH 3/3] [unity] Fixed previous commit's texture settings warning code preventing border artifacts when mip maps are enabled on PMA textures. Now only issues warning on Spine atlas textures. See #1266. --- .../Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs index 5c66ba6d7..d99f2b63a 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/SpineEditorUtilities.cs @@ -1801,8 +1801,10 @@ namespace Spine.Unity.Editor { if (path.EndsWith(".png.meta", System.StringComparison.Ordinal) || path.EndsWith(".jpg.meta", System.StringComparison.Ordinal)) { - string texturePath = System.IO.Path.ChangeExtension(path, null); - SpineEditorUtilities.IssueWarningsForUnrecommendedTextureSettings(texturePath); + string texturePath = System.IO.Path.ChangeExtension(path, null); // .meta removed + string atlasPath = System.IO.Path.ChangeExtension(texturePath, "atlas.txt"); + if (System.IO.File.Exists(atlasPath)) + SpineEditorUtilities.IssueWarningsForUnrecommendedTextureSettings(texturePath); } } }