1. 程式人生 > >解決Unity 中WWW載入 AssetBundle---中文路徑

解決Unity 中WWW載入 AssetBundle---中文路徑

今天在 寫 檔案的時候遇到一個坑,

www 載入檔案,不能支援中路徑,

我了個去~

恰好我的persistPath 是中文的!

我去!

然後找到這麼一個解決方法:

using UnityEngine;  
using System.Collections;  
using System.IO;  
public class LoadAsset : MonoBehaviour {  
    
    AssetBundleCreateRequest asset;//定義一個資源包建立請求  
 IEnumerator LoadAssetBundle()  
    {  
           
        FileStream AssetIO = new FileStream(Application.dataPath + @"/StreamingAssets/好孩子/001.dat", FileMode.Open, FileAccess.ReadWrite); //建立檔案流(物件現含有中文)      
        byte[] assetbytes = new byte[AssetIO.Length];  
        AssetIO.Read(assetbytes, 0, (int)AssetIO.Length);  
        AssetIO.Close();  
    
        asset = AssetBundle.CreateFromMemory(assetbytes);//從記憶體中建立資源          
        yield return asset;  
           
        AssetBundle LoadAsset = asset.assetBundle;//這樣就能得到我們需要的資源包了  
        if (asset.isDone)  
          {  
          Instantiate(LoadAsset.Load("Test_001"));        
          }  
    }