Skip to content

Instantly share code, notes, and snippets.

@jesterswilde
Created February 8, 2015 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesterswilde/e7842dce52a2692ce4f1 to your computer and use it in GitHub Desktop.
Save jesterswilde/e7842dce52a2692ce4f1 to your computer and use it in GitHub Desktop.
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;
AssetDatabase.ImportAsset(_thePath,ImportAssetOptions.ForceUpdate);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment