public IWindowBase GetUI(UGUI_TYPE uiType)
    {
        IWindowBase uiwindow;

        m_loadedWindow.TryGetValue(uiType, out uiwindow);
        return(uiwindow);
    }
    private IWindowBase CreateWindow(UGUI_TYPE uiType)
    {
        UIData uicfg = GetUIDataByUIType(uiType);

        if (uicfg == null)
        {
            Debug.LogErrorFormat("ui type {0} cfg is empty", uiType.ToString());
            return(null);
        }

        GameObject windowObj;

        Debug.LogError("prefa name " + uicfg.PrefabName);
        var prefab = Resources.Load <GameObject>(uicfg.PrefabName); //根据项目具体调整

        windowObj = GameObject.Instantiate(prefab, transform);

        if (windowObj == null)
        {
            Debug.LogErrorFormat("ui type {0} prefab is null", uiType.ToString());
            return(null);
        }
        windowObj.transform.position = Vector3.zero;

        Type scriptType = Type.GetType(uicfg.ScriptName);

        if (scriptType == null || scriptType.GetInterface("IWindowBase") == null)
        {
            Debug.LogErrorFormat("ui type {0} not have IWindowBase attach", uiType.ToString());
            return(null);
        }

        var scaler = windowObj.GetComponent <CanvasScaler>();

        if (scaler != null)
        {
            scaler.uiScaleMode         = CanvasScaler.ScaleMode.ScaleWithScreenSize;
            scaler.screenMatchMode     = CanvasScaler.ScreenMatchMode.Expand; //屏幕的适应方式
            scaler.referenceResolution = new Vector2(1280, 720);
        }

        IWindowBase   uiwindow = windowObj.AddComponent(scriptType) as IWindowBase;
        UIControlData ctrlData = windowObj.GetComponent <UIControlData>();

        if (ctrlData != null)
        {
            ctrlData.BindDataTo(uiwindow);
        }

        windowObj.SetActive(false);
        m_loadedWindow.Add(uiType, uiwindow);
        return(uiwindow);
    }
    private UIData GetUIDataByUIType(UGUI_TYPE uiType)
    {
        string uiName = uiType.ToString();
        var    Datas  = AssetDatabase.LoadAssetAtPath <UIConfig>(m_configPath);

        if (Datas != null)
        {
            for (int i = 0; i < Datas.UIDatas.Count; i++)
            {
                if (Datas.UIDatas[i].UIName == uiName)
                {
                    return(Datas.UIDatas[i]);
                }
            }
        }
        return(null);
    }
    public void ReleaseWindow(UGUI_TYPE uiType)
    {
        IWindowBase uiwindow = GetUI(uiType);

        if (uiwindow == null)
        {
            return;
        }
        if (uiwindow.Is3D())
        {
        }
        else
        {
            m_root2D.Release(uiwindow);
        }
        m_loadedWindow.Remove(uiType);
    }
    public IWindowBase Open(UGUI_TYPE uiType, UGUI_TYPE parentUIType = UGUI_TYPE._BEGIN)
    {
        IWindowBase uiwindow;

        m_loadedWindow.TryGetValue(uiType, out uiwindow);
        if (uiwindow == null)
        {
            uiwindow = CreateWindow(uiType);
            if (uiwindow == null)
            {
                return(null);
            }
            if (!uiwindow.Is3D())
            {
                m_root2D.Add(uiwindow);
            }
        }
        else
        {
            m_root2D.SortChildLayer(uiwindow); //还未销毁,就重新排序
        }

        uiwindow.Open();
        if (!uiwindow.Is3D())
        {
            UIBase2D uibase2D = uiwindow as UIBase2D;
            if (uibase2D.Getlayer() == UGUI_LAYER.MENU)
            {
                SetMainUIActive(false);
            }
        }
        HideMainCamera();
        if (parentUIType != UGUI_TYPE._BEGIN)
        {
            ParentUIStruct parentUI = new ParentUIStruct();
            parentUI.ParentUI = parentUIType;
            parentUI.ChildUI  = uiType;
            m_ParentUI.Push(parentUI);
        }
        return(uiwindow);
    }
    public void Close(UGUI_TYPE uiType, bool release = false)
    {
        IWindowBase uiwindow = GetUI(uiType);

        if (uiwindow == null)
        {
            return;
        }

        uiwindow.Close();
        if (release)
        {
            if (uiwindow.Is3D())
            {
            }
            else
            {
                m_root2D.Release(uiwindow);
            }
            m_loadedWindow.Remove(uiType);
        }

        if (!uiwindow.Is3D())
        {
            if (!CheckMenuLayerVisiable()) //如果没有全屏 的系统了,就打开mainUI
            {
                SetMainUIActive(true);
            }
        }

        if (m_ParentUI.Count > 0)
        {
            ParentUIStruct parentUI = m_ParentUI.Peek();
            if (parentUI.ChildUI == uiType)
            {
                Open(parentUI.ParentUI); //就是一个固定返回界面,一种父子的关系,尽量少用
                m_ParentUI.Pop();
            }
        }
    }