标题: [Unity 组件参考手册]组件:资源组件之文本资源 [打印本页] 作者: . 时间: 2013-1-25 15:05 标题: [Unity 组件参考手册]组件:资源组件之文本资源 Text Assets are a format for imported text files. When you drop a text file into your Project Folder, it will be converted to a Text Asset. The supported text formats are:文本资源是导入的文本文件的一个格式。当你拖入一个文本文件到你的项目时,他会被转换为文本资源。支持的文本格式有: .txt
.html
.htm
.xml
.bytes
The Text Asset Inspector
[Properties 属性] Text 文本
The full text of the asset as a single string.
该资产的完整文本作为一个单一的字符串。 [Details 细节]The Text Asset is a very specialized use case. It is extremely useful for getting text from different text files into your game while you are building it. You can write up a simple .txt file and bring the text into your game very easily. It is not intended for text file generation at ***ntime. For that you will need to use traditional Input/Output programming techniques to read and write external files.文本资源是一个非常专业的使用情况。他通常用于从不同的文本文件中得到文本到你的游戏中当你编译他时。你可以写一个简单的.txt文件并且很容易的把文本带入到你的游戏中去。其目的不是在运行时生成文本文件。为此,你需要使用传统的输入/输出的编程技术来读取和写入外部文件。Consider the following scenario. You are making a traditional text-heavy adventure game. For production simplicity, you want to break up all the text in the game into the different rooms. In this case you would make one text file that contains all the text that will be used in one room. From there it is easy to make a reference to the correct Text Asset for the room you enter. Then with some customized parsing logic, you can manage a large amount of text very easily.请考虑下面的情形。你正在做一个传统的文字冒险游戏。为了制作简单,你想把游戏中的文本分解到不同的房间。在这种情况下,你会制作出一个文本他包含了所有将会在一个房间里使用的文本。从那里你很容易为你输入的房间引用正确的文本资源。然后使用一些自定义的分析逻辑,这样你可以很轻松的管理大量的文本。
Binary data 二进制数据A special feature of the text asset is that it can be used to store binary data. By giving a file the extension .bytes it can be loaded as a text asset and the data can be accessed through the bytes property.文本资源的一个特色是,他可以用来存储二进制数据。文件以.bytes作为扩展名,并且可以被作为一个文本资源进行加载,而且数据可以通过bytes属性进行访问。For example put a jpeg file into the Resources folder and change the extension to .bytes, then use the following script code to read the data at ***ntime:例如放一个jpeg的文件到Resources文件夹里,并且修改他的属性为.bytes,然后使用如下的脚本代码在运行时读取数据://Load texture from disk
TextAsset bindata= Resources.Load("Texture") as TextAsset;
Texture2D tex = new Texture2D(1,1);
tex.LoadImage(bindata.bytes); [Hints 提示] Text Assets are serialized like all other assets in a build. There is no physical text file included when you publish your game.
文本资源在编译时想其他资产一样被序列化。当你发布你的游戏时没有物理文本文件被包括其中。
Text Assets are not intended to be used for text file generation at ***ntime.
文本资源并不是要用于在运行时生成的文本文件。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/