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
1
Question by Mr.LeoSantos · Jul 25, 2014 at 05:54 AM · spritetexture2datlasslice

How do I access a texture slice's rect via scripting?

Hi, I need to get the rect with the coordinates for each of the slices in a texture that's already been sliced in the sprite editor. Couldn't find any reference to slices in the scripting docs. Is there a way to access those "sub-images" directly?

(I'm assuming here that those sub-images are kept in some sort of texture atlas, and what I need are the coordinates of those slices in the atlas).)

Thanks!

Comment
Add comment · Show 3
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 DajBuzi · Jul 25, 2014 at 06:01 AM 0
Share

Nonono, every image is a separate object you need to threat them as a seperate images not as a whole atlas.

avatar image Owen-Reynolds · Jul 25, 2014 at 04:12 PM 0
Share

DajBuz: the Q is about getting the secret Atlas coords. Say you have a goat sprite. The Sprite editor puts it in some part of the altas it makes(?), and saves those goat UV coords.

If you could get the altas texture and those goat coords, you could draw the goat sprite yourself, maybe changing it some special way.

avatar image Mr.LeoSantos · Jul 25, 2014 at 06:25 PM 0
Share

Yes, I'm trying to manipulate the UVs associated with each slice here, not access the images themselves. I imagine there's a rect array that contains the coordinates relative to the original image, which I could convert to a vector2 array representing the uvs in the atlas. Thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Mr.LeoSantos · Aug 14, 2014 at 05:05 AM

I figured it out. It's pretty obvious, actually.

Sprite.rect returns a rectangle that points to the location (in pixels) relative to the original texture. To use it as 4 UV coordinates, one for each corner, simply divide rect.xMin (cast as a float) by the image's width, rect.yMin by the image's height, rect.xMax by the image's width and rect.yMax + rect.height by the image's height again.

http://docs.unity3d.com/ScriptReference/Sprite-rect.html

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Texture2D.PackTextures() - maximumAtlasSize 1 Answer

Reference Specific Sprites from Atlas 1 Answer

Coding my own auto-slicer, getting "islands" of pixels at runtime? 1 Answer

Slicing sliced sprite via script 0 Answers

Can a sprite atlas be 4 bit? 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