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