Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 BeB_Wir3 · Jul 21, 2015 at 01:07 PM · c#uimultipleui imagemask

Create UI Mask from Childrens images

I think the title kind of nails it already. Is it possible to set the image of an UI Mask to the images of the children?

I have made a couple of sprites for some buttons and windows, so they get placed nicely when re-sizing the buttons of windows without stretching like so:

alt text

every color is a different piece of sprite, and only the red, green, blue and yellow pieces are able to stretch. pretty simple. for every piece I have an invisible background which i want to use as a mask, so the mask would scale dynamically with the rest of the window. but i cant seem to find a way to apply the child images to the mask! anyone with a salution or work around?

button-example.jpg (28.0 kB)
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

2 Replies

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

Answer by brunopava · Jul 21, 2015 at 02:34 PM

  • Add them to a Panel.

  • Add a Content Size Filter to the Panel

  • Adjust the Content Size Filter to resize itself.

  • Add a Mask to the Panel.

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
avatar image
1

Answer by alexi123454 · Jul 21, 2015 at 01:20 PM

The mask component takes the image directly from the Image component on the same gameObject. So, to change the image of the mask, all you have to do is set the sprite of the Image component on the parent to the sprite being used by the image component of the child.

 transform.parent.GetComponent<Image>().sprite = GetComponent<Image>().sprite;
Comment
Add comment · Show 7 · 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 BeB_Wir3 · Jul 21, 2015 at 02:27 PM 0
Share

Indeed this would be it. This is the standard procedure for using masks. But what i want to achieve is use a combined set of images (multiple childs) to use as a mask for another object (the background). Is this possible?

avatar image alexi123454 · Jul 21, 2015 at 03:57 PM 0
Share

You could try having a number of Panel parents with masks on them (equal to the number of sprites you have), and put all of the sprites on the bottom-most parent. Then, assign an image to each of the parents for each sprite you want. The masks will combine with each other to form the final mask. This will probably require you to change the way some of the masks work, but I'm having a little trouble understanding what the final product should look like from your screenshot. It just seems like a jumble of colors to me :P

avatar image BeB_Wir3 · Jul 21, 2015 at 10:00 PM 0
Share

I added the colors to show all the different parts of the window. Every colored piece has its own part of the complete sprite. maybe this is a little bit more clear, and closer to the final result.

alt text

alt text

button-example-2.jpg (96.8 kB)
button-example.jpg (28.0 kB)
avatar image BeB_Wir3 · Jul 21, 2015 at 10:12 PM 0
Share

(sadly enough unity answers forces my to do this in multiple comments, i may not add more than 2 images..)

this setup works great with re sizing the windows

alt text

every piece is re-positioned without the corners stretching. This should be done by the "sliced" Image Type option in the Image component, but i cant seem to get I seem to get it to work right.

alt text

image-type-proof.jpg (34.0 kB)
button-example-3.jpg (55.0 kB)
avatar image alexi123454 · Jul 22, 2015 at 06:51 AM 1
Share

The reason your sliced sprite isn't working is probably because of the pixels per unit setting in the sprite import options. Try fiddling with the size of it and see if that helps you at all :P

As for adding multiple panels, you can just right click on an object in the heirarchy, go down to the UI option, and click "Panel". Or, if you can't right click for reason, you can access the same menu from the Assets menu bar option, or the Create button at the top left of the heirarchy window. The reason you couldn't find is as a component is because a "panel" isn't a component, it's just a large image :P

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Getting the overlapping pixels between a UI mask and a UI image 0 Answers

Multiple Cars not working 1 Answer

UI Image source image not changing 2 Answers

Saving image in a variable purely through code? 1 Answer

how Can I make a UI Image Blink On And Off 5 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