I actually have multiple images that I want to use the same packing tag for and I need to create UI Images from all of them.
1 Answer
1I went with the following work around:
Selected all the images I wanted to use and held ALT and dragged them from the project view into the hierarchy. This created a group of Sprite objects with SpriteRenderer components attached and then I made them a parent of “sprite-objects” game object.
I then used the following code:
//Convert Sprites to UI Images
SpriteRenderer[] sprites = GameObject.Find("sprite-objects").GetComponentsInChildren<SpriteRenderer>();
foreach (SpriteRenderer rend in sprites)
{
var sprite = rend.sprite;
GameObject.Destroy(rend.GetComponent<SpriteRenderer>());
rend.gameObject.AddComponent<Image>();
rend.gameObject.AddComponent<CanvasRenderer>();
rend.gameObject.GetComponent<Image>().sprite = sprite;
}
Hit play and then all the sprites will be changed into UI Images types.
Then simply select all the new image objects and “Copy” Cntrl-C or Right Click Copy.
Then Stop playing the scene.
Then paste and bingo you have all your objects as Images ready to interact with.
I'd like to know the same thing. Just a guess would be to create an editor script that does that, but don't know how myself.
– hexagonius