コード例 #1
0
    /// <summary>
    /// 添加一个显示的ui
    /// </summary>
    /// <param name="ui"></param>
    /// <param name="layer"></param>
    public void Add(UIPanel ui, UiLayer layer)
    {
        if (ui != null && uiDic.ContainsKey(layer) && (!uiDic[layer].Contains(ui)))
        {
            uiDic[layer].Add(ui);
            if (layerDic.ContainsKey(ui))
            {
                LoggerManager.Instance.Warn("Layer dictionary contained ui nameed {0}", ui.name);
            }
            else
            {
                layerDic.Add(ui, layer);
            }
            ui.transform.SetAsLastSibling();

            LayerData layerData = layerDataDic[layer];
            if (uiDic[layer].Count > 1) // 一层2个Ui的深度初始化
            {
                ui.depth = uiDic[layer][uiDic[layer].Count - 2].depth + layerData.space;
                if (ui.depth >= layerData.endDepth)
                {
                    AutoResetDepth(layer);
                }
            }
            else
            {
                ui.depth = layerData.startDepth; // 一层1个Ui的深度初始化
            }

            ResetPanelsDepthInPanel(ui.transform, ui.depth);
            ResetUiModelBackgroundDepth(ui, ui.depth);

            List <UIPanel> panelListInLayer = uiDic[layer];
            int            count            = panelListInLayer.Count;
            if (count >= 2)
            {
                BaseUi baseUi = GetBaseUiByPanel(panelListInLayer[count - 2]);
                if (baseUi != null)
                {
                    baseUi.Overlaid(); // 被覆盖的Ui进行覆盖操作
                }
            }
        }
    }