做项目时,用到NGUI,出现了很多警告如下:“You can't place widgets on a layer different than the UIPanel that manages them.",而且越来越多,拖慢性能。
点开警告,代码如下:
/// <summary>
/// Check to ensure that the widget resides on the same layer as its panel.
/// </summary>
public void CheckLayer ()
{
if (panel != null && panel.gameObject.layer != gameObject.layer)
{
Debug.LogWarning("You can't place widgets on a layer different than the UIPanel that manages them.\n" +
"If you want to move widgets to a different layer, parent them to a new panel instead.", this);
gameObject.layer = panel.gameObject.layer;
}
}
代码里写的很清楚,就是ui里父对象与子对象的layer不同,会把所有layer转换为一致,这样会是性能变低所以指定为同一层就可以解决
。