TextAsset.bytes 字节

var bytes : byte[]

Description描述

The raw bytes of the text asset. (Read Only)

文本资源的原始字节。(只读)

If you're using the text asset to contain binary data, you should make sure the file has the .bytes extension. For any other of the extentions the TextImporter will try to strip nonascii characters if it is unable to parse the file as an utf8 string.

如果你使用的文本资源包含二进制数据,你应确保文件有.bytes扩展。对于任意其他的扩展,如果它不能解析为utf8字符串,文本导入器会尽量带nonascii字符。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public TextAsset imageTextAsset;
	void Start() {
		Texture2D tex = new Texture2D(4, 4);
		tex.LoadImage(imageTextAsset.bytes);
		renderer.material.mainTexture = tex;
	}
}
// Load a .jpg or .png file by adding .bytes extensions to the file
// and dragging it on the imageTextAsset
//通过给文件添加一个.bytes扩展,加载一个.jpg或.png文件,
//并且拖动它到imageTextAsset上
var imageTextAsset : TextAsset;

function Start () {
	var tex = new Texture2D (4, 4);
	tex.LoadImage(imageTextAsset.bytes);
	renderer.material.mainTexture = tex;
}
最后修改:2011年1月2日 Sunday 21:35

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。