public static Dictionary <string, UITextureInfo> loadTexturesFromTexturePackerJSON(string filename, Vector2 textureSize) { var textures = new Dictionary <string, UITextureInfo>(); var asset = Resources.Load(filename, typeof(TextAsset)) as TextAsset; if (asset == null) { Debug.LogError("Could not find Texture Packer json config file in Resources folder: " + filename); } var jsonString = asset.text; var decodedHash = jsonString.hashtableFromJson(); var frames = (IDictionary)decodedHash["frames"]; foreach (System.Collections.DictionaryEntry item in frames) { // extract the info we need from the TexturePacker json file, mainly uvRect and size var frame = (IDictionary)((IDictionary)item.Value)["frame"]; var frameX = int.Parse(frame["x"].ToString()); var frameY = int.Parse(frame["y"].ToString()); var frameW = int.Parse(frame["w"].ToString()); var frameH = int.Parse(frame["h"].ToString()); // for trimming support var spriteSourceSize = (IDictionary)((IDictionary)item.Value)["spriteSourceSize"]; var spriteSourceSizeX = int.Parse(spriteSourceSize["x"].ToString()); var spriteSourceSizeY = int.Parse(spriteSourceSize["y"].ToString()); var spriteSourceSizeW = int.Parse(spriteSourceSize["w"].ToString()); var spriteSourceSizeH = int.Parse(spriteSourceSize["h"].ToString()); var sourceSize = (IDictionary)((IDictionary)item.Value)["sourceSize"]; var sourceSizeX = int.Parse(sourceSize["w"].ToString()); var sourceSizeY = int.Parse(sourceSize["h"].ToString()); var trimmed = (bool)((IDictionary)item.Value)["trimmed"]; var rotated = (bool)((IDictionary)item.Value)["rotated"]; var ti = new UITextureInfo(); ti.frame = new Rect(frameX, frameY, frameW, frameH); ti.uvRect = new UIUVRect(frameX, frameY, frameW, frameH, textureSize); ti.spriteSourceSize = new Rect(spriteSourceSizeX, spriteSourceSizeY, spriteSourceSizeW, spriteSourceSizeH); ti.sourceSize = new Vector2(sourceSizeX, sourceSizeY); ti.trimmed = trimmed; ti.rotated = rotated; textures.Add(item.Key.ToString(), ti); } // unload the asset asset = null; Resources.UnloadUnusedAssets(); return(textures); }
public static UIStateSprite create(UIToolkit manager, string[] filenames, int xPos, int yPos, int depth) { // Grab the texture details for the initial state UITextureInfo firstNormalTI = manager.textureInfoForFilename(filenames[0]); Rect frame = new Rect(xPos, yPos, firstNormalTI.frame.width, firstNormalTI.frame.height); // create the button UIStateSprite sprite = new UIStateSprite(manager, frame, depth, firstNormalTI.uvRect); // Add frames sprite.addFrames(filenames); return(sprite); }
private Dictionary <string, UITextureInfo> loadTexturesFromTexturePackerJSON(string filename) { var textures = new Dictionary <string, UITextureInfo>(); var asset = Resources.Load(filename, typeof(TextAsset)) as TextAsset; if (asset == null) { Debug.LogError("Could not find Texture Packer json config file in Resources folder: " + filename); } var jsonString = asset.text; var decodedHash = (Hashtable)MiniJSON.JsonDecode(jsonString); var frames = (Hashtable)decodedHash["frames"]; foreach (System.Collections.DictionaryEntry item in frames) { // extract the info we need from the TexturePacker json file. mainly uvRect and size var sourceSize = (Hashtable)((Hashtable)item.Value)["sourceSize"]; var frame = (Hashtable)((Hashtable)item.Value)["frame"]; var frameX = int.Parse(frame["x"].ToString()); var frameY = int.Parse(frame["y"].ToString()); var frameW = int.Parse(frame["w"].ToString()); var frameH = int.Parse(frame["h"].ToString()); var ti = new UITextureInfo(); ti.frame = new Rect(frameX, frameY, frameW, frameH); ti.size = new Vector2(float.Parse(sourceSize["w"].ToString()), float.Parse(sourceSize["h"].ToString())); ti.uvRect = new UIUVRect(frameX, frameY, frameW, frameH, textureSize); textures.Add(item.Key.ToString(), ti); } // unload the asset asset = null; Resources.UnloadUnusedAssets(); return(textures); }
public static Dictionary<string, UITextureInfo> loadTexturesFromTexturePackerJSON( string filename, Vector2 textureSize ) { var textures = new Dictionary<string, UITextureInfo>(); var asset = Resources.Load(filename, typeof(TextAsset)) as TextAsset; if( asset == null ) Debug.LogError( "Could not find Texture Packer json config file in Resources folder: " + filename ); var jsonString = asset.text; var decodedHash = jsonString.hashtableFromJson(); var frames = (IDictionary)decodedHash["frames"]; foreach( System.Collections.DictionaryEntry item in frames ) { // extract the info we need from the TexturePacker json file, mainly uvRect and size var frame = (IDictionary)((IDictionary)item.Value)["frame"]; var frameX = int.Parse(frame["x"].ToString()); var frameY = int.Parse(frame["y"].ToString()); var frameW = int.Parse(frame["w"].ToString()); var frameH = int.Parse(frame["h"].ToString()); // for trimming support var spriteSourceSize = (IDictionary)((IDictionary)item.Value)["spriteSourceSize"]; var spriteSourceSizeX = int.Parse(spriteSourceSize["x"].ToString()); var spriteSourceSizeY = int.Parse(spriteSourceSize["y"].ToString()); var spriteSourceSizeW = int.Parse(spriteSourceSize["w"].ToString()); var spriteSourceSizeH = int.Parse(spriteSourceSize["h"].ToString()); var sourceSize = (IDictionary)((IDictionary)item.Value)["sourceSize"]; var sourceSizeX = int.Parse(sourceSize["w"].ToString()); var sourceSizeY = int.Parse(sourceSize["h"].ToString()); var trimmed = (bool)((IDictionary)item.Value)["trimmed"]; var rotated = (bool)((IDictionary)item.Value)["rotated"]; var ti = new UITextureInfo(); ti.frame = new Rect( frameX, frameY, frameW, frameH ); ti.uvRect = new UIUVRect( frameX, frameY, frameW, frameH, textureSize ); ti.spriteSourceSize = new Rect( spriteSourceSizeX, spriteSourceSizeY, spriteSourceSizeW, spriteSourceSizeH ); ti.sourceSize = new Vector2( sourceSizeX, sourceSizeY ); ti.trimmed = trimmed; ti.rotated = rotated; textures.Add( item.Key.ToString(), ti ); } // unload the asset asset = null; Resources.UnloadUnusedAssets(); return textures; }
private Dictionary<string, UITextureInfo> loadTexturesFromTexturePackerJSON( string filename ) { var textures = new Dictionary<string, UITextureInfo>(); var asset = Resources.Load( filename, typeof( TextAsset ) ) as TextAsset; if( asset == null ) Debug.LogError( "Could not find Texture Packer json config file in Resources folder: " + filename ); var jsonString = asset.text; var decodedHash = (Hashtable)MiniJSON.JsonDecode( jsonString ); var frames = (Hashtable)decodedHash["frames"]; foreach( System.Collections.DictionaryEntry item in frames ) { // extract the info we need from the TexturePacker json file. mainly uvRect and size var frame = (Hashtable)((Hashtable)item.Value)["frame"]; var frameX = int.Parse( frame["x"].ToString() ); var frameY = int.Parse( frame["y"].ToString() ); var frameW = int.Parse( frame["w"].ToString() ); var frameH = int.Parse( frame["h"].ToString() ); var ti = new UITextureInfo(); ti.frame = new Rect( frameX, frameY, frameW, frameH ); ti.uvRect = new UIUVRect( frameX, frameY, frameW, frameH, textureSize ); textures.Add( item.Key.ToString(), ti ); } // unload the asset asset = null; Resources.UnloadUnusedAssets(); return textures; }