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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by callen · May 23, 2014 at 06:59 PM · 2d2d-gameplayquad

Automatically resize quad to match texture, in the editor

Maybe I'm not searching the right terms, but idk where to even start here... I want to build a simple character editor for a 2D game.

I previously built a prototype version. It would look at its material's texture at runtime, and set the quad's XY scale to a multiple of the pixel width/height of the tex. That worked well until I started trying to make pieces in many different sizes. For example, a tall helmet would cover the char's eyes, short hair and long hair would appear in different places, etc.

So then I wrote a bunch of code to try and auto-align the parts, but it's not a viable solution. What I want to do is align everything in the editor, on separate quads, and then just copy them at runtime according to a character's visual definition.

But to do this, every single quad I throw a texture onto will need its scale set by hand to look the same as it would in-game. Is there any way I can have a quad resize itself in the editor when I change its material/texture?

Thanks for any guidance!

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 Fattie · May 24, 2014 at 07:39 AM 0
Share

Just use 2DToolkit, everyone does

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by callen · May 23, 2014 at 08:13 PM

If I'm doing everything right here, I found a good solution. I didn't know about the ExecuteInEditMode attribute, but a small script with this does a fine job. So after that all I did was attach the material to the script instead of the MeshRenderer, and copied it over in Update:

     void Update()
     {
         if (renderer.sharedMaterial != TexMat)
         {
             if ((renderer.sharedMaterial = TexMat) != null)
                 transform.localScale = PixelScale * new Vector3(TexMat.mainTexture.width, TexMat.mainTexture.height, 1 / PixelScale);
         }
     }

At first I assigned to renderer.material, but got some kind of error which led me to using sharedMaterial. However idk what the difference means for me at runtime, I may have to add more code later.

Comment
Add comment · Show 1 · 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 PixelFireXY · Oct 06, 2021 at 03:17 PM 0
Share

Thank you very much, this is what I was looking for!

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

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

Related Questions

so I'm trying to make a 2D platform but the first animation i make is the only one that registers 0 Answers

2D Animation does not start 1 Answer

Best way for a objects interaction system? 1 Answer

Moving an object after player click? 1 Answer

Is using velocity.y + someNumber a bad idea? 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