Unity读取StreamingAssets路径下的文件

    /// <summary>
    ///读取StreamingAssets中的文件 
    /// </summary>
    /// <param name="path">StreamingAssets下的文件路径</param>
    /// <returns>读取到的字符串</returns>
    public static string GetTextForStreamingAssets(string path)
    {
        string localPath = "";
        if (Application.platform == RuntimePlatform.Android)
        {
            localPath = Application.streamingAssetsPath + "/" + path;
        }
        else
        {
            localPath = "file:///" + Application.streamingAssetsPath + "/" + path;
        }

        WWW www = new WWW(localPath);

        if (www.error != null)
        {
            Debug.LogError("error while reading files : " + localPath);
            return ""; //读取文件出错
        }
        while (!www.isDone) { }
        Debug.Log("File content :  " + www.text);//www下面还有获取字节数组的属性
        return www.text;
    }
原文地址:https://www.cnblogs.com/ezhar/p/12899746.html