RectTransform containerRect = gameObject.GetComponent<RectTransform> ();
RectTransform itemRect = item.GetComponent<RectTransform> ();
float itemHeight = containerRect.rect.height;
float ratio = itemHeight / itemRect.rect.height;
float itemWidth = itemRect.rect.width * ratio;
GameObject newItem = Instantiate (item) as GameObject;
Image image = newItem.GetComponentInChildren <Image> ();
Texture2D preview = AssetPreview.GetMiniThumbnail (newItem);
Rect rect = new Rect (0, 0, itemWidth, itemHeight);
image.sprite = Sprite.Create (preview, rect, new Vector2 (0f, 0f), 125);
The Question
Im trying to get a preview thumbnail of a Prefab and insert it into a Image in a Panel.
It works fine when I run it in a small window, but if I run it in “Maximize on play” i get the following error
Rect rect = new Rect (0, 0, 64, 64);
image.sprite = Sprite.Create (preview, rect, new Vector2 (0f, 0f), 125);
Now i have another problem, the GetMiniThumbnail do not show the thumbnail as seen in the Project Tab, but just a thumbnail of a “standard” prefrab icon
Just Use
image.overrideSprite = Sprite.Create(texture, new Rect(0,0, <texture.width> , <texture.height>),new Vector2(0.5f, 0.5f),100);
hope it will be ok. Thats it
Hello, I’m making something like a “magic wand” that paints the drawing the original color.
For that I modified the PatternBrush as follows [attachment] and this way I get the texture of my assets.
However, the texture is coming in the wrong size/place.
Do you have any solution?