NGUIでのレイヤー管理
NGUI2.7のUIPanel下にGameObjectを追加してUIPanelとは別のLayerを設定しても、実行時に警告ログを出力しつつUIPanelのLayerで上書きされてしまいます
You can't place widgets on a layer different than the UIPanel that manages them.
If you want to move widgets to a different layer, parent them to a new panel instead.
NGUIを使ってゲームっぽいものを作ろうとした時に、UIPanel下のレイヤーが全て統一されてしまうと少し不便です
レイヤー毎にUIPanelを作成する
警告ログで指示されている通りに解決します
- Anchor下にUIPanelを追加する(NGUI > Create a Panel)
- 追加したUIPanelのLayerを設定する
- (追加したUIPanel下に必要なGameObjectを追加する)
- (追加したGameObjectのLayerは実行時に2.で設定したLayerで上書きされる)
- 複数のUIPanelを同時に写し撮るため、CameraのCulling MaskでそれぞれのUIPanelに設定したLayerを選択する
- UICameraのEvent Receiver Maskも5.と同様にLayerを選択する
NGUIのソースコードを改変してレイヤーを上書きさせない
お薦めできない力技ですので自己責任において
- UIwidget.csの342行目をコメントアウト
-
public void CheckLayer ()
{
if (mPanel != null && mPanel.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 = mPanel.gameObject.layer;
}
}