Skip to content

Commit a95221a

Browse files
authored
Update README.MD
1 parent 176217c commit a95221a

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

README.MD

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,58 @@ Unity Runtime SpriteSheets Generator
33

44
Unity and plugins provide many great ways to build Sprite Sheets. However they're used directly into Unity Editor or with an external software which is perfect in many case, but none provide the ability to generate SpriteSheets at runtime.
55

6-
The RectanglePacking algorithm is a port of the AS3 version made by [Ville Koskela](https://github.com/villekoskelaorg/RectanglePacking). Assets used in the demo come from [Kenney](http://kenney.nl/).
6+
The RectanglePacking algorithm is a port of the AS3 version made by [Ville Koskela](https://github.com/villekoskelaorg/RectanglePacking). Assets used in the demo come from [Kenney](http://kenney.nl/).
7+
8+
Example:
9+
--------
10+
Add the `AssetPacker` component to your GameObject:
11+
![AssetPacker](http://davikingcode.com/blog/wp-content/uploads/2017/01/AssetPacker.png)
12+
```csharp
13+
using DaVikingCode.AssetPacker;
14+
using System.Collections;
15+
using System.Collections.Generic;
16+
using System.IO;
17+
using UnityEngine;
18+
using UnityEngine.UI;
19+
20+
public class AssetPackerExample : MonoBehaviour {
21+
22+
public Image anim;
23+
24+
AssetPacker assetPacker;
25+
26+
void Start () {
27+
28+
string[] files = Directory.GetFiles(Application.persistentDataPath + "/Textures", "*.png");
29+
30+
assetPacker = GetComponent<AssetPacker>();
31+
32+
assetPacker.OnProcessCompleted.AddListener(LaunchAnimations);
33+
34+
assetPacker.AddTexturesToPack(files);
35+
assetPacker.Process();
36+
}
37+
38+
void LaunchAnimations() {
39+
40+
StartCoroutine(LoadAnimation());
41+
}
42+
43+
IEnumerator LoadAnimation() {
44+
45+
Sprite[] sprites = assetPacker.GetSprites("walking");
46+
47+
int j = 0;
48+
while (j < sprites.Length) {
49+
50+
anim.sprite = sprites[j++];
51+
52+
yield return new WaitForSeconds(0.1f);
53+
54+
if (j == sprites.Length)
55+
j = 0;
56+
}
57+
}
58+
}
59+
60+
```

0 commit comments

Comments
 (0)