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

时间: 2024-10-23 13:46:12

unity, read text file的相关文章

create feature from text file

'''---------------------------------------------------------------------------------- Tool Name: CreateFeaturesFromTextFile Source Name: CreateFeaturesFromTextFile.py Version: ArcGIS 9.1 Author: Environmental Systems Research Institute Inc. Required

shell脚本执行时报"bad interpreter: Text file busy"的解决方法

在执行一个shell脚本时,遇到了"-bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy"错误提示,如下所示: [[email protected] bin]$ ./killSession.sh      -bash: ./killSession.sh: /bin/bash: bad interpreter: Text file busy 此时只需要在#!/bin/bash,加一空格#! /bin/bas

Writing Text File From A Tabular Block In Oracle Forms

The example given below for writing text file or CSV using Text_IO package from a tabular block in Oracle Forms. Suppose there is a tabular grid data block "Job_History" in your forms and you want to write a CSV on click of a button by reading w

SharePoint 2010: Export User Profile Properties to a Text File or Excel using PowerShell

导出到txt [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") [void][System.Reflection.Assembly]::LoadWithParti

【转】shell脚本执行时报"bad interpreter: Text file busy"的解决方法

1)问题现象: 在ubuntu下执行以下脚本( while_count),报错: -bash: ./while_count: /bin/bash: bad interpreter: Text file busy 2)问题原因: This happens because the script file is open for writing, possibly by a rogue process which has not terminated. 3)解决办法: Solution: Check

解决Unity的 The file 'MemoryStream' is corrupted! Remove it and launch 崩溃问题

孙广东   2015.7.30 问题:   在项目平时删除资源或者脚本资源时产生的prefab的脚本引用丢失,特别是在场景scene中丢了解决方式/// 1.又一次Clone项目/// 2.删除项目的 Library 目录(推荐.解决紧急问题)/// 3.使用这个脚本解决全部问题(这个当然推荐了) http://forum.unity3d.com/threads/editor-want-to-check-all-prefabs-in-a-project-for-an-attached-monob

What is a text file and what is a binary file :)

If you are not coming from a programming background it might not yet be clear what is really a file? What is a binary file and what makes something a text file? 其实总归一句话:[Files that consist exclusively of ASCII characters are known as text ?les. All o

Save output to a text file from Mac terminal

  Simply with output redirection: system_profiler > file.txt Basically, this will take the output of system_profiler and save it to the file file.txt. There are technically two different output "streams", standard output, and standard error.

Unity: Invalid serialized file version xxx Expected version: 5.3.4f1. Actual version: 5.3.5f1.

Unity发布安卓项目,如果直接使用Unity打包APK一切Ok,导出Google项目 使用Idea打包 一进去直接Crash. 报错: 1978-2010/? E/Unity﹕ Invalid serialized file version. File: "/data/app/eran.project.b-1/base.apk/assets/bin/Data/globalgamemanagers". Expected version: 5.3.4f1. Actual version: