zoukankan      html  css  js  c++  java
  • unity, read text file

         using System.IO;

         //test read txt
            //Resources.Load(...) loads an asset stored at path in a Resources folder.
            //ref: http://docs.unity3d.com/Manual/class-TextAsset.html
            //ref: http://forum.unity3d.com/threads/read-text-file-that-is-included-in-the-project.189649/
            //ref: http://www.mindthecube.com/blog/2009/11/reading-text-data-into-a-unity-game
            //ref: http://www.unitymanual.com/6072.html  

            TextAsset textAsset = (TextAsset)Resources.Load("readme", typeof(TextAsset));
            if (textAsset==null) {
                Debug.Log("text file not found");
            } else {
                StringReader reader = new StringReader(textAsset.text);
                if ( reader == null )
                {
                    Debug.Log("text file not readable");
                }
                else
                {
                    // Read each line from the file
                    string str;
                    while ( (str = reader.ReadLine()) != null ){
                        Debug.Log("-->" + str);
                    }
                }

            }

    readme.txt放在Assets/Resources路径下。

  • 相关阅读:
    win10 在当前目录下 打开cmd
    Python 出现 can't use a string pattern on a bytes-like object
    Python3中urllib详细使用方法(header,代理,超时,认证,异常处理)
    python urllib2模块
    安装pip最简单的方法
    Thread.run方法是同步方法
    curl命令总结
    自己构建的Lumbda表达式
    将github上的项目源码导入eclipse详细教程
    JButton点击事件
  • 原文地址:https://www.cnblogs.com/wantnon/p/4605415.html
Copyright © 2011-2022 走看看