- Notifications
You must be signed in to change notification settings - Fork147
Unity – generate SpriteSheets at runtime!
License
DaVikingCode/UnityRuntimeSpriteSheetsGenerator
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
The RectanglePacking algorithm is a port of the AS3 version made byVille Koskela. Assets used in the demo come fromKenney.
You could combine the generated Sprite Sheets.png with apngquant compression via this scriptPngQuantNativeProcess.
Please note that Unity provides aTexture2D.PackTextures method, I didn't test it nor made benchmark performances.
Add theAssetPacker component to your GameObject:
usingDaVikingCode.AssetPacker;usingSystem.Collections;usingSystem.Collections.Generic;usingSystem.IO;usingUnityEngine;usingUnityEngine.UI;publicclassAssetPackerExample:MonoBehaviour{publicImageanim;AssetPackerassetPacker;voidStart(){string[]files=Directory.GetFiles(Application.persistentDataPath+"/Textures","*.png");assetPacker=GetComponent<AssetPacker>();assetPacker.OnProcessCompleted.AddListener(LaunchAnimations);assetPacker.AddTexturesToPack(files);assetPacker.Process();}voidLaunchAnimations(){StartCoroutine(LoadAnimation());}IEnumeratorLoadAnimation(){Sprite[]sprites=assetPacker.GetSprites("walking");inti=0;while(i<sprites.Length){anim.sprite=sprites[i++];yieldreturnnewWaitForSeconds(0.1f);// loopif(i==sprites.Length)i=0;}}}
About
Unity – generate SpriteSheets at runtime!
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
