mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Dispose temp textures after repacking.
This commit is contained in:
parent
b8a603d6af
commit
48173c6d85
@ -305,9 +305,11 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
var skinAttachments = o.Attachments;
|
var skinAttachments = o.Attachments;
|
||||||
var newSkin = new Skin(newName);
|
var newSkin = new Skin(newName);
|
||||||
|
|
||||||
|
// Use these to detect and use shared regions.
|
||||||
var existingRegions = new Dictionary<AtlasRegion, int>();
|
var existingRegions = new Dictionary<AtlasRegion, int>();
|
||||||
var regionIndexes = new List<int>();
|
var regionIndexes = new List<int>();
|
||||||
|
|
||||||
|
// Collect all textures from the attachments of the original skin.
|
||||||
var repackedAttachments = new List<Attachment>();
|
var repackedAttachments = new List<Attachment>();
|
||||||
var texturesToPack = new List<Texture2D>();
|
var texturesToPack = new List<Texture2D>();
|
||||||
var originalRegions = new List<AtlasRegion>();
|
var originalRegions = new List<AtlasRegion>();
|
||||||
@ -334,11 +336,13 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
newSkin.AddAttachment(key.slotIndex, key.name, newAttachment);
|
newSkin.AddAttachment(key.slotIndex, key.name, newAttachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fill a new texture with the collected attachment textures.
|
||||||
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize, textureFormat, mipmaps);
|
var newTexture = new Texture2D(maxAtlasSize, maxAtlasSize, textureFormat, mipmaps);
|
||||||
newTexture.anisoLevel = texturesToPack[0].anisoLevel;
|
newTexture.anisoLevel = texturesToPack[0].anisoLevel;
|
||||||
newTexture.name = newName;
|
newTexture.name = newName;
|
||||||
var rects = newTexture.PackTextures(texturesToPack.ToArray(), padding, maxAtlasSize);
|
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);
|
var newMaterial = new Material(shader);
|
||||||
newMaterial.name = newName;
|
newMaterial.name = newName;
|
||||||
newMaterial.mainTexture = newTexture;
|
newMaterial.mainTexture = newTexture;
|
||||||
@ -352,11 +356,16 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
repackedRegions.Add(newRegion);
|
repackedRegions.Add(newRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Map the cloned attachments to the repacked atlas.
|
||||||
for (int i = 0, n = repackedAttachments.Count; i < n; i++) {
|
for (int i = 0, n = repackedAttachments.Count; i < n; i++) {
|
||||||
var a = repackedAttachments[i];
|
var a = repackedAttachments[i];
|
||||||
a.SetRegion(repackedRegions[regionIndexes[i]]);
|
a.SetRegion(repackedRegions[regionIndexes[i]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
foreach (var ttp in texturesToPack)
|
||||||
|
UnityEngine.Object.Destroy(ttp);
|
||||||
|
|
||||||
t = newTexture;
|
t = newTexture;
|
||||||
m = newMaterial;
|
m = newMaterial;
|
||||||
return newSkin;
|
return newSkin;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user