From d2eebdf81fc2cc502d8e7938d55b72eb861bcef1 Mon Sep 17 00:00:00 2001 From: John Date: Thu, 15 Dec 2016 05:52:51 +0800 Subject: [PATCH] [unity] Fix case where only materials changed. --- spine-unity/Assets/spine-unity/SkeletonRenderer.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs index 1e13650e9..123a33b85 100644 --- a/spine-unity/Assets/spine-unity/SkeletonRenderer.cs +++ b/spine-unity/Assets/spine-unity/SkeletonRenderer.cs @@ -534,11 +534,20 @@ namespace Spine.Unity { bool mustUpdateRendererMaterials = mustUpdateMeshStructure || (lastPushedMaterials.Length != submeshCount); + // Assumption at this point: (lastPushedMaterials.Count == workingSubmeshInstructions.Count == thisSubmeshMaterials.Count == submeshCount) + + // Case: mesh structure or submesh count did not change but materials changed. if (!mustUpdateRendererMaterials) { var workingSubmeshInstructionsItems = workingSubmeshInstructions.Items; - for (int i = 0, n = lastPushedMaterials.Length; i < n; i++) { - if (lastPushedMaterials[i].GetInstanceID() != workingSubmeshInstructionsItems[i].material.GetInstanceID()) { // Bounds check is implied above. + for (int i = 0; i < submeshCount; i++) { + if (lastPushedMaterials[i].GetInstanceID() != workingSubmeshInstructionsItems[i].material.GetInstanceID()) { // Bounds check is implied by submeshCount above. mustUpdateRendererMaterials = true; + { + var thisSubmeshMaterials = this.submeshMaterials.Items; + if (mustUpdateRendererMaterials) + for (int j = 0; j < submeshCount; j++) + thisSubmeshMaterials[j] = workingSubmeshInstructionsItems[j].material; + } break; } }