1. ์คํ๋ผ์ดํธ๋ฅผย ๋ฉํฐํ๋ก ํ๊ณ ์๋ํฐ์์ ์ํ๋๋๋ก ์ฌ๋ผ์ด์ค ํ๋ค
2. Read/Write Enabled ์ฒดํฌ
3. ํฌ๋งท ๋ฐฉ๋ฒ์ ํ์ผํ์ ํธํ๋๋ ๊ฑธ๋กย ์ค์ ํ๋ค. (RGBA 32bit ์ถ์ฒ)
4. Apply๋ฅผ ๋๋ฅธ๋ค.
using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class TextureToImage : MonoBehaviour { public Sprite[] sprites; // Start is called before the first frame update void Start() { foreach (var sp in sprites) { int x = Mathf.FloorToInt(sp.textureRect.x); int y = Mathf.FloorToInt(sp.textureRect.y); int width = Mathf.FloorToInt(sp.textureRect.width); int height = Mathf.FloorToInt(sp.textureRect.height); Texture2D t2d = new Texture2D(width, height); Color[] c = sp.texture.GetPixels(x, y, width, height); t2d.SetPixels(c); t2d.Apply(); File.WriteAllBytes(Application.dataPath + "/../" + sp.name + ".png", t2d.EncodeToPNG()); } } }
5. ์คํฌ๋ฆฝํธ ์์ฑ
6. ์ค๋ธ์ ํธ ํ๋ ๋ง๋ค๊ณ ์คํฌ๋ฆฝํธ ์ง์ด๋ฃ๊ณ sprites์๋ ์คํ๋ผ์ดํธ๋ค๋ ์ง์ด ๋ฃ๋๋ค.
7. ์คํ
8. Profit!
๋ฐ์ ์ง๋ฌธ ์๊ธธ๋ ์์๋ด
๊ทผ๋ฐ ์ด๊ฒ ์ ํ์ํ์ง๋ ๋ชฐ๊ฒ ๋ค
์ค;; ์ง์ง ๊ฐ์ฌ
์ ๋ ๊ฒ ๋ฑ๋ฑ ๋๋์ด์ ธ์์ผ๋ฉด ์ฝ๋๋ก ์๋ฅด๊ธฐ๊ฐ ํธํ๋ฐ ๊ฐ๋ ์์น ์ง๋ฉ๋๋ก ๋์๋๊ฒ๋ค ๋ค๋ฅธ๊ณณ์์ ์๋ฅด๊ธฐ๊ฐ ํ๋ค์ด๊ฐ์ง๊ณ .. ์ ๋ํฐ๊ฐ ์๋์ผ๋ก ์๋ผ์ฃผ๋ ๊ธฐ๋ฅ์ ์ธ๋ถ์์๋ ์ฐ๊ณ ์ถ์์