【发布时间】:2016-04-21 10:17:44
【问题描述】:
您好,我在为 Unity3D 编写编辑器时遇到了问题,我遇到了一个问题,我正在读取具有常规字符串的 .txt 文件中的行,然后是每个常规字符串下方的文件扩展名(代表扩展名的类别)。当我尝试在分配给下一行的字符串上运行子字符串时,问题就出现了。当我尝试使用任何子字符串时,文件显示为打开失败,但没有它,打开就好了。
public bool PopulateList()
{
bool success = true;
string path = "Assets/Scripts/Editor/Extensions.txt";
sourceFile = new FileInfo("Assets/Scripts/Editor/Extensions.txt");
if (!File.Exists(path))
{
Debug.Log("File Does Not Exist");
TextWriter tw = new StreamWriter(path, true);
tw.Close();
}
string line;
ExtensionUnit anExtension;
try
{
StreamReader myStreamReader = sourceFile.OpenText();
line = myStreamReader.ReadLine();
while (!myStreamReader.EndOfStream)
{
anExtension = new ExtensionUnit();
anExtension.Categories = line;
line = myStreamReader.ReadLine();
/*if(line.Substring(0,1) == ".")
{
//Debug.Log(line.Substring(0, 1));
}*/
//Debug.Log(line.Substring(0, 1));
/*while(line.Substring(0,1) == ".")
{
anExtension.Extensions = line;
theExtensions.Add(anExtension);
//Next extension
line = myStreamReader.ReadLine();
}*/
//Empty blank space
line = myStreamReader.ReadLine();
}
myStreamReader.Close();
}
catch
{
success = false;
}
return success;
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow。你能显示文本文件的例子吗?
-
你不能只使用 TextAsset 吗?
-
@JoeBlow 我会使用文本资源,但我没有使用 Unity 引擎库,仅使用 Unity 编辑器库
标签: c# unity3d substring streamreader unity5