简体   繁体   English

在Unity3d(NGUI)中将预制件与面板之间的父级化

[英]Reparenting prefabs between to panels in Unity3d (NGUI)

Not sure this is the best forum for Unity3d/NGUI questions but give it a try... 不确定这是Unity3d / NGUI问题的最佳论坛,但请尝试一下...

I am trying to move a gameobject from a scrollable panel to a normal panel by reparenting it. 我试图通过重设它来将游戏对象从可滚动面板移动到普通面板。

firstGameObject.transform.parent = secondGameObject.transform;

firstGameObject is initially child of a clipped scrollable panel. firstGameObject最初是剪辑的可滚动面板的子级。 The transform seems to move just fine in the hierarchy and no longer becoming scrollable. 转换似乎在层次结构中移动得很好,并且不再变得可滚动。 But it is still clipped like it was a child of the clipped panel. 但是它仍然像被剪切面板的孩子一样被剪切。

Any ideas? 有任何想法吗?

Edit: Someone at NGUI's forum suggested calling Refresh() on both uipanels, but it had no effect. 编辑:NGUI论坛上的某人建议在两个uipanel上都调用Refresh(),但没有效果。 http://www.tasharen.com/forum/index.php?topic=1941.0 http://www.tasharen.com/forum/index.php?topic=1941.0

Finally got it working. 终于成功了。 The correct way was to call CheckParent() on each widget in the old panel after reparenting. 正确的方法是在重新设定父级后,在旧面板的每个小部件上调用CheckParent()。

UIPanel smallPanel = NGUITools.FindInParents<UIPanel>(firstGameObject);
List<UIWidget> list = new List<UIWidget>(smallPanel.widgets.buffer);

foreach (UIWidget widget in list)
{
    if (widget != null)
    {
        widget.CheckParent();
    }
}

Function CheckParent() is obsolete. 函数CheckParent()已过时。 Now you can use ParentHasChanged() on reparented UIWidget. 现在,您可以在父级UIWidget上使用ParentHasChanged()

It depends on what scroll bar are you using. 这取决于您使用的滚动条。 Setting new parent to prefab you only setting new local coordinate system to it. 设置新的父对象为预制件,您只需为其设置新的本地坐标系。 You saing that objects in this scroll bar are clipping. 您说此滚动条中的对象正在剪切。 So, there must be an array or list or something like that, storing your prefab and making some actions on your prefab. 因此,必须有一个数组或列表或类似的东西,存储您的预制件并在预制件上执行一些操作。 Or, there is some kind of mask, that hides ALL objects in specific area (I think that is your case). 或者,有某种遮罩,可将所有对象隐藏在特定区域中(我认为这是您的情况)。 In that case you should move your prefab out of mask's area. 在这种情况下,您应该将预制件移出遮罩区域。 If you don't need to change screen position, change only Z coordanate, so prefab will becom closer to camera, and out of mask area. 如果您不需要更改屏幕位置,则只需更改Z坐标,因此预制件将更靠近相机且不在遮罩区域内。

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

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