简体   繁体   English

如果从脚本调用 MRTK Grid Object Collection UpdateCollection() 不起作用

[英]MRTK Grid Object Collection UpdateCollection() not working if called from script

I am using the GridObjectCollection Script from MRTK to display a number of buttons.我正在使用 MRTK 中的GridObjectCollection脚本来显示许多按钮。 I am instantiating the buttons dynamically through a script and place them as children of the GridObjectCollection GameObject.我正在通过脚本动态实例化按钮并将它们放置为GridObjectCollection的子项。 Now you can Update the collection through the UpdateCollection() function.现在您可以通过UpdateCollection() function 更新集合。 Everything works as expected except the following case:除以下情况外,一切都按预期工作:

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.如果我想在同一个GridObjectCollection中显示一组不同的按钮,我会像以前一样销毁集合的所有子项并实例化新按钮并调用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?为什么修改集合内容后UpdateCollection()没有按预期工作?

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.所以我开始一个协程并在那里调用更新 function。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM