Skip to content

Commit ab944ff

Browse files
committed
working on multiple sprite sheet generation
1 parent 0111c74 commit ab944ff

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Assets/SpriteSheetRuntimeGenerator/Demos/Scripts/LoadTextures.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void LaunchAnimations() {
3131

3232
IEnumerator LoadAnimation() {
3333

34-
Sprite[] sprites = assetManager.GetSprites ("walking");
34+
Sprite[] sprites = assetManager.GetSprites("walking");
3535

3636
int j = 0;
3737
while (j < sprites.Length) {

Assets/SpriteSheetRuntimeGenerator/Scripts/AssetManager/AssetManager.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ protected IEnumerator process() {
6969
while (mRectangles.Count > 0) {
7070

7171
mPacker = new RectanglePacker(mTexture.width, mTexture.height, padding);
72+
7273
for (int i = 0; i < mRectangles.Count; i++)
7374
mPacker.insertRectangle((int) mRectangles[i].width, (int) mRectangles[i].height, i);
7475

@@ -80,7 +81,9 @@ protected IEnumerator process() {
8081
IntegerRectangle rect = new IntegerRectangle();
8182
List<TextureAsset> textureAssets = new List<TextureAsset>();
8283

83-
List<Rect> rectGarbages = new List<Rect>();
84+
List<Rect> garbageRect = new List<Rect>();
85+
List<Texture2D> garabeTextures = new List<Texture2D>();
86+
List<string> garbageImages = new List<string>();
8487

8588
for (int j = 0; j < mPacker.rectangleCount; j++) {
8689

@@ -99,17 +102,19 @@ protected IEnumerator process() {
99102

100103
textureAssets.Add(texture);
101104

102-
rectGarbages.Add(mRectangles[index]);
105+
garbageRect.Add(mRectangles[index]);
106+
garabeTextures.Add(textures[index]);
107+
garbageImages.Add(images[index]);
103108
}
104109

105-
foreach (Rect rectGarbage in rectGarbages) {
110+
foreach (Rect garbage in garbageRect)
111+
mRectangles.Remove(garbage);
106112

107-
int indexToDestroy = mRectangles.IndexOf(rectGarbage);
113+
foreach (Texture2D garbage in garabeTextures)
114+
textures.Remove(garbage);
108115

109-
mRectangles.RemoveAt(indexToDestroy);
110-
textures.RemoveAt(indexToDestroy);
111-
images.RemoveAt(indexToDestroy);
112-
}
116+
foreach (string garbage in garbageImages)
117+
images.Remove(garbage);
113118

114119
mTexture.Apply();
115120

@@ -129,7 +134,6 @@ protected IEnumerator process() {
129134

130135
foreach (TextureAsset textureAsset in textureAssets)
131136
mSprites.Add(textureAsset.name, Sprite.Create(mTexture, new Rect(textureAsset.x, textureAsset.y, textureAsset.width, textureAsset.height), Vector2.zero));
132-
133137
}
134138

135139
}

0 commit comments

Comments
 (0)