관리 메뉴

caLAB

[유니티] 유니티 PNG 캡처(feat. 투명 배경 저장) 본문

카테고리 없음

[유니티] 유니티 PNG 캡처(feat. 투명 배경 저장)

도이(doi) 2021. 9. 26. 15:02
728x90

https://assetstore.unity.com/packages/tools/transparency-capture-509

 

Transparency Capture | 도구 | Unity Asset Store

Get the Transparency Capture package from orange030 and speed up your game development process. Find this & other 도구 options on the Unity Asset Store.

assetstore.unity.com

이 애셋 사용하시면 됨. 

짱!bb

 

쓰기 편하게 코드도 작성해놨다궁 XD

using System.Collections;
using UnityEngine;

public class zzTransparencyCaptureExample:MonoBehaviour
{
    public Texture2D capturedImage; //캡처된 이미지 저장
    public Material saveCapture;

    public IEnumerator capture()
    {
        //전체 화면 캡처
        Rect lRect = new Rect(0f,0f,Screen.width,Screen.height);
        if(capturedImage)
            Destroy(capturedImage);

        yield return new WaitForEndOfFrame();
        capturedImage = zzTransparencyCapture.capture(lRect);

        //material의 texture에 captureImage 저장
        saveCapture.SetTexture("_MainTex", capturedImage);
    }

    Vector3 lastMousePosition;
    public void Update()
    {
        //c 눌렀을 때 캡처
        if (Input.GetKeyDown(KeyCode.C))
            StartCoroutine(capture());
        //s 눌렀을 때 캡처 지움
        if (Input.GetKeyDown(KeyCode.S))
            Destroy(capturedImage);
    }

    //gui화면에 보여줌.
    void OnGUI()
    {
        if (capturedImage)
        {
            GUI.DrawTexture(
                new Rect(Screen.width * 0.1f, Screen.height * 0.1f, Screen.width * 0.8f, Screen.height * 0.8f),
                capturedImage,
                ScaleMode.ScaleToFit,
                true);
            GUI.color = Color.green;
        }

        GUI.color = Color.black;
    }
}
728x90
반응형
Comments