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;
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM