• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jan 08, 2015 at 11:23 AM by Josh Naylor for the following reason:

The question is answered, right answer was accepted

avatar image
Question by Tomer-Barkan · May 31, 2013 at 09:37 PM · texturespritejsonatlas

Parsing a TexturePacker JSON file

When I use texture packer to publish a texture atlas of for "Unity3d", it creates a txt file with the following JSON format:

 {
     "frames": {
         "frame-abc.png":
         {
             "frame": {"x":41,"y":2,"w":256,"h":256},
             "rotated": false,
             "trimmed": false,
             "spriteSourceSize": {"x":0,"y":0,"w":256,"h":256},
             "sourceSize": {"w":256,"h":256}
         },
         "someframe":
         {
             "frame": {"x":2,"y":2,"w":37,"h":382},
             "rotated": false,
             "trimmed": false,
             "spriteSourceSize": {"x":0,"y":0,"w":37,"h":382},
             "sourceSize": {"w":37,"h":382}
         }
     }
 }

My question is, how can I parse this to create a simple class so I can easily access the uv coordinates for each frame:

 public class FrameAtlas{
     Frame[] frames;
 }


 public class Frame {
     private string name;
     private Rect rect;
 }
Comment

People who like this

0 Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image adgristy · Jan 07, 2014 at 12:41 PM 0
Share

Did you ever get this sorted tbkn? I am working on exactly the same thing at the moment and I am struggling a little!

avatar image Tomer-Barkan · Jan 08, 2014 at 08:05 AM 0
Share

I ended up using MiniJSON. The atlas packer JSON is simple enough to pack using this without any smart magic deserializer... Simply iterate the JSON objects and create a rect from the data within each.

Eventually I didn't use the atlas, so I don't have any code to share anymore... sorry. But as far as I understand, unity now has a built in atlas packer (maybe only pro?)

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by TonyLi · Jun 01, 2013 at 12:56 AM

Use LitJSON: http://lbv.github.io/litjson/

Or use JSONObject: http://wiki.unity3d.com/index.php/JSONObject

Or, since you're providing the JSON, there aren't any security issues with just using eval(), but it's much slower than LitJSON.

Or, if you can get Texture Packer to export to XML instead, you can use XmlSerializer to load it.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by Andreas Loew · Jan 08, 2015 at 11:21 AM

If you really need access to the UV coordinates one of the JSON readers is the best solution. See above.

However if you intend to create sprites from the data the way easier solution is to use Unity's Texture2D / Sprite classes with a sprite sheet. This already handles the complete drawing and also allows you to directly use your sprites in the editor.

There's a unity plugin that can directly parse sprite sheet data.

Comment
Josh Naylor

People who like this

-1 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Josh Naylor ♦♦ · Jan 08, 2015 at 11:22 AM 0
Share

Fair enough posting on newer questions with this solution but this is becoming spam/advertising on older questions. Please stop

avatar image Josh Naylor ♦♦ · Jan 08, 2015 at 11:23 AM 0
Share

Also, the link doesn't work anyway

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

loading sprite from atlas in script 4 Answers

NGUI Texture atlas help ! 1 Answer

How to get textures/sprites from Atlas and use it ? 1 Answer

Create 1 NGUI atlas , which has more than 1 PNG's 0 Answers

How to scroll a region of texture (which is an atlas) on a mesh (which is a sprite) 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges