コード例 #1
0
ファイル: UIMgr.cs プロジェクト: mengtest/laughing-memory
    /// <summary>
    /// 打开一个UI
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    protected UIConfig OpenUI(UIID id)
    {
        IUICtrl  ctrl   = _register[id];
        UIConfig uiJson = JsonMgr.GetSingleton().GetUIConfigByID((int)id);

        if (uiJson == null)
        {
            return(null);
        }
        UIViewBase vb = ctrl.GetView();

        if (vb == null)
        {
            GameObject uigo = GameObject.Instantiate(ResourceMgr.Instance.LoadResource(uiJson.Resid) as GameObject);
            if (uigo == null)
            {
                throw new System.Exception("加载UI资源出错 -------- " + uiJson.Resid);
            }
            vb = uigo.GetComponent <UIViewBase>();

            ctrl.SetView(vb);
            ctrl.OnInit();
            vb.AddComponent(uiJson);
        }
        vb.SetOrder(++layerOrder[uiJson.Layer]);

        if (!ctrl.IsOpen())
        {
            vb.SetView(true);
            ctrl.OnOpen();
        }
        if (!openList.Contains(id))
        {
            if ((uiJson.Layer.Equals("UI1") || uiJson.Layer.Equals("Default")))
            {
                Debug.LogFormat("Add into OpenList {0}", id);
                openList.Add(id);
            }
        }
        else
        {
            //换到队尾
            openList.Remove(id);
            openList.Add(id);
        }
        return(uiJson);
    }