• Stars
    star
    492
  • Rank 89,005 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unity – generate SpriteSheets at runtime!

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

More Repositories

1

Citrus-Engine

Modern AS3 Game Engine
ActionScript
548
star
2

PDollar-Unity

PDollar algorithm Unity friendly
C#
138
star
3

Citrus-Engine-Examples

Examples for the Citrus Engine, AS3 Game Engine
ActionScript
120
star
4

UnityDetectHeadset

Detect if a headphone is plugged on iOS & Android.
C#
54
star
5

Video-ANE

ANE for iOS to play videos on top of everything
Objective-C
30
star
6

Instagram-ANE

Instagram sharing ANE for iOS & Android
C
28
star
7

ZXing-ANE

a QR Code, bar code, image recognizer ANE for iOS & Android using ZXing library
Objective-C
25
star
8

PngQuantNativeProcess

Example running pngquant from C#, Unity and Adobe AIR.
ActionScript
15
star
9

ZBar-ANE

a QR Code, bar code, image recognizer ANE for iOS & Android using ZBar library
C++
12
star
10

Hutch

Starling and Pixi merged in a Haxe Framework
Haxe
12
star
11

IconsCreator

Generate app icons for Android & iOS in all requested resolutions.
PHP
11
star
12

FromAirAppToMacAppStore

A quick script for going on the Mac App Store from your Adobe Air Application.
Shell
8
star
13

TextFieldTextRenderer-extended

Feathers's TextFieldTextRenderer with hyperlink support
ActionScript
7
star
14

FromUnityAppToMacAppStore

A quick script for going on the Mac App Store from your Unity Application.
Shell
5
star
15

Citrus-Engine-old

Modern AS3 Game Engine
ActionScript
5
star
16

SaveRingtone-ANE

An ANE to save a sound file as an Android Ringtone.
Java
3
star
17

TexturePacker-multi-size-generator

Bash utility to generate multi size assets from a .tps file.
Shell
3
star
18

Altimeter-ANE

iOS ANE for the CMAltimeter class
C
2
star
19

PhaserMultiResolutions

Using multi-resolutions textures with Phaser framework
Haxe
2
star
20

Citrus-Engine-Examples-old

Examples for the Citrus Engine, AS3 Game Engine
ActionScript
2
star
21

AssetsOperations

Rename and delete files depending name
PHP
1
star
22

esadd-poo-prog-evenementiel

Enseignement de la Programmation Orientée Objet via la programmation évenementielle appliquée aux jeux
JavaScript
1
star
23

GGJ-2020

Game made during the GGJ 2020 at Dijon.
C#
1
star