• 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 /
avatar image
0
Question by reptilebeats · Jul 25, 2012 at 11:08 PM · atlas

atlas tool like ngui

hi i was just wandering if there was an asset on unity that can make an atlas like ngui, and will have a list of the textures that can be used on object. so i can click the object and say use image 1 in atlas out of 10 images

Comment
Add comment · Show 10
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 reptilebeats · Jul 26, 2012 at 12:02 AM 0
Share

i still can't seem to find one, all i want is say a small box around each image inside the atlas which gives the cords of the image, and will then realign the uv size by which ever image is selected

avatar image reptilebeats · Jul 27, 2012 at 12:20 AM 0
Share

does anyone know of a tool that will do this

avatar image AlucardJay · Jul 27, 2012 at 12:27 AM 0
Share

Prime31's UIToolkit uses Texture Packer (free version available). http://www.codeandweb.com/texturepacker

You can create your atlas with this program, but will have to write a script to parse the packed image text file information, to extract the image names and positions in the atlas. This is something I am going to do, but havn't done it yet. (I have done a font file parser script, so it shouldn't be much more than that when I get around to it!)

avatar image reptilebeats · Jul 27, 2012 at 01:40 AM 0
Share

well if you ever get round to finishing it let us know, i was looking for a tool to pack the images into an atlas and give a drop down menu of the images in the atlas which can be used for objects. basically its exactly the same as ngui, but for gameObjects ins$$anonymous$$d.

i can use his tool to make an atlas but its a bit annoying scaling and moving the uv, i tend to save the object as a prefab now after i have done it, but i thought maybe someone had made a tool to do this

avatar image AlucardJay · Jul 27, 2012 at 10:37 PM 0
Share

Before and while making this script, I have searched alot on parsing .json files, and there is some info out there. But nothing ready made, except for the stuff to buy, or UIToolkit is free and works (I had a hard time learning this, that's when I started to write my own, I have my own text mesh scripts now). For example, this test of $$anonymous$$e is all procedurally generated meshes, using my text file reader : http://www.alucardj.net16.net/unityanswers/sndmngr1.html

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by AlucardJay · Jul 27, 2012 at 10:45 PM

EDIT :

So I have been working on this, and thanks to a script supplied by @heaversm , I have made a solution that applies a texture by name to a plane created with heaversm's script. The result is automatically assigned UVs for the textures and all in 1 drawcall =]

Download the full package here, it contains all scripts and a sample texture sheet to show proof-of-concept : http://www.alucardj.net16.net/unityanswers/TexturePackerParser.unitypackage

To make Atlas : Create your atlas and text file with Texture Packer (free version available http://www.codeandweb.com/texturepacker ). Remember to change the information file to .txt format. Note - you can save your texture packer project, and as long as you don't move the images on your computer, the project can be opened and other images then can be added or removed. In Unity, set the texture import settings, then create a material with your Atlas (also assign shader).

To use the Reader : Place the script on an empty gameObject. In the script, set up a variable and typecast it to GameObject (e.g. public var object1 : GameObject;). Then to assign an image, In the Start function call the method AssignMaterials with the object variable name and the Image in the Atlas you wish to use. Drag-and-drop the Material and the image information Text File into the inspector. Drag-and-drop the object into the Inspector. That's it ! You can call AssignMaterials in any function to change the image (with some scripting it would be possible to play a sprite-sheet animation).

To use the Plane Creator : This is a modified version of heaversm's script. I have locked it to a single quad, and changed the Menu location. In Unity, there should now be a new option - Custom Item. Click on this, then click on Custom Simple Plane ... Set the Width, Length, Orientation (Vertical), optional Collider and the name for the object, then hit create. Done.

And that's about it. Please give it a try and leave feedback on what you think, I am very excited at how this works. I have uploaded a package because it's much easier than upping each script and explaining where it goes, and with an example project it should be easy to work out how to use it for yourself. Happy Coding =]

http://www.alucardj.net16.net/unityanswers/TexturePackerParser.unitypackage


After a long night (yes, I'm watching the sun come up!) I think I've cracked it. Actually had to ask a couple of questions myself to get it done, but I have the first stage of a working Texture Packer Reader completed. Woo-Hoo =]

I say first stage because there are a few considerations. Firstly this is a dirty script i.e. the values are hard-coded, but I have tested this on several Texture Packer atlases, and the text format stays the same so it always works (for me so far).

Also this script uses SetTextureOffset and mainTextureScale to change the UVs on the object. Using these commands the benefit of an atlas is lost, as SetTextureOffset increases the drawcall by one. So instead of 4 objects sharing an atlas having 1 drawcall, this has 4.

The Proper way to do this is to swap the UVs on the vertices. As I know you are interested in performance (from your other questions) I had to mention it. I can make Quad-Meshes and swap the UVs on the verts, but that will take alot more work (that's why they charge for NGUI, FlyingText3D, etc). Also I am still trying to perfect procedural meshes in ExecuteInEditMode.

Anyway, here is a working reader. You can download Texture Packer and make your own atlases to test it for yourself (or I can upload some sample textures and text files).

I have left in some commented lines, these can be used to read a texture instead of a material. To use a texture instead of a material, comment out any line with textureAtlasMaterial, and un-comment any line with textureAtlas. Just make sure you have a suitable material with shader on your objects if you do this. The script will assign the texture by itself.

To test and learn to use this :

  • Create an atlas and a text file, make the atlas as a material, drag and drop the text file and the material in the Inspector.

  • Then Create 4 cubes, and drop them in the Inspector.

  • In the script, look for the line with the comment Change the image name HERE, type the name of the IMAGE you want to display here. (the name of the separate image in the atlas, Not the atlas name)

  • Hit Play =]

The 4 cubes should then be individually rendered to the name of the image you gave.

Hopefully this explanation and the screenshot shows what I mean.

Here's the script !

 #pragma strict
 
 public var textureAtlasInfo : TextAsset;
 
 //public var textureAtlas : Texture;
 public var textureAtlasMaterial : Material;
 
 private var textureInfo : Vector4;
 private var textureWidth : float;
 private var textureHeight : float;
 
 private var tempInfo : String;
 private var _words : String[];
 
 // -- user objects --
 public var cube1 : GameObject;
 public var cube2 : GameObject;
 public var cube3 : GameObject;
 public var cube4 : GameObject;
 // -- END --
 
 function Start() 
 {
  LoadTextureInfo();
  AssignMaterials();
 }
 
 function AssignMaterials() 
 {
  // -- Code to assign material and set the Tiling and Offset -- 
  
  // cube1.renderer.material.mainTexture = textureAtlas;
  cube1.renderer.material = textureAtlasMaterial;
  var cube1_offsets : Vector4 = GetTexInfo( "box_checked.png" ); // ** Change the image name HERE
  cube1.renderer.material.SetTextureOffset ( "_MainTex", Vector2( cube1_offsets.x, 0 - cube1_offsets.y - cube1_offsets.w ) );
  cube1.renderer.material.mainTextureScale = Vector2( cube1_offsets.z, cube1_offsets.w );
  
  
  // cube2.renderer.material.mainTexture = textureAtlas;
  cube2.renderer.material = textureAtlasMaterial;
  var cube2_offsets : Vector4 = GetTexInfo( "joystick.png" ); // ** Change the image name HERE
  cube2.renderer.material.SetTextureOffset ( "_MainTex", Vector2( cube2_offsets.x, 0 - cube2_offsets.y - cube2_offsets.w ) );
  cube2.renderer.material.mainTextureScale = Vector2( cube2_offsets.z, cube2_offsets.w );
  
  
  // cube3.renderer.material.mainTexture = textureAtlas;
  cube3.renderer.material = textureAtlasMaterial;
  var cube3_offsets : Vector4 = GetTexInfo( "knob.png" ); // ** Change the image name HERE
  cube3.renderer.material.SetTextureOffset ( "_MainTex", Vector2( cube3_offsets.x, 0 - cube3_offsets.y - cube3_offsets.w ) );
  cube3.renderer.material.mainTextureScale = Vector2( cube3_offsets.z, cube3_offsets.w );
  
  
  // cube4.renderer.material.mainTexture = textureAtlas;
  cube4.renderer.material = textureAtlasMaterial;
  var cube4_offsets : Vector4 = GetTexInfo( "button_pause.png" ); // ** Change the image name HERE
  cube4.renderer.material.SetTextureOffset ( "_MainTex", Vector2( cube4_offsets.x, 0 - cube4_offsets.y - cube4_offsets.w ) );
  cube4.renderer.material.mainTextureScale = Vector2( cube4_offsets.z, cube4_offsets.w );
  
  // -- END --
 }
 
 function LoadTextureInfo() // Read the Text File
 {
  //if (textureAtlasInfo == null || textureAtlas == null)
  if (textureAtlasInfo == null || textureAtlasMaterial == null)
  {
  Debug.Log("TEXT INFO FILE or TEXTURE is NOT FOUND");
  return;
  }
  
  //textureWidth = textureAtlas.width;
  //textureHeight = textureAtlas.height;
  textureWidth = textureAtlasMaterial.mainTexture.width;
  textureHeight = textureAtlasMaterial.mainTexture.height;
  
  tempInfo = textureAtlasInfo.text;
  
  tempInfo = tempInfo.Replace("\r", "");
  tempInfo = tempInfo.Replace("\n", "");
  tempInfo = tempInfo.Replace("\t", "");
  tempInfo = tempInfo.Replace("{", "");
  tempInfo = tempInfo.Replace("}", "");
  tempInfo = tempInfo.Replace(":", "");
  tempInfo = tempInfo.Replace(",", "");
  tempInfo = tempInfo.Replace(" ", "");
  
  _words = tempInfo.Split("\""[0]);
  
 }
 
 function GetTexInfo( imageName : String ) : Vector4 // Call this to assign material UVs
 {
  for (var i : int = 0; i < _words.length; i ++)
  {
  if ( String.Equals( _words[i], imageName ) )
  {
  textureInfo.x = parseFloat( _words[i + 5] ) / textureWidth;
  textureInfo.y = parseFloat( _words[i + 7] ) / textureHeight;
  textureInfo.z = parseFloat( _words[i + 9] ) / textureWidth;
  textureInfo.w = parseFloat( _words[i + 11] ) / textureHeight;
  }
  }
  
  return textureInfo;
 }

  • Only change things between the // ---- and // -- END --

  • Calling the function GetTexInfo( "box_checked.png" ); returns the UV position and size for the image in the quotation marks.

Then the material is set to the correct UVs with cube1.renderer.material.SetTextureOffset and cube1.renderer.material.mainTextureScale . Like I said before , the proper way to reduce drawcalls is to swap the UVs on the verts with the Vector4 info.

Let me know what you think =]

alt text

Comment
Add comment · Show 21 · 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 AlucardJay · Jul 28, 2012 at 09:00 PM 0
Share

Please check out the answer again with my new Edit, thanks to a script supplied by @heaversm (http://answers.unity3d.com/questions/270852/animated-texture-on-quad.html), I have made a solution that applies a texture by name to a plane created with heaversm's script. The result is automatically assigned UVs for the textures and all in 1 drawcall =]

avatar image reptilebeats · Jul 28, 2012 at 11:47 PM 0
Share

yh something like this is awesome, i would love to see this made into an editor version, if anyone decides to make this into an asset i would gladly pay for it as my coding skills aren't that good at the moment.

if it needed texture packer i would still get it, as even assets like ngui require third party software. but in all something like this is exactly what i was looking for just an editor version

avatar image reptilebeats · Jul 29, 2012 at 12:08 AM 0
Share

ok I'm getting confused is jay kay alucardj

avatar image AlucardJay · Jul 29, 2012 at 12:11 AM 0
Share

Yep, that's me =]

You can check this by clicking on the name (it is a link to the profile page)

                                                         -->
avatar image AlucardJay · Jul 29, 2012 at 12:21 AM 0
Share

You can see the textures by adding this line at the start of the TexturePackerParser script :

  @script ExecuteInEdit$$anonymous$$ode

It throws the error : Instantiating mesh due to calling $$anonymous$$eshFilter.mesh during edit mode. This will leak meshes. Please use $$anonymous$$eshFilter.shared$$anonymous$$esh ins$$anonymous$$d.

but when you hit play it doesn't affect the scene. And then just delete this line when you are done or about to publish and there shouldn't be a problem =]

Show more comments
avatar image
0

Answer by bruce.. · Oct 31, 2012 at 09:33 PM

Hi! I've been trying TexturePacker and noticed that if you have no license, the exported texture has some "adds" remaining you have no license...is there any other free option? Thanks!

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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

9 People are following this question.

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

Related Questions

Combined Mesh + Texture Atlas = Distorted lightmap 0 Answers

Modify texture coordenates with a shader. 0 Answers

How can I apply settings for a TextureImporter during post process? 1 Answer

Get a sprite from a Sprite Packer atlas? 2 Answers

Need help with Particle System 0 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