[unity] Added warnings for PMA vs straight alpha mismatch between import settings and atlas.txt content. See #2928.

This commit is contained in:
Harald Csaszar 2025-09-17 21:31:21 +02:00
parent d300b399a6
commit 611031beab
2 changed files with 28 additions and 0 deletions

View File

@ -738,6 +738,8 @@ namespace Spine.Unity.Editor {
atlasAsset.Clear(); atlasAsset.Clear();
atlas = atlasAsset.GetAtlas(onlyMetaData: false); atlas = atlasAsset.GetAtlas(onlyMetaData: false);
if (atlas != null) { if (atlas != null) {
IssuePMAWarnings(atlas, atlasAsset);
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic); FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic);
List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas); List<AtlasRegion> regions = (List<AtlasRegion>)field.GetValue(atlas);
string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset); string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
@ -768,6 +770,32 @@ namespace Spine.Unity.Editor {
return loadedAtlas != null ? loadedAtlas : atlasAsset; return loadedAtlas != null ? loadedAtlas : atlasAsset;
} }
static void IssuePMAWarnings (Atlas atlas, SpineAtlasAsset atlasAsset) {
bool isPMA = atlas.Pages.Count > 0 && atlas.Pages[0].pma;
if (QualitySettings.activeColorSpace == ColorSpace.Linear && isPMA)
Debug.LogWarning(string.Format("{0} :: Atlas was exported as PMA but your color space is set to Linear. " +
"Please\n"
+ "a) re-export atlas as straight alpha texture with 'premultiply alpha' unchecked.\n"
+ "b) switch to Gamma color space via\nProject Settings - Player - Other Settings - Color Space.\n",
atlasAsset.name), atlasAsset);
else if (SpineEditorUtilities.Preferences.UsesPMAWorkflow != isPMA) {
if (isPMA)
Debug.LogWarning(string.Format("{0} :: Atlas was exported as PMA but Spine Preferences are set " +
"to use straight-alpha import presets. Please\n"
+ "a) re-export atlas as straight-alpha texture with 'premultiply alpha' disabled, or\n"
+ "b) Select 'Edit - Preferences - Spine - Switch Texture Workflow' - 'PMA'. " +
"Select `Reimport` on the skeleton directory afterwards.\n",
atlasAsset.name), atlasAsset);
else
Debug.LogWarning(string.Format("{0} :: Atlas was exported as straight-alpha but Spine Preferences are set " +
"to use PMA import presets. Please\n"
+ "a) re-export atlas as PMA texture with 'premultiply alpha' enabled, or\n"
+ "b) Select 'Edit - Preferences - Spine - Switch Texture Workflow' - 'Straight Alpha'. " +
"Select `Reimport` on the skeleton directory afterwards.\n",
atlasAsset.name), atlasAsset);
}
}
static bool HasCustomMaterialsAssigned (List<Material> vestigialMaterials, string primaryName, List<string> pageFiles) { static bool HasCustomMaterialsAssigned (List<Material> vestigialMaterials, string primaryName, List<string> pageFiles) {
if (pageFiles.Count == 0 || vestigialMaterials.Count == 0) if (pageFiles.Count == 0 || vestigialMaterials.Count == 0)
return false; return false;