텍스트 에셋(Text Assets) 는 임포트한 텍스트 파일의 포맷입니다. 텍스트 파일을 Project 폴더에 드롭하면 텍스트 에셋으로 변환됩니다. 지원되는 텍스트 포맷은 다음과 같습니다.
스크립트 파일도 AssetDatabase.FindAssets 함수 사용을 목적으로 텍스트 에셋으로 간주되며, 이 함수를 “t:TextAsset” 필터와 함께 사용할 때 결과 리스트에도 포함됩니다.
프로퍼티: | 기능: |
---|---|
Text | 한 문자열로 나타낸 에셋의 전체 텍스트입니다. |
텍스트 에셋의 사용 사례는 아주 특수합니다. 빌드 중 게임에 다른 텍스트 파일에서 텍스트를 가져올 때 특히 유용합니다. 간단한 .txt 파일을 작성하여 아주 쉽게 게임으로 텍스트를 가져올 수 있습니다. 런타임 시점에 텍스트 파일을 생성하는 용도가 아닙니다. 이를 위해 외부 파일을 읽고 쓰려면 전형적인 입력/출력 프로그래밍 기술을 사용해야 합니다.
다음 시나리오를 고려해야 합니다. 텍스트가 아주 많은 모험 게임을 만들려고 합니다. 제작 과정을 단순화하기 위해 게임의 모든 텍스트를 여러 방으로 나누려고 합니다. 이 경우 한 방에 사용되는 모든 텍스트가 포함된 텍스트 파일을 하나 만들 수 있습니다. 거기에서 입력한 방의 올바른 텍스트 에셋을 쉽게 참조할 수 있습니다. 그런 다음, 사용자 정의 구문 분석 로직을 사용하여 많은 양의 텍스트를 아주 쉽게 관리할 수 있습니다.
텍스트 에셋의 특별한 기능은 바이너리 데이터 보관에 사용할 수 있다는 것입니다. 파일에 .bytes 확장자를 부여함으로 텍스트 에셋으로 로드할 수 있으며 bytes 프로퍼티를 통해 데이터에 액세스할 수 있습니다.
예를 들어 jpeg 파일을 Resources 폴더에 넣고 .bytes로 확장자를 변경하면 다음 스크립트 코드를 사용하여 런타임 시점에 데이터를 읽어야 합니다.
//Load texture from disk
TextAsset bindata = Resources.Load("Texture") as TextAsset;
Texture2D tex = new Texture2D(1,1);
tex.LoadImage(bindata.bytes);
.txt 및 .bytes 확장자 파일은 각각 텍스트와 바이너리 파일로 취급됩니다. 데이터를 읽을 때 예기치 못한 동작이 발생할 수 있기 때문에 바이너리 파일을 .txt 확장자로 저장하지 말아야 합니다.
TextAsset
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.