일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 람다식
- BGM
- 배열
- script
- 스파르타내일배움캠프
- 프로그래머스
- unity
- invokec#events
- skybox
- ObjectPool
- 유니티
- 장애물달리기
- 인터페이스
- soundmanager
- delegate
- c#
- 메서드
- 스택
- Generic
- 자료구조
- FSM
- 비선형자료구조
- InputManager
- 코루틴
- 유한상태머신
- 효과음
- inputsystem
- 직렬화
- LINQ
- UI
- Today
- Total
Unity 개발일지
[Unity] 스크린샷 찍는 코드 본문
오늘은 간단하게 Unity에서 스크린샷을 찍어 누끼를 따는데 도움이 되는 코드를 공유하고자 한다.
private Texture2D ScreenShot(RenderTexture externalTexture)
{
Texture2D myTexture2D = new Texture2D(externalTexture.width, externalTexture.height);
if (myTexture2D == null)
{
myTexture2D = new Texture2D(externalTexture.width, externalTexture.height);
}
//Make RenderTexture type variable
RenderTexture tmp = RenderTexture.GetTemporary(
externalTexture.width,
externalTexture.height,
0,
RenderTextureFormat.ARGB32,
RenderTextureReadWrite.sRGB);
Graphics.Blit(externalTexture, tmp);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = tmp;
myTexture2D.ReadPixels(new UnityEngine.Rect(0, 0, tmp.width, tmp.height), 0, 0);
myTexture2D.Apply();
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(tmp);
byte[] screenshot = myTexture2D.EncodeToPNG();
File.WriteAllBytes(Application.dataPath + "/Screenshots/test.png", screenshot);
#if UNITY_EDITOR
AssetDatabase.Refresh();
#endif
return myTexture2D;
}
코드리뷰