unity3D热更新——(2)Assetbundle资源更新部分

///
///通过tomcat服务器进行下载ab包

///

using System;
using System. Collections;
using System. Collections. Generic;
using System. IO;
using UnityEngine;

public class UpdateAssetBundles : MonoBehaviour
{
/// < summary >
/// 配表路径
/// </ summary >
List< string> mainPath;
/// < summary >
/// 配表信息
/// </ summary >
Dictionary< string, List< string>> tablePath;
/// < summary >
/// 进入游戏进行资产更新
/// </ summary >
public void FirstUpdateAB()
{
StartCoroutine( IEFirstUpdateAB());
}
IEnumerator IEFirstUpdateAB()
{
//进入游戏先检测persistent目录下是否有文件,没有则表示为第一次进游戏,
//需要将streaming目录下的文件拷贝到该目录下。
if (! Directory. Exists( AssetPath. persistentPath))
{
Debug. Log( "解压本地文件!(该步骤不需要流量)");
//注意,在Android中,StreamingAssets中的文件包含在一个.jar压缩文件(基本上与标准的zip为统一格式)中,所以只能用
//WWW读取,否则要使用第三方软件来读取,不能用C#的文件读取方法。
List< string> streamList = new List< string>();
yield return StartCoroutine( IECStomcat( AssetPath. streamingPath + "/" + IP. preloadedPath, streamList));
string tableStr = "";
for ( int i = 0; i < streamList. Count; i++)
{
tableStr += streamList[ i];
tableStr += Environment. NewLine;
string relativePath = "/" + streamList[ i]. Split( ';')[ 0];
yield return StartCoroutine( IEUpdateAssetBundle( Application. streamingAssetsPath + relativePath. Replace( ' \\ ', '/'), Application. persistentDataPath + relativePath. Replace( ' \\ ', '/')));
}
Debug. Log( "解压完成!");
CreadTextFile( AssetPath. persistentPath + "/" + IP. preloadedPath, tableStr);
yield return new WaitForSeconds( 0);
}
//获取主配表
Debug. Log( "获取服务器列表!(建议在WiFi下更新)");
mainPath = new List< string>();
yield return StartCoroutine( IECStomcat( IP. ResoucelsIP + AssetPath. _Android + "/" + IP. ResoucelsTablePath, mainPath));
Debug. Log( "检测是否需要更新!");
if ( mainPath != null)
{
tablePath = new Dictionary< string, List< string>>();
for ( int i = 0; i < mainPath. Count; i++)
{
List< string> list = new List< string>();
tablePath. Add( mainPath[ i], list);
yield
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值