Esempio n. 1
0
 public void OpenPanel(PanelBase panelBase, UIPanelID id, OpenPanelType forParentType, bool waitAni)
 {
     if (!isInitEnd)
     {
         return;
     }
     if (mUIPanelConfigDic.ContainsKey(id))
     {
         if (mUIPanelPoolDic.ContainsKey(id))
         {
             mUIPanelPoolDic[id].OpenPanel(panelBase, id, forParentType, waitAni);
             runPanelBaseList.Add(mUIPanelPoolDic[id]);
         }
         else
         {
             var data = new UILoadderData
             {
                 id = id,
                 //config = mUIPanelConfigDic[id],
                 parentPanel   = panelBase,
                 forParentType = forParentType,
                 waitAni       = waitAni
             };
             UIResManager.Instance.LoadAsset(mUIPanelConfigDic[id].prefabName, UILoadCallBack, data);
         }
     }
     else
     {
         if (GMManager.IsInEditor)
         {
             Debug.LogError("mUIPanelConfigDic 不存在 id:" + id);
         }
     }
 }
Esempio n. 2
0
 public static string getUIPrefabPath(UIPanelID id)
 {
     if (prefabPathDict.ContainsKey(id))
     {
         return(prefabPathDict[id]);
     }
     return(null);
 }
Esempio n. 3
0
    public void ShowUIPanel(UIPanelID id)
    {
        //1:判断是否是已显示的UI面板
        if (showedUIPanelDict.ContainsKey(id))//当前UI已经在显示列表中了,就直接返回
        {
            return;
        }

        //2:判断此面板是否已创建,没有则加载 预置体,创建面板,显示+管理起来

        //通过ID获取需要显示的UI,从 AllUIdict 容器中获取(打开过的面板,会在 AllUIdict 引用)
        UIBasePanel tmpUIPanel = GetUIPanelFromAllDict(id);

        if (tmpUIPanel == null)                                   //如果在容器中没有此UI,就从资源中读取ui预制体,并创建
        {
            string prefabPath = UIPrefabPath.getUIPrefabPath(id); //通过ID,获取对应的路径

            if (!string.IsNullOrEmpty(prefabPath))
            {
                GameObject prefab = Resources.Load <GameObject>(prefabPath);          //加载资源

                if (prefab != null)                                                   //资源加载成功
                {
                    GameObject goWillShowUIPanelObj = GameObject.Instantiate(prefab); //克隆游戏对象到层次面板上

                    tmpUIPanel = goWillShowUIPanelObj.GetComponent <UIBasePanel>();   //获取此对象上的UI

                    prefab = null;
                }
                else
                {
                    Debug.LogError("资源" + prefabPath + "不存在");
                }
            }
        }

        //3:更新显示其它的UI
        UpdateOtherUIPanelState(tmpUIPanel);

        // 将创建的新的UIPanel添加到字典中(如果有,就等于无此操作)
        allUIPanelDict[id]    = tmpUIPanel;
        showedUIPanelDict[id] = tmpUIPanel;

        //  改变当前的显示层级,放在外面更加灵活,可能会修改面板的显示层级
        if (tmpUIPanel != null)
        {
            Transform root = GetRootNodeOfPanel(tmpUIPanel);//获取UI所对应的根节点

            //放入根节点下面
            UIUtils.addChildToParent(root, tmpUIPanel.transform);//放入根节点下面
        }

        //4:显示当前UI
        tmpUIPanel.Show();

        curDisplayUIPanel = tmpUIPanel;
    }
Esempio n. 4
0
 private UIBasePanel GetUIPanelFromShowedDict(UIPanelID id)
 {
     if (showedUIPanelDict.ContainsKey(id))
     {
         return(showedUIPanelDict[id]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 5
0
 private UIBasePanel GetUIPanelFromAllDict(UIPanelID id)
 {
     if (allUIPanelDict.ContainsKey(id))
     {
         return(allUIPanelDict[id]);
     }
     else
     {
         return(null);
     }
 }
Esempio n. 6
0
    private void AddConfig(UIPanelID id, string prefabName, string scriptName)
    {
        if (mUIPanelConfigDic.ContainsKey(id))
        {
            if (GMManager.IsInEditor)
            {
                Debug.LogError("重复的UIPanelID " + id);
            }
            return;
        }

        mUIPanelConfigDic.Add(id, new UIPanelConfig(prefabName, scriptName));
    }
Esempio n. 7
0
    public void HideUIPanel(UIPanelID id)
    {
        var tmpUIPanel = GetUIPanelFromShowedDict(id);

        if (tmpUIPanel != null)
        {
            showedUIPanelDict.Remove(id);
            tmpUIPanel.Hide();
        }
        else
        {
            Debug.LogError(id + "没有显示,无法隐藏");
            return;
        }
    }
Esempio n. 8
0
    /// <summary>
    /// 隐藏面板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public void HidePanel <T>() where T : UIPanelBase
    {
        UIPanelID id = (UIPanelID)System.Enum.Parse(typeof(UIPanelID), typeof(T).ToString());

        if (!panelDict.ContainsKey(id))
        {
            return;
        }
        if (!panelDict[id].isShow)
        {
            return;
        }
        panelDict[id].OnHide();
        panelDict[id].isShow = false;
        panelDict[id].skin.SetActive(false);
    }
Esempio n. 9
0
    //UIManager只负责面板的加载、显示与隐藏,其他面板方法由对应Controller调用

    /// <summary>
    /// 显示面板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="args"></param>
    public void ShowPanel <T>(params object[] args) where T : UIPanelBase
    {
        UIPanelID id = (UIPanelID)System.Enum.Parse(typeof(UIPanelID), typeof(T).ToString());

        //如果该面板没被加载过,则加载
        if (!panelDict.ContainsKey(id))
        {
            LoadPanel <T>();
        }
        //如果该面板正显示着,则不理
        if (panelDict[id].isShow)
        {
            return;
        }
        panelDict[id].skin.SetActive(true);
        panelDict[id].isShow = true;
        panelDict[id].OnShow(args);
    }
Esempio n. 10
0
 public T Get <T>(UIPanelID id) where T : UIPanel
 {
     if (_registeredPanels.ContainsKey(id))
     {
         if (_registeredPanels[id] is T)
         {
             return(_registeredPanels[id] as T);
         }
         else
         {
             Debug.LogError("UIPanel mathcing ID '" + id.ToString() + "' is not of type '" + typeof(T).ToString() + "'.");
         }
     }
     else
     {
         Debug.LogError("No UIPanel with id '" + id.ToString() + "' registered with UIManager.");
     }
     return(null);
 }
Esempio n. 11
0
    public void OpenPanel(PanelBase parent, UIPanelID id, OpenPanelType forParentType, bool waitAni)
    {
        Reset();

        panelID = id;

        SetParentPanel(parent);

        if (parent == null)
        {
            ShowPanel(forParentType);
            return;
        }

        if (waitAni)
        {
            parent.AddQuitAniCallBack(() => ShowPanel(forParentType));
        }
    }
Esempio n. 12
0
    /// <summary>
    /// 加载面板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    private void LoadPanel <T>() where T : UIPanelBase
    {
        UIPanelID   id    = (UIPanelID)System.Enum.Parse(typeof(UIPanelID), typeof(T).ToString());
        UIPanelBase panel = System.Activator.CreateInstance(typeof(T)) as UIPanelBase;

        panelDict.Add(id, panel);
        //加载皮肤
        string     skinPath = panel.skinPath;
        GameObject skin     = ResourcesManager.Instance.LoadPrefab(skinPath);

        if (skin == null)
        {
            Debug.LogError("找不到路径" + skinPath + "的面板");
        }
        panel.skin = GameObject.Instantiate(skin);
        //设置父物体
        panel.skin.transform.SetParent(layerDict[panel.layer], false);
        //初始化,获取控件
        panel.OnLoad();
    }
Esempio n. 13
0
 public bool IsRegistered(UIPanelID id)
 {
     return(_registeredPanels.ContainsKey(id));
 }
Esempio n. 14
0
    void onInit()
    {
        DontDestroyOnLoad(this.gameObject);//场景切换时,不销毁脚本所在的对象

        if (allUIPanelDict != null)
        {
            allUIPanelDict.Clear();
        }
        if (showedUIPanelDict != null)
        {
            showedUIPanelDict.Clear();
        }

        //Canvas下保持显示始终在前 的根节点
        if (transUIRootForKeepAbove == null)
        {
            transUIRootForKeepAbove = new GameObject("UIRootForKeepAbove").transform;
            UIUtils.addChildToParent(transUIRoot, transUIRootForKeepAbove);//把此对象放在父对象下面
        }

        //Canvas下普通UI元素的 根节点
        if (transUIRootForNormal == null)
        {
            transUIRootForNormal = new GameObject("UIRootForNormal").transform;
            UIUtils.addChildToParent(transUIRoot, transUIRootForNormal);
        }

        //来缓冲对象, panel对象创建后就会直接出现在场景中
        foreach (var tmp in UIPrefabPath.prefabPathDict)
        {
            UIPanelID id         = tmp.Key;
            string    prefabPath = tmp.Value;

            if (!string.IsNullOrEmpty(prefabPath))
            {
                GameObject prefab = Resources.Load <GameObject>(prefabPath); //加载资源

                if (prefab != null)                                          //资源加载成功
                {
                    GameObject storedUIPanelObj = GameObject.Instantiate(prefab);
                    storedUIPanelObj.SetActive(false);

                    UIBasePanel uiPanel = storedUIPanelObj.GetComponent <UIBasePanel>();//获取此对象上的UI
                    allUIPanelDict.Add(id, uiPanel);

                    if (uiPanel != null)
                    {
                        Transform root = getRootNodeOfPanel(uiPanel);//获取UI所对应的根节点

                        //放入根节点下面
                        UIUtils.addChildToParent(root, storedUIPanelObj.transform); //放入根节点下面

                        prefab = null;                                              //清空预制体对象
                    }
                }
            }
            else
            {
                Debug.LogError("资源" + prefabPath + "不存在");
            }
        }

        //默认显示
        showUIPanel(UIPanelID.ID_LoginPanel);//显示主界面UI
    }
Esempio n. 15
0
 public DTUIPanel(UIPanelID _id, string _name, string _path)
 {
     this.PanelId   = _id;
     this.PanelName = _name;
     this.PanelPath = _path;
 }