Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unity – generate SpriteSheets at runtime!

License

NotificationsYou must be signed in to change notification settings

DaVikingCode/UnityRuntimeSpriteSheetsGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 

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.

Example:

Add theAssetPacker component to your GameObject:
AssetPacker

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;}}}

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp