Assetbundle加载中文路径方法FileStream

上篇文章 Unity教程之-Unity3d打包Assetbundle并加载,这篇我们来学习下利用FileStream在读取我们的AssetBundle数据文件,并解决unity WWW中文路径问题。下面开始,因为FileStream是允许中文路径的,可以先通过文件流把AssetBundle读取到内存,在通过CreateFromMemory 创建AssetBundle资源,这样的话就避开了WWW不能加载中文路径的问题。贴上代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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" ));
}
}

好了,本篇Unity3d教程到此结束!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值