示例#1
0
 private void openWindow(UIWin win, Action <object> onClose, params object[] args)
 {
     if (win.eLayer == EUILayer.Normal)
     {
         OpenNormalWin(win, onClose, args);
     }
     //play animation
     win.gameObject.SetActive(true);
     win.Open(onClose, args);
     CheckBack();
 }
示例#2
0
文件: UIManager.cs 项目: hjj0416/Demo
    /// <summary>
    /// 加载prefab,创建uiwin,绑定gameobject、config
    /// </summary>
    /// <param name="winName"></param>
    /// <param name="cb"></param>
    public void LoadUI(string winName, object data = null, Action <UIWin> cb = null)
    {
        string     prefabPath = string.Format("{0}/{1}", PathDefine.DIR_UI_PREFAB, winName);
        GameObject prefab     = Resources.Load <GameObject>(prefabPath);

        if (prefab == null)
        {
            Debug.LogError("prefab is null : " + prefabPath);
            if (cb != null)
            {
                cb(null);
            }
            return;
        }
        GameObject uiObject = Instantiate(prefab);

        uiObject.name = winName;
        UIWin win = uiObject.GetComponent <UIWin>();

        if (win == null)
        {
            Debug.LogError("prefab should add UIWin script");
            if (cb != null)
            {
                cb(null);
            }
            return;
        }
        Transform winTrans = uiObject.transform;

        uiObject.SetActive(true);
        Transform parent = GetParent(win);

        if (parent == null)
        {
            Debug.LogError("parent is null");
            if (cb != null)
            {
                cb(null);
            }
            return;
        }
        winTrans.SetParent(parent);
        RectTransform rect = winTrans as RectTransform;

        if (rect != null)
        {
            if (rect.anchorMin == rect.anchorMax)
            {
                rect.anchoredPosition = Vector2.zero;
            }
            else
            {
                rect.offsetMin = Vector2.zero;
                rect.offsetMax = Vector2.zero;
            }
            rect.localPosition = Vector3.zero;
            rect.localScale    = Vector3.one;
            rect.SetAsLastSibling();
        }
        win.Open(data);
        if (cb != null)
        {
            cb(win);
        }
    }
示例#3
0
    public UIWin OpenWindow(WinID winID, Action <object> onClose = null, params object[] args)
    {
        try {
            if (winID >= WinID.Unsupported)
            {
                //UITipManager.Instance().ShowTip(11102);
                return(null);
            }

            UIWin win = getUI(winID);
            if (win)
            {
                if (win.ReOpenable || !IsOpen(winID))
                {
                    if (win.type == UIType.Update)
                    {
                        if (win.CloseType == UIWin.eCloseType.CloseOthers)
                        {
                            CloseAll();
                        }
                        else
                        {
                            int count = (int)win.CloseType;
                            if (count > 0)
                            {
                                for (int index = 0; index < count; ++index)
                                {
                                    LinkedListNode <UIWin> last = openWins.Last;
                                    if (last == null || last.Value.type == UIType.Main)
                                    {
                                        continue;
                                    }
                                    last.Value.gameObject.SetActive(false);
                                    last.Value.Close(null);
                                }
                            }
                        }
                    }
                    if (openWins.Contains(win))
                    {
                        openWins.Remove(win);
                    }
                    if (win.type == UIType.Main)
                    {
                        openWins.AddFirst(win);
                    }
                    else
                    {
                        openWins.AddLast(win);
                    }
                    int i = 0;
                    foreach (UIWin temp in openWins)
                    {
                        if (temp && temp.type != UIType.Main)
                        {
                            temp.transform.localPosition = new Vector3(temp.transform.localPosition.x, temp.transform.localPosition.y, i * -zInterval); //
                            UIPanel[]      tempPanel = temp.GetComponentsInChildren <UIPanel>(true);
                            List <UIPanel> tempList  = new List <UIPanel>();
                            for (int j = 0; j < tempPanel.Length; j++)
                            {
                                tempList.Add(tempPanel[j]);
                            }
                            tempList.Sort((a, b) => a.depth.CompareTo(b.depth));
                            for (int k = 0; k < tempList.Count; k++)
                            {
                                tempList[k].depth = i * depthInterval + k;
                                NowMaxDepth       = tempList[k].depth + 1;
                            }

                            if (temp && temp.ID == WinID.JL_UIMainEvent)
                            {
                                temp.GetComponent <UIPanel>().depth = -1;
                            }
                            i++;
                        }
                    }

                    win.Open(onClose, args);
                    if (winAction != null && win.type != UIType.Main)
                    {
                        if (win.backdrop)
                        {
                            winAction(win.transform);
                        }
                        else
                        {
                            winAction(null);
                        }
                    }

                    //foreach (UIWin temp in openWins)
                    //{
                    //    int Num = openWins.Count;
                    //    bool a = temp.transform.gameObject.activeSelf;
                    //    string Name = temp.transform.gameObject.name;
                    //    Debug.LogError("====Num:::" + Num + "====IsActive:::" + a + "====Name:::" + Name);
                    //}
                }
            }
            return(win);
        } catch (System.Exception ex) {
            Debug.LogException(ex);
            return(null);
        }
    }