///
///通过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