当前位置:   article > 正文

Unity 3D 读取 TextAsset_unity textasset

unity textasset

TextAsset是Unity 提供的一个文本对象,它可以通过Resources.Load 或者 AssetBundle 来读取数据。

其中数据是string格式的。当然也可以按byte[]读取。

它支持读取的文本格式包括 .txt .html .htm .bytes .json .csv .yaml .fnt。

新建一个文本

拖入工程Resources下

 加载读取

  1. using UnityEngine;
  2. public class LoadMyTextMyTools : MonoBehaviour
  3. {
  4. private void Start()
  5. {
  6. string mystr = Resources.Load<TextAsset>("MyText/MyText").text;
  7. Debug.Log(mystr);
  8. }
  9. }

 Editor编辑器模式下

  1. using UnityEditor;
  2. using UnityEngine;
  3. public class LoadTextAssetEditorMyTools
  4. {
  5. [MenuItem("MyTextAsset/LoadTextAsset", false, 0)]
  6. static void LoadMyTextAsset()
  7. {
  8. string mystr = Resources.Load<TextAsset>("MyText/MyText").text;
  9. Debug.Log(mystr);
  10. }
  11. }

log

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/112016?site
推荐阅读
相关标签
  

闽ICP备14008679号