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 vexe · Aug 14, 2013 at 06:55 AM · texturetransformscalesizengui

Help finding the right scale for an icon inside a backgorund sprite

In my inventory system, an item could take more than one slot, 2x2, 2x3, 3x3, etc. Each item has a texture - I don't care about the texture size (for a 2x2 item, the texture size doesn't have to be like, 256x256 or 128x128, but it would be better if it was)

Since I'm using NGUI, the item slot is actually a button, with a background, an icon (both sprites) and a label. I instantiate the slots, by using a Slot prefab, which has a script that stores the Slot size, for now I'm using 50. There's also a spaceBetweenSlots variable, which is 5.

So if I had a 2x2 item, its background would be of size 105x105, I scale the background to that size.

But the problem is, the item icon. I can't seem to know how to scale the icon, for it to fit perfectly inside the background. Take a look at this example:

alt text

alt text

Now the RedHerb fits, because its size is 594x601 and I'm scaling it by 100x100x1, but the gun is 640x453, if I scale it by the same scale as the Herb, you would get the results above.

Now the question is, how can I scale the icon to perfectly sit inside the background?

I came up with an idea of finding the difference between the icon's and the background's size, I keep scaling down the icon till there's a low dif between the two sizes. But NGUI is giving me a hard time of doing anything -_-

For my idea to work I just need the icon's and the background's size. I searched and found NGUIMath.CalculateAbsoluteWidgetsBounds, I'm not sure how to use it, it asks for a transform, and returns a Bounds, so I gave my background's, it got me back a bound with size of 0.2x0.2, did the same for the icon it gave me back a size of 0.0x0.0 lol O_O what is that?!

I tried background.relativeSize, I got back a V3 of (50,50,1) - NGUI forums says to Scale that by background.cachedTransform.relativeSize, to get the size in pixles, so I did:

 background.relativeSize.Scale(background.cachedTransform.localScale);

Is that correct? is that how to scale two vectors? - I got back a V2 of (1.0, 1.0) :D

Any help would be much appreciated, thanks a lot.

ngui.png (38.3 kB)
ngui.png (169.5 kB)
Comment
Add comment · Show 6
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 Joyrider · Aug 14, 2013 at 08:02 AM 0
Share

I'd post a link of this question on the NGUI forum ^^ They should be most suited to respond to how you should do this. I don't know NGUI, but it seems a pretty basic functionality you should have, so I'm sure they'll be able to help you along.

avatar image vexe · Aug 14, 2013 at 08:09 AM 0
Share

Unfortunately NGUI = one guy. He answers most the Qs, pretty overloaded/overworked guy. So the answer might come really slow... :/ Anyway, I did ask there.

avatar image Joyrider · Aug 14, 2013 at 08:21 AM 0
Share

Something I'm not getting about your scaling... are you trying to apply the same scaling modifier to the gun, than you do to the leaves? Even though the original texture/object do not have the same original size?

avatar image vexe · Aug 14, 2013 at 08:31 AM 0
Share

No, not the same scale. I'm having the problem because I'm using the same scale for textures of dif sizes. The background is scaled 105,105,1 the gun is 100,100,1 - that gives the result ^. However, if manually change the gun scale down to 85,75,1 it fits perfectly. $$anonymous$$y whole journey is to figure out a formula to give me back that new scale I have to apply to the gun.

avatar image Joyrider · Aug 14, 2013 at 08:44 AM 0
Share

Since I don't know NGUI, I'm probably not getting all of this. But when you say scale, you're talking about the transform scaling right? (And not talking about the size in pixels) And if you know the scaling of the background and its original size, and know the original size of the gun, you should be able to compute the scale of the gun, no?

logicaly, scaleGun/scaleBG = sizeGun/sizeBG so scaleGun = scaleBG*sizeGun/sizeBG;

But again, might be missing something ^^

Show more comments

1 Reply

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

Answer by vexe · Aug 14, 2013 at 02:38 PM

Solved, with some help from Chulup @NGUI forums.

It wasn't about dif textures sizes not being able to scale uniformly, it was just NGUI trying to be a smart-ass!

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

16 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

Related Questions

NGUI sprite size 1 Answer

NGUI resizes fine in engine but not on actual devices 1 Answer

Why does this not scale smoothly? Any Ideas? Transform.localscale 2 Answers

How do you Scale Game Objects with the Screen? 0 Answers

Draw texture the same size of a sprite 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