我正在关注库存教程系列,它正在使用JSON来保存用于库存的数据。
错误在此块中
using UnityEngine;
using System.Collections;
using LitJson;
using System.Collections.Generic;
using System.IO;
public class ItemDatabase : MonoBehaviour {
private List<Item> database = new List<Item>();
private JsonData itemData;
void Start()
{
itemData = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/StreamingAssets/Items.json"));
ConstructItemDatabase();
Debug.Log(database[1].Player);
}
我得到的错误是
DirectoryNotFoundException:找不到路径的一部分&#34; H:\ Webb_Finale \ Fantasy \ Assets \ StreamingAssets \ Items.json&#34;。 System.IO.FileStream..ctor(System.String路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,布尔匿名,FileOptions选项)(在/ Users / builduser / buildslave / mono-runtime-and-classlibs / build /mcs/class/corlib/System.IO/FileStream.cs:292) System.IO.FileStream..ctor(System.String路径,FileMode模式,FileAccess访问,FileShare共享) (wrapper remoting-invoke-with-check)System.IO.FileStream:.ctor(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) System.IO.File.OpenRead(System.String path)(at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:363) System.IO.StreamReader..ctor(System.String path,System.Text.Encoding encoding,Boolean detectEncodingFromByteOrderMarks,Int32 bufferSize)(at / Users / builduser / buildslave / mono-runtime-and-classlibs / build / mcs / class / corlib / System.IO / StreamReader.cs:167) System.IO.StreamReader..ctor(System.String路径,System.Text.Encoding编码) (wrapper remoting-invoke-with-check)System.IO.StreamReader:.ctor(string,System.Text.Encoding) System.IO.File.ReadAllText(System.String path,System.Text.Encoding encoding)(at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File的.cs:587) System.IO.File.ReadAllText(System.String path)(at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/File.cs:582) ItemDatabase.Start()(在Assets / Scripts / ItemDatabase.cs:13
我不知道如何解决这个问题,感谢您的帮助!