From 48173c6d852db98c36a23f2d0810a00fef4822d7 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 31 Mar 2017 02:01:14 +0800 Subject: [PATCH] [unity] Dispose temp textures after repacking. --- .../Modules/AttachmentTools/AttachmentTools.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs index e231c244a..02c9607c3 100644 --- a/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs +++ b/spine-unity/Assets/spine-unity/Modules/AttachmentTools/AttachmentTools.cs @@ -305,9 +305,11 @@ namespace Spine.Unity.Modules.AttachmentTools { var skinAttachments = o.Attachments; var newSkin = new Skin(newName); + // Use these to detect and use shared regions. var existingRegions = new Dictionary(); var regionIndexes = new List(); + // Collect all textures from the attachments of the original skin. var repackedAttachments = new List(); var texturesToPack = new List(); var originalRegions = new List(); @@ -334,11 +336,13 @@ namespace Spine.Unity.Modules.AttachmentTools { newSkin.AddAttachment(key.slotIndex, key.name, newAttachment); } + // Fill a new texture with the collected attachment textures. var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize, textureFormat, mipmaps); newTexture.anisoLevel = texturesToPack[0].anisoLevel; newTexture.name = newName; var rects = newTexture.PackTextures(texturesToPack.ToArray(), padding, maxAtlasSize); + // Rehydrate the repacked textures as a Material, Spine atlas and Spine.AtlasAttachments var newMaterial = new Material(shader); newMaterial.name = newName; newMaterial.mainTexture = newTexture; @@ -352,11 +356,16 @@ namespace Spine.Unity.Modules.AttachmentTools { repackedRegions.Add(newRegion); } + // Map the cloned attachments to the repacked atlas. for (int i = 0, n = repackedAttachments.Count; i < n; i++) { var a = repackedAttachments[i]; a.SetRegion(repackedRegions[regionIndexes[i]]); } + // Clean up + foreach (var ttp in texturesToPack) + UnityEngine.Object.Destroy(ttp); + t = newTexture; m = newMaterial; return newSkin;