0

我无法访问上传到 LMS 服务器的 WebGL 构建中的文件 StreamingAssets 文件夹,我将这些文件保存在 StreamingAssets 文件夹中以更新它以备将来使用。遵循统一手册中给出的说明,在编辑器中工作正常,但直接构建运行并且在 LMS 中无法正常工作。

http://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html

张贴在论坛上,他们要求遵循手册,但它不起作用。请在此处找到附加的脚本以获取更多详细信息。检查游戏开始时调用的名为'userDetailsXmlPath'的协程函数。

public string filePath = Application.streamingAssetsPath + "/UserDetails.xml";
public string result = "";

IEnumerator userDetailsXmlPath() 
{
    print (filePath);

    if (filePath.Contains ("://") || filePath.Contains (":///")) {
        WWW www = new WWW (filePath);
        yield return www;
        result = www.text;

        print (result);
        FetchUserDetails ();
    } else {
        result = File.ReadAllText (filePath);

        print (result);
        FetchUserDetails ();
    }
}

public void FetchUserDetails()
{
    XmlDocument userXml1 = new XmlDocument ();
//  userXml1.Load(Application.streamingAssetsPath + "/UserDetails.xml");
//  userXml1.Load(Application.dataPath + "js/UserDetails 1.xml");
//  userXml1.LoadXml(userXml.text);

    userXml1.LoadXml(result);


    XmlNodeList userList = userXml1.GetElementsByTagName ("user");

    foreach(XmlNode userValue in userList)
    {
        XmlNodeList userContent = userValue.ChildNodes;
        objUser = new Dictionary<string, string>();

        foreach(XmlNode value in userContent)
        {
            objUser.Add (value.Name, value.InnerText);
        }

        userFullDetails.Add (objUser);

        userCountInXml = userList.Count;

        userId = new string[userList.Count];
        questionSetOfUser = new string[userList.Count];
    }

    AssignUserXmlValuesToArray ();
}

请引导我解决这个问题。

4

1 回答 1

0

使用 WWW 类https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html访问 StreamingAssets 路径文件夹

public string filePath = Application.streamingAssetsPath + "/UserDetails.xml";
         public string result = "";
   
   void Awake () 
   { 
   filePath = Application.streamingAssetsPath + "/UserDetails.xml"; 
   }
   
   void Start () 
   { 
   StartCoroutine(userDetailsXmlPath() );
   }
   
         IEnumerator userDetailsXmlPath() 
         {
             print (filePath);
     
             if (filePath.Contains ("://") || filePath.Contains (":///")) {
                 WWW www = new WWW (filePath);
                 yield return www;
                 result = www.text;
     
                 print (result);
                 FetchUserDetails ();
             } else {
                 result = File.ReadAllText (filePath);
     
                 print (result);
                 FetchUserDetails ();
             }
         }
     
         public void FetchUserDetails()
         {
             XmlDocument userXml1 = new XmlDocument ();
     
             userXml1.LoadXml(result);
     
     
             XmlNodeList userList = userXml1.GetElementsByTagName ("user");
     
             foreach(XmlNode userValue in userList)
             {
                 XmlNodeList userContent = userValue.ChildNodes;
                 objUser = new Dictionary<string, string>();
     
                 foreach(XmlNode value in userContent)
                 {
                     objUser.Add (value.Name, value.InnerText);
                 }
     
                 userFullDetails.Add (objUser);
     
                 userCountInXml = userList.Count;
     
                 userId = new string[userList.Count];
                 questionSetOfUser = new string[userList.Count];
             }
     
             AssignUserXmlValuesToArray ();
         }

于 2016-08-30T05:45:22.480 回答