- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常大型 3D 世界/环境
我分成了 1000 x 1000 米(1 公里)的方 block 。
制作了所有图 block 的 Assets 包,目前只有 5 个 Assets 包(预计会显着增长,可能在 1000 左右 Assets 包)。
public Vector3 tileSize;
public int maxDistance;
public MultipleAssetBundleLoader[] tiles;
void Start()
{
this.tiles = FindObjectsOfType<MultipleAssetBundleLoader>();
}
void DeactivateDistantTiles()
{
foreach (MultipleAssetBundleLoader tile in tiles)
{
Vector3 tilePosition = tile.gameObject.transform.position + (tileSize / 2f);
float xDistance = Mathf.Abs(tilePosition.x - playerPosition.x);
float zDistance = Mathf.Abs(tilePosition.z - playerPosition.z);
if (xDistance + zDistance > maxDistance)
{
tile.DestroyBundleObject();
//tile.SetActive(false);
}
else
{
tile.StartDownloadingAB();
}
}
}
void Update()
{
DeactivateDistantTiles();
}
StartDownloadingAB 函数只是从服务器或缓存中下载 Assets 包并实例化游戏对象,而 DestroyBundleObject 则停用加载包的游戏对象(如果可用)。以下是下载 Assets 包的代码片段:
public void StartDownloadingAB()
{
if (BundleLoadStatus == BundleLoadStatusEnum.bundleNotLoadedYet)
{
BundleLoadStatus = BundleLoadStatusEnum.bundlesLoading;
downloadABRef = StartCoroutine(DownloadAB());
}
else if (bundleObjectsDeactivated == true && BundleLoadStatus == BundleLoadStatusEnum.bundlesHasLoaded)
{
BundleObjectActive(true);
}
}
public IEnumerator DownloadAB()
{
if (isBundleLoading == true)
yield return false;
BundleLoadStatus = BundleLoadStatusEnum.bundlesLoading;
isBundleLoading = true;
//Debug.Log("loading " + url);
www = UnityWebRequestAssetBundle.GetAssetBundle(url);
yield return www.SendWebRequest();
if (www.error != null)
{
Debug.LogError("assetBundleURL : " + url);
Debug.LogError("www error : " + www.error);
www.Dispose();
www = null;
yield break;
}
AssetBundle bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;
GameObject bundlePrefab = null;
bundlePrefab = (GameObject)bundle.LoadAsset(bundle.name);
AssetBundleRequest bundlePrefabAsync = bundle.LoadAssetAsync(bundle.name, typeof(GameObject));
yield return bundlePrefab;
if (bundlePrefab != null)
{
//assetBundleToLoadObj = (GameObject)Instantiate(bundlePrefab);
assetBundleToLoadObj = Instantiate(bundlePrefabAsync.asset as GameObject);
assetBundleToLoadObj.transform.parent = envParent.transform;
floorL7MeshRenderer.enabled = false;
}
www.Dispose();
www = null;
// try to cleanup memory
Resources.UnloadUnusedAssets();
bundle.Unload(false);
//bundle = null;
isBundleLoading = false;
BundleLoadStatus = BundleLoadStatusEnum.bundlesHasLoaded;
}
对于销毁(实际上是停用对象,因为销毁是昂贵的功能) bundle 。
代码工作正常,我可以加载/卸载 Assets 包但问题是
它的性能不好(预计循环会增长)。
Webgl 有时会很长,而且它不是无缝或流畅运行的。
谁能帮我写出更高效、更优雅的方式来加载/卸载 Assets 包?
最佳答案
您应该首先查看分析器并查看您的应用程序的阻塞点,如果它卡在加载包(协程仍在主线程上运行并可能导致延迟),您可能需要使用 async loading .但是你会想提前调用那些(当玩家靠近另一个 block 时,所以当他真正到达 block 时它就准备好了)。如果您的瓶颈在其他地方,例如与渲染有关的事情,您可能会以其他方式处理它(具有较少顶点/三角形的较小 Assets 或更积极的剔除)。无论哪种方式,为了更好地判断,您都需要找到问题所在,但乍一看,似乎是在主线程上加载 Assets 才是问题所在。
关于c# - 使用 Assets 包在 unity webgl 中加载/卸载巨大的世界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55570170/
1.使用start-all.sh启动hadoop服务时,提示输入 您确定要继续连接吗(是/否) 当我通过脚本启动它时如何抑制这个提示,现在我正在使用期望模块,但我认为可能有一种更简单的方法来做到这一点
我安装了在 Ubuntu 12.04 下运行的 Geonode R 2.01。我尝试使用以下命令卸载它: sudo apt-get remove --purge geonode sudo apt-ge
假设我有 AppDomainA,它启动 AppDomainB。 AppDomainB 然后启动 AppDomainC。 如果在 AppDomainA 中卸载 AppDomainB,AppDomainC
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我尝试使用以下命令从我的 Ubuntu 中卸载 NGinX: sudo apt-get remove nginx-core nginx-full nginx-light nginx-extras n
我已经从 /Applications/ 中删除了 MacVim目录,但当我输入 vim 时在终端中显示错误:no such file or directory: /Applications/MacVi
我的页面中有一个 iframe,该 iframe 嵌入了一个不在我的服务器上的网站。 我正在寻找一种在 iframe 重定向之前触发函数的方法。例如,当用户单击 iframe 内的链接并且 ifram
看来我被 Visual Studio 的 Atomineer Pro 文档加载项挟持了!试用期结束了,我没有用了!但现在每次我在 Visual Studio 中做某事时,我都会收到一条错误消息并发送到
我有一个使用 WiX 完成的安装程序。安装完成后,它会启动一个应用程序,在 Explorer 进程中注入(inject)一些代码。 目前,当我卸载时,重新启动管理器会启动并关闭我的应用程序和资源管理器
在我的网络应用中,我需要在用户离开页面之前发送他们更改的最新数据。 我在页面卸载时调用这样的函数: window.onbeforeunload=sendData; 这就是函数内部调用的内容 funct
我使用 jQuery 和 history.js 来管理部分页面之间的动态转换;这样我就可以避免重新加载整个文档。其中一些部分页面调用自己独特的 javascript 文件。虽然页面之间的转换运行良好,
我需要处理应用程序包的变化,我这样写我的 mainfest mainfest.xml 我的接收器类
我目前在使用大量内存方面遇到了麻烦,我正在尽一切努力削减和优化涉及内存的代码...目前我的游戏的大部分 Nib 文件都加载了所有它在 ViewDidLoad 中的变量,现在我的问题是,在我的 view
如何从系统中删除 composer Php Dependecny Manager? 它说卸载无法继续,因为以下应用程序正在使用需要删除的文件。 Windows 资源管理器 最佳答案 我遇到了同样的问题
所以我使用 stow 在服务器上安装了 Python 2.7.1 源代码 .我过去很粗心,在处理源代码安装时我试图保持井井有条。所以,输入 stow。现在我使用 wget 安装了 easy_insta
有谁知道如何卸载 MacRuby?我在使用 RubyCocoa 然后决定试用 MacRuby,在安装 MacRuby 之后,RubyCocoa 已经停止工作。所以我想删除 MacRuby,但我找不到任
我无法从 64 位 EC2 卸载 mongo。在/usr/bin 我有 mongo 和 mongod 等等。当我从任何地方键入 mongo 时,它会在 1.8 版打开 shell。我现在下载了 2.0
本文实例讲述了Android编程实现监控apk安装,卸载,替换的方法。分享给大家供大家参考,具体如下: ?
1说明 mysql++是mysql开发团队为OO编程提供的C++开发库,是对mysql提供的底层数据存取API进行的C++封装,用其手册上的说法是:复杂而又庞大,当然功能也更强大。 Mysql+
自从我开始建立我的网站那天起,我安装了很多包,有时是为了测试一堆代码,有时是为了项目本身(后来我发现这不是需要的包)。但是现在,当我运行 pip freeze 时,我有一个包列表,我很难卸载不使用的包
我是一名优秀的程序员,十分优秀!