Unity 中把一张大图(Texture)分割多个小图(Sprite)方法;
Texture2D bg = Resources.Load<Texture2D>("bg1");
sprites = new Sprite[9];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
sprites[index] = Sprite.Create(bg, new Rect(width * j, height * i, width, height), new Vector2(0, 0));
sprites[index].name = index.ToString();
GameObject game = Instantiate(box, list.transform) as GameObject;
game.GetComponent<Image>().sprite = sprites[index];
index++;
}
}