- Home /
Switch sprite by code using atlas
Hello!
So, here's what I have: I have a atlas for my UI since I want to reduce my drawcalls. I want to replace a sprite in one of my UI elements with another one from the same atlas. In NGUI, you could do this quite simply. I wrote some code to allow me to find sprite info in my atlas using the sprite's name.
So far, so good. Now, I have the info about the texture, the pivot and the rectangle I want my sprite to use. However, Unity does not allow me to just set these values in a sprite since all of those attributes are read-only. The only workaround I found is to create a sprite and assign it to my image, which is ridiculously slow.
So my question is: Is there an easy way to edit my image's sprite data without just creating and assigning a new one?
Thanks in advance! Let me know if there are any questions.
Your answer
Follow this Question
Related Questions
Best way to change sprite in Image (GUI 4.6) ? 1 Answer
My Spritesheet won't slice and appears super pixelated 0 Answers
override SpritePacker packing order 0 Answers
Change Spritesheet Programatically 1 Answer
Gui Box - Texture - Spritesheet 0 Answers