首页 > 编程语言 > 详细

unity, read text file

时间:2015-06-28 13:58:23      阅读:181      评论:0      收藏:0      [点我收藏+]

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

unity, read text file

原文:http://www.cnblogs.com/wantnon/p/4605415.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!