Exemple #1
0
        //显示面板
        public T ShowPanel <T>(string planeName, UI_Layer layer = UI_Layer.Top)
            where T : CUIBase
        {
            CUIBase plane;

            if (!IsHavePanel(planeName))
            {
                GameObject obj = CResLoadMgr.Instance.LoadPrefab("Prefabs/UI", planeName);
                obj.name = planeName;
                //设置层级
                RectTransform tr = obj.transform as RectTransform;
                switch (layer)
                {
                case UI_Layer.Top: tr.SetParent(m_UITopLayer); break;

                case UI_Layer.Mid: tr.SetParent(m_UIMidLayer); break;

                case UI_Layer.Bot: tr.SetParent(m_UIBotLayer); break;
                }
                tr.localPosition = Vector3.zero;
                tr.localScale    = Vector3.one;
                tr.offsetMax     = Vector2.zero;
                tr.offsetMin     = Vector2.zero;
                plane            = obj.AddComponent <T>();
                m_UIPanelList.Add(planeName, plane);
                plane.gameObject.SetActive(true);
                return(plane as T);
            }
            plane = m_UIPanelList[planeName];
            plane.gameObject.SetActive(true);
            return(plane as T);
        }
Exemple #2
0
    /// <summary>
    /// 加载并显示面板
    /// </summary>
    /// <typeparam name="T">面板类型</typeparam>
    /// <param name="name">面板名</param>
    /// <param name="layer">层级</param>
    /// <param name="callback">回调函数</param>
    public void ShowPanel <T>(string name, UI_Layer layer = UI_Layer.Bottom, UnityAction <T> callback = null) where T : BasePanel
    {
        if (panelDic.ContainsKey(name))
        {
            callback?.Invoke(panelDic[name] as T);
            return;
        }
        resManager.LoadAsyn <GameObject>("UI/" + name, (gObj) =>
        {
            Transform parent = bottomTF;
            switch (layer)
            {
            case UI_Layer.Middle:
                parent = middleTF;
                break;

            case UI_Layer.Top:
                parent = topTF;
                break;

            case UI_Layer.System:
                parent = systemTF;
                break;
            }
            gObj.transform.SetParent(parent);
            gObj.transform.localPosition = Vector3.zero;
            gObj.transform.localScale    = Vector3.one;
            (gObj.transform as RectTransform).offsetMax = Vector3.zero;
            (gObj.transform as RectTransform).offsetMin = Vector3.zero;

            T panel = gObj.GetComponent <T>();
            callback?.Invoke(panel);
            panelDic.Add(name, panel);
        });
    }
Exemple #3
0
    public void MoveToLayer(int index)
    {
        //Check if there is a layer selected.
        if (selectedLayer.layerName != "")
        {
            //Disable the current layer's element holder object.
            selectedElement.outlineObject.SetActive(false);
            selectedLayer.layerObject.SetActive(false);
        }

        //Loop through the layer array.
        for (int i = 0; i < layers.Length; i++)
        {
            //Check if the layer index is matching.
            if (layers[i].layerIndex == index)
            {
                //Update the selected layer and its corresponding elements.
                selectedLayer = layers[i];
                selectedLayer.layerObject.SetActive(true);
                selectedElement = layers[i].firstElement;
                selectedElement.outlineObject.SetActive(true);
                break;
            }
        }

        //Reset the hold timer.
        executionInputHoldTimer = 0f;
    }
Exemple #4
0
    public void ShowPanel(string prefabpath, UI_Layer layer)
    {
        if (_panel.ContainsKey(prefabpath))
        {
            _panel[prefabpath].ShowMe();
            return;
        }
        GameObject obj    = GameObject.Instantiate(Resources.Load <GameObject>(prefabpath));
        Transform  parent = CanvasMgr.Instance.GetLayer(layer);

        // 设置父对象
        obj.transform.SetParent(parent);
        // 设置相对位置和大小
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localScale    = Vector3.one;

        RectTransform rectObj = obj.transform as RectTransform;

        rectObj.offsetMax = Vector2.zero;
        rectObj.offsetMin = Vector2.zero;

        // 得到面板脚本
        T panel = obj.GetComponent <T>();

        _panel.Add(prefabpath, panel);
    }
Exemple #5
0
    public void ShowPanel(string panelName, UI_Layer layer)
    {
        ResMgr.getInst().LoadAsync <GameObject>("UI/" + panelName, (obj) =>
        {
            Transform parent = bot;
            switch (layer)
            {
            case UI_Layer.Bot:
                parent = bot;
                break;

            case UI_Layer.Mid:
                parent = mid;
                break;

            case UI_Layer.Top:
                parent = top;
                break;

            case UI_Layer.System:
                parent = system;
                break;
            }

            //初始化设置面板位置
            obj.transform.SetParent(parent);
            obj.transform.localPosition = Vector3.zero;
            obj.transform.localScale    = Vector3.one;
            (obj.transform as RectTransform).offsetMax = Vector2.zero;
            (obj.transform as RectTransform).offsetMin = Vector2.zero;

            obj.GetComponent <BasePanel>().Show();
        });
    }
Exemple #6
0
    /// <summary>
    /// 将对象设置挂载在某层对象上
    /// </summary>
    /// <param name="obj">挂载对象</param>
    /// <param name="layer">层对象</param>
    public void SetParent(GameObject obj, UI_Layer layer)
    {
        Transform parent = GetLayer(layer);

        if (parent != null)
        {
            obj.transform.SetParent(parent);
        }
    }
Exemple #7
0
    /// <summary>
    /// 获取层对象
    /// </summary>
    /// <param name="layer"></param>
    /// <returns></returns>
    public Transform GetLayer(UI_Layer layer)
    {
        switch (layer)
        {
        case UI_Layer.BOT:
            return(bot);

        case UI_Layer.MID:
            return(mid);

        case UI_Layer.TOP:
            return(top);
        }
        return(null);
    }
Exemple #8
0
        /// <summary>
        /// 显示面板
        /// </summary>
        /// <typeparam name="T">面板类型</typeparam>
        /// <param name="PanelName">面板名</param>
        /// <param name="layer">面板应该显示在哪一层</param>
        /// <param name="callBack">面板创建成功后要执行的内容</param>
        public void ShowPanel <T>(string PanelName, UI_Layer layer = UI_Layer.Bottom, UnityAction <T> callBack = null) where T : BasePanel
        {
            switch (layer)
            {
            case UI_Layer.Bottom:
                if (CurrentBottomPanel != null)
                {
                    HidePanel(CurrentBottomPanel.gameObject.name);
                    CurrentBottomPanel = null;
                }
                break;

            case UI_Layer.Middle:
                if (CurrentMiddlePanel != null)
                {
                    HidePanel(CurrentMiddlePanel.gameObject.name);
                    CurrentMiddlePanel = null;
                }
                break;

            case UI_Layer.Top:
                if (CurrentTopPanel != null)
                {
                    HidePanel(CurrentTopPanel.gameObject.name);
                    CurrentTopPanel = null;
                }
                break;

            case UI_Layer.System:
                if (CurrentSystemPanel != null)
                {
                    HidePanel(CurrentSystemPanel.name);
                    CurrentSystemPanel = null;
                }
                break;

            default:
                break;
            }

            if (panelDic.ContainsKey(PanelName))
            {
                panelDic[PanelName].ShowPanel();
                callBack?.Invoke(panelDic[PanelName] as T);
                return;
            }
            else
            {
                ResMgr.I().LoadAsync <GameObject>("UI/" + PanelName, (obj) =>
                {
                    //将其移到Canvas中的各个层级之下
                    Transform father = Bottom;
                    switch (layer)
                    {
                    case UI_Layer.Bottom:
                        CurrentBottomPanel = obj;
                        break;

                    case UI_Layer.Middle:
                        CurrentMiddlePanel = obj;
                        father             = Middle;
                        break;

                    case UI_Layer.Top:
                        CurrentTopPanel = obj;
                        father          = Top;
                        break;

                    case UI_Layer.System:
                        CurrentSystemPanel = obj;
                        father             = System;
                        break;
                    }

                    //设置父对象
                    obj.transform.SetParent(father);

                    //设置其相对位置
                    obj.transform.localPosition = Vector3.zero;
                    obj.transform.localScale    = Vector3.one;

                    (obj.transform as RectTransform).offsetMax = Vector2.zero;
                    (obj.transform as RectTransform).offsetMin = Vector2.zero;

                    //得到预设体身上的BasePanel脚本
                    T panel    = obj.GetComponent <T>();
                    panel.name = PanelName;
                    panel.ShowPanel();
                    //将其添加到PanelDic中
                    panelDic.Add(PanelName, panel);
                    //处理面板创建完成后,要执行的方法
                    callBack?.Invoke(panel);
                });
            }
        }
Exemple #9
0
 //Lua显示面板
 public CUIBase LuaShowPanel(string planeName, UI_Layer layer = UI_Layer.Top)
 {
     return(ShowPanel <CUIBase>(planeName, layer));
 }