我正在统一实例化一个预制面板,并且我将其设置为另一个面板的父面板,如下所示:
GameObject notificationPanel = (GameObject) Resources.Load("NotificationWindow");
Text notificationText = notificationPanel.GetComponentInChildren<Text>();
if (notificationType == NotificationType.Warning)
{
notificationText.color = Color.red;
}
notificationText.text = text;
GameObject newNotificationWindow =
(GameObject) Instantiate(notificationPanel, new Vector3(0, 0, 0), Quaternion.identity);
newNotificationWindow.transform.SetParent(Settings.NotificationHolder.transform);
但是,当实例化它具有疯狂的大小时,父面板具有一个布局组,其内部具有固定大小的单元格,这为什么不影响它呢?新面板比我的屏幕大10倍左右。在层次结构视图中,新面板正确显示为父面板下的子面板。另外'z'位置在-3900为什么?
因此,在阅读了Unity文档:实例化UI元素之后,您要做的就是调用:
newNotificationWindow.transform.SetParent(Settings.NotificationHolder.transform, false);
“ false”代表worldPositionStays参数,它缩放UI。
让我知道这是否适合您。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句