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 /
avatar image
0
Question by Essential · Jun 15, 2012 at 10:12 PM · iostexturesmenuguitexturepacktextures

Need help packing menu textures

I have a menu that is essentially a background image and 4 buttons using GUITextures. What I'm trying to do is get the buttons into one draw call.

My idea is to use the PackTextures() function to create an atlas, but I need help! I'm unfamiliar with non-runtime code and was wondering if someone could give me the basics of how I'd go about replacing my buttons into one atlas and getting them back into the scene?

I'm thinking something along the lines of…

  1. Create temporary GameObject

  2. Attach the button textures as an array

  3. Run PackTextures() function on array to create atlas

  4. Delete/disable the temp GameObject

  5. Find the resulting atlas [where?] and attach it to all 4 buttons

  6. Get the rect coordinates [how?]

  7. Specify the rect coordinates to each GUITexture component so it knows which area of atlas to use [also how?]

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

1 Reply

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

Answer by Wolfram · Jun 15, 2012 at 10:35 PM

Hm, I don't think you can change the UV mapping of GUITextures, you might need to use UnityGUI instead (the stuff in OnGUI(), although I'm also not sure it's possible with that, either, since I don't use it), or use a planar 3D object attached to your camera parallel to your screen (there are scripts around on how to accomplish that)

But to answer the rest of your questions:

  • 1+4 You don't need an additional GameObject, just attach the script to an empty object, or your target object

  • 5 PackTextures() is a method of Texture2D, and the resulting atlas will replace that texture. So for example, you could create an empty texture, call myTexture.PackTextures() on it, and now myTexture will be your atlas

  • 6 The Rect[] array matching your Texture2D[] input array is returned by PackTextures()

Comment
Add comment · Show 5 · 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 Essential · Jun 15, 2012 at 10:51 PM 0
Share

Thanks Wolfram. It's making a bit more sense now. I will try the plane approach. (Then I can do some funky stuff with 3D buttons!)

Though I'm still confused on how to use a script like this… I'm guessing it's not something I want to have happen at runtime right? $$anonymous$$y understanding is I'd set-up the script, press the editor's play button, it would create the atlas, I'd stop the game in the editor, and now I can disable that script for the future because it created the atlas already. — Is this right? I'm thinking my understanding may be a bit off.

avatar image Wolfram · Jun 15, 2012 at 10:59 PM 0
Share

You can do both. Either just do it at runtime, in a regular script. Then your script would also need to replace all textures with the atlas reference, and replace the UVs of all objects involved.

Or you could write an EditorWindow script, which would create the atlas, and store it as an asset (AssetDatabase.CreateAsset). But then you'd have to think about something to also store the UV values somewhere.

avatar image Wolfram · Jun 15, 2012 at 11:06 PM 1
Share

In our projects, we're doing our GUIs using 3D objects exclusively, since OnGUI() doesn't work with uniTUIO, which we rely on, and GUITextures are far less flexible. See my answer here: http://answers.unity3d.com/questions/24863/3d-plane-width-in-pixels-worldtoscreensize.html

avatar image Essential · Jun 18, 2012 at 09:32 PM 0
Share

Nice. Thanks!

avatar image Essential · Jun 18, 2012 at 09:33 PM 0
Share

Also realized that BatchTools will do this for me anyway! :)

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.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why do I have to click GUI Menu twice to start in Web player? 0 Answers

Textures on iPhone appear blurry? 1 Answer

Calling Function in other Script via Touch => iOS Crash 1 Answer

How will i get animated gif images in scene? 6 Answers

The name 'Joystick' does not denote a valid type ('not found') 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