GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - DaVikingCode/UnityRuntimeSpriteSheetsGenerator: Unity – generate SpriteSheets at runtime!

BranchesTags
Open more actions menu

Latest commit

 

History

47 Commits
47 Commits

Folders and files

NameName
Last commit message
Last commit date
Assets
Assets
 
 
ProjectSettings
ProjectSettings
 
 
.gitignore
.gitignore
 
 
LICENSE.txt
LICENSE.txt
 
 
README.MD
README.MD
 
 

Repository files navigation

Unity Runtime SpriteSheets Generator

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 by Ville Koskela. Assets used in the demo come from Kenney.

You could combine the generated Sprite Sheets.png with a pngquant compression via this script PngQuantNativeProcess.

Please note that Unity provides a Texture2D.PackTextures method, I didn't test it nor made benchmark performances.

Example:

Add the AssetPacker component to your GameObject:
AssetPacker

using DaVikingCode.AssetPacker;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;

public class AssetPackerExample : MonoBehaviour {
	
	public Image anim;

	AssetPacker assetPacker;
	
	void Start () {

		string[] files = Directory.GetFiles(Application.persistentDataPath + "/Textures", "*.png");

		assetPacker = GetComponent<AssetPacker>();

		assetPacker.OnProcessCompleted.AddListener(LaunchAnimations);

		assetPacker.AddTexturesToPack(files);
		assetPacker.Process();
	}

	void LaunchAnimations() {

		StartCoroutine(LoadAnimation());
	}

	IEnumerator LoadAnimation() {

		Sprite[] sprites = assetPacker.GetSprites("walking");

		int i = 0;
		while (i < sprites.Length) {

			anim.sprite = sprites[i++];

			yield return new WaitForSeconds(0.1f);

			// loop
			if (i == sprites.Length)
				i = 0;
		}
	}
}

About

Unity – generate SpriteSheets at runtime!

davikingcode.com/blog/unity-generate-spritesheets-at-runtime/

Topics

runtimespritesheetsunity

Resources

Readme
MIT license
Activity
Custom properties

Stars

605 stars

Watchers

26 watching

Forks

146 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.