此问题已解决、
加载逻辑有问题,WWW 的并发太高导致通讯堵塞造成的、 修改加载逻辑,保证WWW的低并发就ok了
环境描述
因热更需求,项目4.x升级 5.x
Unity5.6 + windows
AssetBundle打包方式:
1、命名AssetBundleName:文件路径+文件名称+ .myBundle 后缀
Example: assets/resources/gui/tracktaskui.prefab.mybundle (总共有一万+ 个文件)
使用Unity5.x 最新打包函数
[MenuItem("Assetbundle/3_ExportBundle")]
static void ExportBundle() {
EditorUtility.DisplayCancelableProgressBar("ExportBundle", "", 0.5f);
// Choose the output path according to the build target.
string outputPath = Path.Combine("MyAssetBundles", GetPlatformName());
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
//@TODO: use append hash... (Make sure pipeline works correctly with it.)
BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget);
}
打包出来的资源路劲
file://F:/ThreeKingdom_5_6/ThreeKingdom185_temp1/Assets/../MyAssetBundles/Android/assets/resources/gui/tracktaskui.prefab.mybundle
首先、我会加载 Android(AssetBundle)
然后把依赖描述文件(Android.manifest)读取出来
private AssetBundle main_manifestBundle;
private AssetBundleManifest main_manifest;
public void Init() {
// 1.加载main_Manifest文件
path = GetBundlePath("Android");
if (File.Exists(path))
main_manifestBundle = AssetBundle.LoadFromFile(path);
else
Debug.LogError("file not found:" + path);
main_manifest = (AssetBundleManifest)main_manifestBundle.LoadAsset("AssetBundleManifest");
}
然后就是读取资源了 用www 从本地读取:
在原有框架上 直接改
LoadAsset、LoadUIAsset俩个函数,同时在项目配置中增加个bool 这样就不会干扰到原有逻辑 UseMyAssetBundle=true
public void LoadAsset(string prefab, Action
public void LoadUIAsset(string prefab, Action
private Dictionary loadingDic = new Dictionary();
private IEnumerator LoadMyAssetBundle(string prefab, Action
private IEnumerator LoadMyAssetBundleDepends(string prefab, Action
这个是调用LoginUI.prefab 的例子
public void ShowMogoLoginUI(Action callback, Action progress = null)
{
if (!UICanChange)
return;
//if (CurrentUI)
// CurrentUI.SetActive(false);
//CurrentUI = m_LoginUI;
//CurrentUI.SetActive(true);
//if (MogoMainCamera.instance)
// MogoMainCamera.instance.SetActive(false);
//m_camUI.clearFlags = CameraClearFlags.Depth;
//ShowBillboardList(false);
if (m_LoginUI == null)
{
if (!IsLoginUILoaded)
{
IsLoginUILoaded = true;
//CallWhenUILoad(0,false);
AssetCacheMgr.GetUIInstance("LoginUI.prefab",//LoginUI
(prefab, guid, go) =>
{
m_LoginUI = go as GameObject;
m_LoginUI.transform.parent = GameObject.Find("MogoMainUIPanel").transform;
m_LoginUI.transform.localPosition = new Vector3(1.25f, -52f, 0);
m_LoginUI.transform.localScale = new Vector3(1, 1, 1);
m_LoginUI.AddComponent();
if (CurrentUI != m_LoginUI)
{
if (CurrentUI != null)
{
ShowCurrentUI(false);
}
CurrentUI = m_LoginUI;
ShowCurrentUI(true);
m_camUI.clearFlags = CameraClearFlags.Depth;
//if (MogoMainCamera.instance)
// MogoMainCamera.instance.SetActive(false);
ShowBillboardList(false);
if (callback != null)
{
callback();
}
//MogoGlobleUIManager.Instance.ShowWaitingTip(false);
}
}, progress);
}
}
else
{
if (CurrentUI != m_LoginUI)
{
ShowCurrentUI(false);
CurrentUI = m_LoginUI;
ShowCurrentUI(true);
m_camUI.clearFlags = CameraClearFlags.Depth;
ShowBillboardList(false);
//if (MogoMainCamera.instance)
// MogoMainCamera.instance.SetActive(false);
if (callback != null)
{
callback();
}
}
}
}
那么现在问题出在 协程递归的地方