Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
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
Comments Locked · 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 $$anonymous$$iniJSON. 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
0
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
Comments Locked · 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
-1

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
Comments Locked · 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 beco$$anonymous$$g 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

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

How can I use atlas sprite as texture for a material? 2 Answers

SpriteAtlas clone memory problem 0 Answers

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


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