mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] Repacked AtlasRegions are now shared.
This commit is contained in:
parent
92bdd8921b
commit
922bd8ac5d
@ -306,10 +306,11 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
var newSkin = new Skin(newName);
|
var newSkin = new Skin(newName);
|
||||||
|
|
||||||
var existingRegions = new Dictionary<AtlasRegion, int>();
|
var existingRegions = new Dictionary<AtlasRegion, int>();
|
||||||
var textureIndexes = new List<int>();
|
var regionIndexes = new List<int>();
|
||||||
|
|
||||||
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>();
|
||||||
int newRegionIndex = 0;
|
int newRegionIndex = 0;
|
||||||
foreach (var kvp in skinAttachments) {
|
foreach (var kvp in skinAttachments) {
|
||||||
var newAttachment = kvp.Value.GetClone(true);
|
var newAttachment = kvp.Value.GetClone(true);
|
||||||
@ -318,11 +319,12 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
var region = newAttachment.GetAtlasRegion();
|
var region = newAttachment.GetAtlasRegion();
|
||||||
int existingIndex;
|
int existingIndex;
|
||||||
if (existingRegions.TryGetValue(region, out existingIndex)) {
|
if (existingRegions.TryGetValue(region, out existingIndex)) {
|
||||||
textureIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
|
regionIndexes.Add(existingIndex); // Store the region index for the eventual new attachment.
|
||||||
} else {
|
} else {
|
||||||
|
originalRegions.Add(region);
|
||||||
texturesToPack.Add(region.ToTexture()); // Add the texture to the PackTextures argument
|
texturesToPack.Add(region.ToTexture()); // Add the texture to the PackTextures argument
|
||||||
existingRegions.Add(region, newRegionIndex); // Add the region to the dictionary of known regions
|
existingRegions.Add(region, newRegionIndex); // Add the region to the dictionary of known regions
|
||||||
textureIndexes.Add(newRegionIndex); // Store the region index for the eventual new attachment.
|
regionIndexes.Add(newRegionIndex); // Store the region index for the eventual new attachment.
|
||||||
newRegionIndex++;
|
newRegionIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,12 +345,16 @@ namespace Spine.Unity.Modules.AttachmentTools {
|
|||||||
var page = newMaterial.ToSpineAtlasPage();
|
var page = newMaterial.ToSpineAtlasPage();
|
||||||
page.name = newName;
|
page.name = newName;
|
||||||
|
|
||||||
|
var repackedRegions = new List<AtlasRegion>();
|
||||||
|
for (int i = 0, n = originalRegions.Count; i < n; i++) {
|
||||||
|
var oldRegion = originalRegions[i];
|
||||||
|
var newRegion = UVRectToAtlasRegion(rects[i], oldRegion.name, page, oldRegion.offsetX, oldRegion.offsetY, oldRegion.rotate);
|
||||||
|
repackedRegions.Add(newRegion);
|
||||||
|
}
|
||||||
|
|
||||||
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];
|
||||||
var r = rects[textureIndexes[i]];
|
a.SetRegion(repackedRegions[regionIndexes[i]]);
|
||||||
var oldRegion = a.GetAtlasRegion();
|
|
||||||
var newRegion = UVRectToAtlasRegion(r, oldRegion.name, page, oldRegion.offsetX, oldRegion.offsetY, oldRegion.rotate);
|
|
||||||
a.SetRegion(newRegion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t = newTexture;
|
t = newTexture;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user