Skip to content

Instantly share code, notes, and snippets.

Created Feb 8, 2015
What would you like to do?
The Unity component of creating a sprite sheet
using UnityEngine;
using System.Collections;
using UnityEditor;
using System;
public class CustPipeline {
//This function relies on get custom argument and is called from 3ds max. It gets the frames, height and diemensions and properly chops up the sprite sheet
public static void MakeIntoSS(){
string _thePath = CLRead.GetCustomArgument ("ThePath");
int _width = Convert.ToInt32(CLRead.GetCustomArgument("Width"));
int _height = Convert.ToInt32(CLRead.GetCustomArgument("Height"));
int _numOfFrames = Convert.ToInt32 (CLRead.GetCustomArgument("Frames"));
int _perColumn = Convert.ToInt32(CLRead.GetCustomArgument("Columns"));
Debug.Log ("Making sprite sheet");
TextureImporter _tImporter = AssetImporter.GetAtPath (_thePath) as TextureImporter;
_tImporter.textureType = TextureImporterType.Sprite;
_tImporter.spriteImportMode = SpriteImportMode.Multiple;
SpriteMetaData[] _theSprites = new SpriteMetaData [_numOfFrames + 1];
for (int i = 0; i < _numOfFrames + 1;i++) { //the + 1 is because max uses a base 1 system.
SpriteMetaData _sprite = new SpriteMetaData();
int _y =_perColumn - 1 - i/_perColumn;
int _yReversed = i/_perColumn;
int _x = i -_yReversed*_perColumn;
_sprite.rect = new Rect(_x*_width,_y*_height,_width,_height);
_theSprites[i] = _sprite;
_tImporter.spritesheet = _theSprites;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment