From 6cd3e54b8315b4e762ea8950eb4d94ba0c785cef Mon Sep 17 00:00:00 2001 From: Harald Csaszar Date: Tue, 31 Aug 2021 17:52:20 +0200 Subject: [PATCH] [unity] Fixed SkeletonGraphic with `Multiple Canvas Renderers` ignoring Mask when CustomMaterialOverride or blend modes are active. Closes #1948. --- .../Editor/Components/SkeletonGraphicInspector.cs | 4 ++-- .../Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs index d8e2e1891..e98a65d2c 100644 --- a/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs +++ b/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Components/SkeletonGraphicInspector.cs @@ -244,8 +244,8 @@ namespace Spine.Unity.Editor { } else if (meshRendersIncorrectlyWithSingleRenderer) { using (new SpineInspectorUtility.BoxScope()) { meshGeneratorSettings.isExpanded = true; - EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("This mesh uses multiple atlas pages. You\n" + - "need to enable 'Multiple Canvas Renderers'\n" + + EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("This mesh uses multiple atlas pages or blend modes.\n" + + "You need to enable 'Multiple Canvas Renderers'\n" + "for correct rendering. Consider packing\n" + "attachments to a single atlas page if possible.", Icons.warning), GUILayout.Height(60), GUILayout.Width(340)); } diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs index a6d52b44e..b0130ccf5 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/Components/SkeletonGraphic.cs @@ -678,7 +678,7 @@ namespace Spine.Unity { meshGenerator.Begin(); meshGenerator.AddSubmesh(submeshInstructionItem); - var targetMesh = meshesItems[i]; + Mesh targetMesh = meshesItems[i]; meshGenerator.ScaleVertexData(scale); if (OnPostProcessVertices != null) OnPostProcessVertices.Invoke(this.meshGenerator.Buffers); meshGenerator.FillVertexData(targetMesh); @@ -703,6 +703,7 @@ namespace Spine.Unity { parent = separatorParts[++separatorSlotGroupIndex]; } + SkeletonSubmeshGraphic submeshGraphic = submeshGraphics[i]; if (useOriginalTextureAndMaterial) { Texture usedTexture = submeshMaterial.mainTexture; if (!hasBlendModeMaterials) @@ -724,6 +725,7 @@ namespace Spine.Unity { else if (blendMode == BlendMode.Screen && screenMaterial) usedMaterial = screenMaterial; + usedMaterial = submeshGraphic.GetModifiedMaterial(usedMaterial); canvasRenderer.SetMaterial(usedMaterial, usedTexture); #if HAS_CULL_TRANSPARENT_MESH canvasRenderer.cullTransparentMesh = allowCullTransparentMesh ? @@ -738,6 +740,8 @@ namespace Spine.Unity { usedMaterial = material; if (!customTextureOverride.TryGetValue(originalTexture, out usedTexture)) usedTexture = originalTexture; + + usedMaterial = submeshGraphic.GetModifiedMaterial(usedMaterial); canvasRenderer.SetMaterial(usedMaterial, usedTexture); } }