如果从脚本调用 MRTK 网格对象集合 UpdateCollection() 不起作用 [英] MRTK Grid Object Collection UpdateCollection() not working if called from script

查看:42
本文介绍了如果从脚本调用 MRTK 网格对象集合 UpdateCollection() 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 MRTK 的 GridObjectCollection 脚本来显示多个按钮.我正在通过脚本动态实例化按钮,并将它们作为 GridObjectCollection 游戏对象的子项放置.现在您可以通过 UpdateCollection() 函数更新集合.除以下情况外,一切都按预期工作:

I am using the GridObjectCollection Script from MRTK to display a number of buttons. I am instantiating the buttons dynamically through a script and place them as children of the GridObjectCollection GameObject. Now you can Update the collection through the UpdateCollection() function. Everything works as expected except the following case:

如果我想在同一个 GridObjectCollection 中显示一组不同的按钮,我会销毁集合的所有子项并像以前一样实例化新按钮并调用 UpdateCollection()功能.但是集合没有正确更新.旧按钮被破坏,新按钮被添加,但位置发生了变化.如果我单击检查器中的 UpdateCollection 按钮,则该集合会正确更新.

If i want to display a set of different buttons in the same GridObjectCollection, i destroy all children of the collection and instantiate the new buttons as before and call the UpdateCollection() function. But the collection is not updating properly. The old buttons were destroyed and the new added, but the placement is shifted. If i click the UpdateCollection button in inspector, the collection is correctly updated.

为什么 UpdateCollection() 在修改集合内容后没有按预期工作?

Why UpdateCollection() is not working as expected after modifying the content of the collection?

推荐答案

我刚刚解决了这个问题.如果集合在下一帧中更新,则更新按预期工作.所以我正在启动一个协程并在那里调用更新函数.

I just fixed the problem. If the collection is updated in the next frame, the update works as expected. So i am starting a Coroutine and call the update function there.

private IEnumerator InvokeUpdateCollection()
{
    yield return null;
    gridObjectCollection.UpdateCollection();
}

这篇关于如果从脚本调用 MRTK 网格对象集合 UpdateCollection() 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆