示例#1
0
    protected override void Awake()
    {
        base.Awake();
        if (_uiRootTrans == null)
        {
            //_uiRootTrans = Instantiate(Resources.Load<Transform>("Prefabs/UI/Canvas"));
            _uiRootTrans = GameObject.Find("Canvas").transform;
            DontDestroyOnLoad(_uiRootTrans);
        }
        _dicAllUI         = new Dictionary <EUiId, BaseView>();
        _dicShownUI       = new Dictionary <EUiId, BaseView>();
        _stackReturnInfor = new Stack <UIReturnInfor>();

        _normalUIRoot = new GameObject("NormalUIRoot").transform;
        GlobalTools.AddChildToParent(_uiRootTrans, _normalUIRoot);
        GlobalTools.SetLayer(_uiRootTrans.gameObject.layer, _normalUIRoot);

        _keepAboveUIRoot = new GameObject("KeepAboveUIRoot").transform;
        GlobalTools.AddChildToParent(_uiRootTrans, _keepAboveUIRoot);
        GlobalTools.SetLayer(_uiRootTrans.gameObject.layer, _keepAboveUIRoot);

        _topUIRoot = new GameObject("TopUIRoot").transform;
        GlobalTools.AddChildToParent(_uiRootTrans, _topUIRoot);
        GlobalTools.SetLayer(_uiRootTrans.gameObject.layer, _topUIRoot);
    }
示例#2
0
    public BaseView JudgeShowUI(EUiId uiId)
    {
        //First、FirstOrDefault的区别在于:当没有元素满足条件时,一个抛出异常,一个返回默认值。
        BaseView baseUI = _dicAllUI.FirstOrDefault(t => t.Key == uiId).Value;

        //如果baseui在字典里面没有查找到,说明该窗体还没有加载过
        if (baseUI == null)
        {
            Type     type  = Type.GetType(uiId.ToString());
            BaseView theUI = Instantiate(Resources.Load <GameObject>("Prefabs/UI/" + uiId.ToString())).AddComponent(type) as BaseView;
            if (theUI != null)
            {
                Transform theRoot = GetUIRoot(theUI);
                GlobalTools.AddChildToParent(theRoot, theUI.transform);
                _dicAllUI[uiId] = theUI;
                baseUI          = theUI;
            }
            else
            {
                Debug.LogError("Load UI Null");
            }
        }
        UpDateStack(baseUI);
        return(baseUI);
    }