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 /
This question was closed Apr 28, 2016 at 10:33 AM by Kamil1064 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Kamil1064 · Apr 07, 2016 at 08:10 PM · uisprite

Set picture to 4 UI Image grid

Hi, I have got simple grid on canvas made by UI Images. I would like to set sprites in UI Images so they fit right their content. What I want is on the right, what I have already is on left. Is there way to set uv for them? alt text

unity-ui-imgae-001.jpg (223.3 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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by TBruce · Apr 07, 2016 at 09:43 PM

The easy solution would be to slice up the image in import settings. Then you could easily set each individual image.

To do this dynamically its a bit more complicated, especially since the UI image has a RectTransform but it can be done with some coding. You would need to create a script that does something like this:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Gem : MonoBehaviour
 {
     public List<Image> uiImages = new List<Image>();
     public Texture2D image;
     public int rows = 2;
     public int columns = 2;
 
     // Use this for initialization
     void Start ()
     {
         if ((image != null) && (rows * columns) == uiImages.Count)
         {
             // first verify all GameObjects have been assigned
             for (int i = 0; i < uiImages.Count; i++)
                 if (uiImages[i] == null)
                     return;
         }
     }
 
     public void AssignImages()
     {
         for (int i = 0; i < rows; i++)
         {
             for (int j = 0; j < columns; j++)
             {
                 // you will need to create a sprite based on the portion of the image that you wan to copy
                 // and then assign it to the appropriate image in your list
             }
         }
     }
 }
Comment
Add comment · Show 3 · 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 TBruce · Jun 23, 2016 at 06:50 PM 0
Share

@$$anonymous$$amil1064 Would you be so kind as to click the tick to accept the answer if your question was answered. Thank you!

avatar image Kamil1064 TBruce · Jun 23, 2016 at 07:58 PM 0
Share

Sure, no problem :) I was sure it was done.

avatar image TBruce Kamil1064 · Jun 23, 2016 at 08:00 PM 0
Share

Thanks! Greatly appreciated.

Follow this Question

Answers Answers and Comments

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

Related Questions

UI Sprite location changes its appearance. 0 Answers

Crop UI image and convert it as Sprite 1 Answer

Sprite import problem? 1 Answer

Change UI GUI Image Sprite at runtime .. Unity 5 .. js 1 Answer

Inconsistent Sprite location on screen 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