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路径下。

  • 相关阅读:
    读后感之—寒门学子重要选择-程序员
    架构中的分而治之
    如何从码农进化到项目管理者
    饿了么架构
    简单理解支付宝和蚂蚁花呗的架构
    架构小谈之美团外卖
    漫谈架构总结之1500
    平台基本信息项目目标文档
    第六学期每周总结-第三周
    质量管理之可用性战术分析
  • 原文地址:https://www.cnblogs.com/wantnon/p/4605415.html
Copyright © 2011-2022 走看看