Unity 中WWW加载 AssetBundle---中文路径

因为FileStream是允许中文路径的,可以先通过文件流把AssetBundle读取到内存,在通过CreateFromMemory 创建AssetBundle资源,这样的话就避开了WWW不能加载中文路径的问题。

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

原文点击这里

你可能感兴趣的:(Unity)