gpt4 book ai didi

c# - 参数异常 : Empty path not allowed

转载 作者:太空宇宙 更新时间:2023-11-03 14:51:15 25 4
gpt4 key购买 nike

我想通过以下代码访问 Resources 文件夹中的 .txt 文件

void Start () {
TextAsset txtAsset = (TextAsset)Resources.Load("Dialogue0", typeof(TextAsset));
string dialogue = txtAsset.text;

lines = new List<DialogueLine>();

LoadDialogue(dialogue);
}

void LoadDialogue(string filename)
{
string line;
StreamReader r = new StreamReader(filename);

using (r)
{
do
{
line = r.ReadLine();
if (line != null)
{
string[] lineData = line.Split('|');
if (lineData[0] == "Player")
{
DialogueLine lineEntry = new DialogueLine(lineData[0], "", 0,0, "");
lineEntry.options = new string[lineData.Length - 1];
for (int i = 1; i < lineData.Length; i++)
{
lineEntry.options[i - 1] = lineData[i];
}
lines.Add(lineEntry);
}
else
{
DialogueLine lineEntry = new DialogueLine(lineData[0], lineData[1], int.Parse(lineData[2]), int.Parse(lineData[3]), lineData[4]);
lines.Add(lineEntry);
}
}
}
while (line != null);
r.Close();
}
}

但总是出现错误:

ArgumentException: Empty path not allowed

System.IO.StreamReader..ctor (System.String path, System.Text.Encoding encoding,
Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
(at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/StreamReader.cs:159)

System.IO.StreamReader..ctor (System.String path)
(wrapper remoting-invoke-with-check) System.IO.StreamReader:.ctor (string)

DialogueParser.LoadDialogue (System.String filename) (at Assets/Script/DialogueParser.cs:54)

DialogueParser.Start () (at Assets/Script/DialogueParser.cs:44)

The .txt file is really exist, named "Dialogue0.txt"

我已经搜索了一段时间,但我还没有找到解决问题的方法。

编辑:Contents of dialogue0.txt

最佳答案

我认为你应该有扩展名“Dialogue0.txt”而不仅仅是“Dialogue0”:

TextAsset txtAsset = (TextAsset)Resources.Load("Dialogue0.txt", typeof(TextAsset));

关于c# - 参数异常 : Empty path not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51691380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com