-
-
Save jesterswilde/e7842dce52a2692ce4f1 to your computer and use it in GitHub Desktop.
The Unity component of creating a sprite sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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