Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

资源管理模块自动设置常驻包问题 #37

Open
bigbigfun opened this issue Nov 27, 2018 · 1 comment
Open

资源管理模块自动设置常驻包问题 #37

bigbigfun opened this issue Nov 27, 2018 · 1 comment

Comments

@bigbigfun
Copy link

实际测试发现:在AssetBundleManager Initialize()函数中自动根据依赖关系设置常驻包,循环的复杂度太高,实际上Bundle数量达到一定量(我们在研项目的Bundle量就会卡死,大约350M大小,粒度比较小)就卡死了,可以优化成O(n)的复杂度,不过我这里直接在打Bundle之前提前统计好存了下来

这段代码有问题:
foreach (var curAssetbundleName in allAssetbundleNames)
{
if (string.IsNullOrEmpty(curAssetbundleName))
{
continue;
}

            int count = 0;
            foreach (var checkAssetbundle in allAssetbundleNames)
            {
                if (checkAssetbundle == curAssetbundleName || string.IsNullOrEmpty(checkAssetbundle))
                {
                    continue;
                }

                var allDependencies = manifest.GetAllDependencies(checkAssetbundle);
                if (Array.IndexOf(allDependencies, curAssetbundleName) >= 0)
                {
                    count++;
                    if (count >= 2)
                    {
                        break;
                    }
                }
            }

            // 说明:设置被依赖数量为1的AB包为常驻包的理由详细情况见AssetBundleAsyncLoader.cs那一大堆注释
            // TODO:1)目前已知Unity5.3版本和Unity5.5版本没问题,其它试过的几个版本都有问题,如果你使用的版本也有问题,需要修改这里的宏
            //       2)整套AB包括压缩格式可能都要重新设计,这个以后有时间再去尝试

#if !UNITY_5_3 && !UNITY_5_5
if (count >= 1)
#else
if (count >= 2)
#endif
{
// SetAssetBundleResident(curAssetbundleName, true);
}
}

@smilehao
Copy link
Owner

smilehao commented Jan 9, 2019

的确,在在打Bundle之前提前统计好时个不错的点子~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants