Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 saiato · Nov 26, 2013 at 02:09 AM · 2dgameobjectrendering

Drawing 2D rectangles with rounded corners

I am working on translating this prototype I built in HTML into Unity, but I cannot figure out how to draw the 2D rectangles that are the blocks. In HTML this was very simple: I would create an element, set its width/height, set it's border radius (rounded corners), set its fill and stroke. I know Unity uses meshes, but is there any way I can create and manipulate them to get this effect? Maybe I need to use something other than meshes? I have been playing with the idea of making them cubes instead of 2D planes, would this be easier?

Comment
Add comment · Show 1
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 Kiloblargh · Nov 26, 2013 at 02:20 AM 0
Share

Why? It looks like all you need are some textures with alpha channel.

2 Replies

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

Answer by s_guy · Nov 26, 2013 at 02:32 AM

If your app is strictly 2d, don't make your assets into cubes. Try to recreate your prototype with squares in Unity first. I recommend using the sprite pipeline. Then, with the textured squares, use the alpha channel to hide the curved corners.

If you are having trouble making a 2d app in Unity, post a new question about your specific issues.

Comment
Add comment · Show 4 · 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 saiato · Nov 26, 2013 at 02:51 AM 0
Share

Thank you for your reply! I apologize if my question sounds silly, I am still a beginner. That does make sense, but how would the texture handle scaling? The blocks in the game can be grouped into bigger blocks of different ratios, so how can I keep the rounded corners consistent if the block is scaled, say, 4x2y? Example: http://i.imgur.com/8ohTVtu.png

EDIT: I used the sprite material to create a block, and the alpha is working great! The scaling is still a problem, however... Screenshot: http://i.imgur.com/3$$anonymous$$ds$$anonymous$$Cd.png

avatar image Kiloblargh · Nov 26, 2013 at 04:34 AM 0
Share

So just make another texture for half a block... Or make separate corner, edge, and center tiles, then you can assemble them in any configuration you like. You're not going to run out of texture space, you can make the faces separate from the outlines and use a vertex colored shader to tint it all the different colors.

avatar image Excrubulent · Nov 26, 2013 at 04:51 AM 1
Share

Currently Unity doesn't do 2d vector graphics out of the box; only sprites. You may want to look into RageSpline: http://u3d.as/content/freakow-/rage-spline/1D$$anonymous$$ However, you could also create a corner sprite and edge sprites, then scale the edges to fill the gaps between corners. It's not as elegant as simply specifying roundness and size, and it's not as flexible, but that's a way you could do it without spending money.

avatar image s_guy · Nov 26, 2013 at 08:00 PM 0
Share

The technique $$anonymous$$iloblargh describes is sometimes called a "9 slice". $$anonymous$$nowing that should help you find more on google or find some related tools in the unity asset store that can automate the pipeline. 9 slicing can give pixel-perfect edges on arbitrarily large rectangles, with some constraints. It won't keep a face drawn in the middle of a rectangle from having artifacts as it scales up though.

For center detail that holds up on larger blocks like in your example, you'll need a bigger texture. If you have only a few sizes and only a few textures, you can probably afford a custom texture for each size. Experiment with the "pixels to units" texture scaling in the sprite pipeline.

avatar image
0

Answer by andrii-shpak · Oct 14, 2015 at 01:12 AM

https://www.assetstore.unity3d.com/en/#!/content/46997 you can use this plugin to draw round rect, circle, tringle, polygon, curve in uGUI like image

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

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

Related Questions

How to improve 2D rendering at a distance. 1 Answer

How am I supposed to use SetTile( ) on a GameObject's position if its x and y values aren't integers? , 1 Answer

Small line appearing under my 2D pixel sprite - 2D Graphics not rendering properly 2 Answers

Unity 2d - drawing effects composed of sprites 0 Answers

Horizontal gravity on One gameobject 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