I have a real hard time finding information about how to do this. I have a sprite sheet that is set to multiple and I want to get the slices information so I can use it as texture on a mesh. Could someone point me in the right direction? Can this be done by using the rectOffset somehow? Or should I just forget it and use single sprites as opposed to a sprite sheet?
I tried something like this (pseudo-ish code):
public Sprite[] spriteList; //all sprite slices referenced in inspector
void Start(){
renderer.material.mainTexture = spriteList[0].texture; //only gets the whole texture of the sprite sheet, not just the slice
}
If you’re wondering what my goal is: I want to animate the faces of my character models not as 3D animation, but by changing the texture. I guess I can easily do this with single sprites, but I suppose it would be better using sheets (or atlases?)
If it is unclear what I’m trying to achieve, please don’t hesitate to inquire.
Thanks! Alas, it is not really an answer to my question, which essentially is: how can I load the textures defined by sprite slices I cut by using the Sprite Editor when I reference them through the inspector? At the moment I’m solving my issue by offsetting and scaling the whole sheet, but out of interest, I would still love to know how to get the splice texture information.
Iirc the way sprites work is by offsetting the uvs, but sharing the same texture. So the texture is never actually cut.
If you want to cut the texture itself, look into Texture2D.GetPixels and Texture2D.SetPixels
you can use the Rects from the sprite and determine what pixels you need to get that way, then create new textures and set their pixels with this slice.