mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[unity] Clean up editor Sprite generation.
This commit is contained in:
parent
46c2c6428a
commit
f36a573072
@ -288,21 +288,11 @@ namespace Spine.Unity.Editor {
|
|||||||
var sprites = new List<SpriteMetaData>(spriteSheet);
|
var sprites = new List<SpriteMetaData>(spriteSheet);
|
||||||
|
|
||||||
var regions = AtlasAssetInspector.GetRegions(atlas);
|
var regions = AtlasAssetInspector.GetRegions(atlas);
|
||||||
int textureHeight = texture.height;
|
|
||||||
char[] FilenameDelimiter = {'.'};
|
char[] FilenameDelimiter = {'.'};
|
||||||
int updatedCount = 0;
|
int updatedCount = 0;
|
||||||
int addedCount = 0;
|
int addedCount = 0;
|
||||||
|
|
||||||
foreach (var r in regions) {
|
foreach (var r in regions) {
|
||||||
int width, height;
|
|
||||||
if (r.rotate) {
|
|
||||||
width = r.height;
|
|
||||||
height = r.width;
|
|
||||||
} else {
|
|
||||||
width = r.width;
|
|
||||||
height = r.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
string pageName = r.page.name.Split(FilenameDelimiter, StringSplitOptions.RemoveEmptyEntries)[0];
|
string pageName = r.page.name.Split(FilenameDelimiter, StringSplitOptions.RemoveEmptyEntries)[0];
|
||||||
string textureName = texture.name;
|
string textureName = texture.name;
|
||||||
bool pageMatch = string.Equals(pageName, textureName, StringComparison.Ordinal);
|
bool pageMatch = string.Equals(pageName, textureName, StringComparison.Ordinal);
|
||||||
@ -320,23 +310,34 @@ namespace Spine.Unity.Editor {
|
|||||||
) : -1;
|
) : -1;
|
||||||
bool spriteNameMatchExists = spriteIndex >= 0;
|
bool spriteNameMatchExists = spriteIndex >= 0;
|
||||||
|
|
||||||
int x = r.x;
|
if (pageMatch) {
|
||||||
int y = r.page.height - height - r.y;
|
Rect spriteRect = new Rect();
|
||||||
if (spriteNameMatchExists) {
|
|
||||||
var s = sprites[spriteIndex];
|
if (r.rotate) {
|
||||||
s.rect = new Rect(x, y, width, height);
|
spriteRect.width = r.height;
|
||||||
sprites[spriteIndex] = s;
|
spriteRect.height = r.width;
|
||||||
updatedCount++;
|
} else {
|
||||||
} else {
|
spriteRect.width = r.width;
|
||||||
if (pageMatch) {
|
spriteRect.height = r.height;
|
||||||
|
}
|
||||||
|
spriteRect.x = r.x;
|
||||||
|
spriteRect.y = r.page.height - spriteRect.height - r.y;
|
||||||
|
|
||||||
|
if (spriteNameMatchExists) {
|
||||||
|
var s = sprites[spriteIndex];
|
||||||
|
s.rect = spriteRect;
|
||||||
|
sprites[spriteIndex] = s;
|
||||||
|
updatedCount++;
|
||||||
|
} else {
|
||||||
sprites.Add(new SpriteMetaData {
|
sprites.Add(new SpriteMetaData {
|
||||||
name = r.name,
|
name = r.name,
|
||||||
pivot = new Vector2(0.5f, 0.5f),
|
pivot = new Vector2(0.5f, 0.5f),
|
||||||
rect = new Rect(x, y, width, height)
|
rect = spriteRect
|
||||||
});
|
});
|
||||||
addedCount++;
|
addedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.spritesheet = sprites.ToArray();
|
t.spritesheet = sprites.ToArray();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user