Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 youngwolf0 · May 24, 2017 at 07:38 AM · ui imagescalingresizing

Rezise model to match canvas

I am trying to create a room with framed pictures on the wall, I have a model from blender that I have placed as a child under a ui canvas object. I already have code to set the image in the canvas based on a public variable, what I want to be able to do is make the frame model match the size of the parent canvas.

The idea being that I can save this as a prefab then recreate it with different image sources so that no matter what size image I use and its dimensions the 3d model will match it.

I'm not sure how to do this or if I should be using something other than ui.frame for this.

Comment
Add comment · Show 2
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 RobAnthem · May 24, 2017 at 05:11 PM 0
Share

Why are you using a 3D model as a picture? Does it walk around and move? Why wouldn't it just be a render texture? Or an animation, or if it doesn't move, a screenshot?

avatar image youngwolf0 · May 24, 2017 at 05:18 PM 0
Share

@RobAnthem The ingame object is a canvas showing a piece of art that I am loading in from an api so I can periodically change the art on the wall.

The way it works is I have a ui image and a 3D model of a canvas frame inside a single parent object and I wanted it to resize properly based on the image size being pulled in.

1 Reply

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

Answer by youngwolf0 · May 24, 2017 at 05:33 PM

The answer I eventually came up with was I manually lined up the frame with the canvas, then in the code:

  • Load image source dynamically from url variable.

  • Get the pixel size of the image.

  • Resize the canvas to the image pixel size.

  • Work out the percentage difference in the height and width of the image from the original default size.

  • Apply this percentage difference to the scale attribute of the frame model.

Worked perfectly :)

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 RobAnthem · May 24, 2017 at 05:38 PM 0
Share

Why wouldn't you of just used a flat plane, put the frame over it, and load the picture as a texture? It would automatically fit if the image was square. No canvas/ui mess either.

avatar image youngwolf0 · May 24, 2017 at 05:45 PM 0
Share

@RobAnthem Because the images aren't all square, i don't know what the aspect ratio of the image is going to be until it's pulled into the app. I really need the frame because of the nature of the app I'm making so this was the only way I could find to do it.

avatar image RobAnthem youngwolf0 · May 24, 2017 at 07:33 PM 0
Share

I feel like there is a more efficient method, but neither of us can think of it, so glad you got it solved :)

avatar image youngwolf0 RobAnthem · May 24, 2017 at 08:21 PM 0
Share

Yeah, thanks for the input as well, I'm really new to game development in general so it's all appreciated :)

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

How to make Image same size as UI Button 1 Answer

How to scale ui image eventually from all sides ? 1 Answer

MessageBox Panel (How to add resizable Text container?) 0 Answers

How to fine-control UI elements scale 0 Answers

Wrpping my head around canvas,Wraping my head around Canvas placement 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