赞
踩
TextAsset是Unity 提供的一个文本对象,它可以通过Resources.Load 或者 AssetBundle 来读取数据。
其中数据是string格式的。当然也可以按byte[]读取。
它支持读取的文本格式包括 .txt .html .htm .bytes .json .csv .yaml .fnt。
新建一个文本
拖入工程Resources下
加载读取
- using UnityEngine;
-
- public class LoadMyTextMyTools : MonoBehaviour
- {
- private void Start()
- {
- string mystr = Resources.Load<TextAsset>("MyText/MyText").text;
- Debug.Log(mystr);
- }
- }
Editor编辑器模式下
- using UnityEditor;
- using UnityEngine;
-
- public class LoadTextAssetEditorMyTools
- {
- [MenuItem("MyTextAsset/LoadTextAsset", false, 0)]
- static void LoadMyTextAsset()
- {
- string mystr = Resources.Load<TextAsset>("MyText/MyText").text;
- Debug.Log(mystr);
- }
- }
log
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。