유니티 엔진으로 모바일 게임을 개발하던 중, 유니티  에디터에서는 분명히 잘 되던 파일 입출력이 안드로이드로 빌드해서 테스트하면 안되는 문제를 겪었다. 

 이 문제에 대해서 알아보니, 유니티 에디터에서는 에셋 폴더에 접근 가능하지만, 빌드 버전에서는 접근이 불가능하다는 것을 알게 되었다.(https://answers.unity.com/questions/272486/cannot-read-or-write-a-txt-file-after-build.html)

 빌드버전에서 에셋 파일을 사용하기 위해서는 Streaming Asset을 사용할 수 있다.


1. Streaming Asset이란

 에셋 폴더 내의 폴더들 중 특별취급되는 폴더 중 하나다.(http://wiki.unity3d.com/index.php/Special_Folder_Names_in_your_Assets_Folder)

 이 폴더에 포함된 파일들은 빌드 타겟 컴퓨터(안드로이드든, ios든 윈도우든)로 복사되어 들어가고, 읽기 전용이라서 게임 도중에 데이터 저장은 불가능하다.

 이 방법을 사용하려면 유니티 엔진에서 에셋 폴더 내에 StreamingAssets 라는 폴더를 만들고 ,그 안에 파일을 넣으면 이용 가능하다.

StraminAssets 폴더를 Asset 폴더 내에 배치하여 사용한다.


2. Streaming Assets 이용 방법

  Streaming Assets를 이용하는 방법은 2가지가 있다. WWW 클래스를 이용하는 방법, BetterStreamingAssets 오픈소스 라이브러리를 이용하는 방법, 이렇게 2가지인데, 각 방법은 각각의 포스팅으로 다루었으니 링크를 참조하기 바란다.

https://invincibletyphoon.tistory.com/48 (WWW Class) (비추천)

https://invincibletyphoon.tistory.com/47 (BetterStreaminAssets) (추천)



3. 레퍼런스

https://answers.unity.com/questions/272486/cannot-read-or-write-a-txt-file-after-build.html - 에디터에서는 에셋 폴더 접근이 가능하지만, 빌드버전에서는 불가능하다.

http://wiki.unity3d.com/index.php/Special_Folder_Names_in_your_Assets_Folder - 유니티 에셋 내의 특별한 디렉토리명들

https://docs.unity3d.com/2018.4/Documentation/Manual/StreamingAssets.html - 유니티 StreamingAssets 레퍼런스

https://stackoverflow.com/questions/20188742/writing-to-unitys-streamingassets-folder-at-runtime-on-android - StreamingAsset은 읽기 전용임.

http://memocube.blogspot.com/2014/04/blog-post.html - 유니티 DataPath 정리

https://ajh322.tistory.com/135 - 유니티 안드로이드 파일입출력 예제




'IT 관련 > 유니티 엔진' 카테고리의 다른 글

유니티 모바일 한글 깨짐  (2) 2019.09.25
WWW 클래스를 이용한 StreamingAsset 처리  (0) 2019.09.25
Better Streaming Asset  (5) 2019.09.25
블로그 이미지

서기리보이

,