유니티 C# 스크린샷 찍고 다운로드 폴더에 이미지 저장 방법 간단 구현

반응형

유니티 C# 스크린샷 찍고 다운로드 폴더에 이미지 저장 방법 간단 구현

using UnityEngine;
using System.IO;

public class ScreenshotManager : MonoBehaviour
{
    public string screenshotFileName = "screenshot.png";

    void Update()
    {
        // 스페이스바를 눌렀을 때 스크린샷을 찍고 저장
        if (Input.GetKeyDown(KeyCode.Space))
        {
            TakeScreenshot();
        }
    }

    // 스크린샷을 찍고 저장하는 함수
    void TakeScreenshot()
    {
        string path = GetScreenshotPath(screenshotFileName);
        ScreenCapture.CaptureScreenshot(path);
        Debug.Log("Screenshot saved to: " + path);
    }

    // 다운로드 폴더 경로 가져오기
    string GetScreenshotPath(string fileName)
    {
        string folderPath = "";

        // 각 플랫폼별로 다운로드 폴더 경로 지정
        if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor)
        {
            folderPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Downloads");
        }
        else if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
        {
            folderPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "Downloads");
        }
        else if (Application.platform == RuntimePlatform.Android)
        {
            folderPath = "/storage/emulated/0/Download"; // Android의 다운로드 폴더
        }
        else if (Application.platform == RuntimePlatform.IPhonePlayer)
        {
            folderPath = Application.persistentDataPath; // iOS에서는 다운로드 폴더 대신 이 경로 사용
        }

        // 폴더가 없으면 생성
        if (!Directory.Exists(folderPath))
        {
            Directory.CreateDirectory(folderPath);
        }

        // 파일 전체 경로 반환
        return Path.Combine(folderPath, fileName);
    }
}

 

유니티 Simple Capture 활용 (에셋)

 

[유니티 Unity] 유니티로 화면 캡쳐하기 <SimpleCapture>

유니티로 화면 캡쳐하기 유니티 화면 간단 캡쳐 도구 패키지를 다운 받으면 다음 처럼 창이 생깁니다. 클릭하면 스크린 샷을 사용할 수있는 속성창이 나옵니다. 캡처를 원하는 카메라를 컴포넌

j2su0218.tistory.com

 

반응형