예제 #1
0
    /// <summary>
    /// 同步加载窗口
    /// </summary>
    /// <param name="name">窗口名称</param>
    /// <returns></returns>
    public GameObject LoadWindow(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
            return(null);
        }
        name = name.ToLower();
        GameObject       go         = null;
        UIWindowViewBase windowBase = null;

        //如果窗口不存在 则
        if (!m_DicWindow.ContainsKey(name) || m_DicWindow[name] == null)
        {
            string windowName = string.Format("pan_{0}", name);
            string path       = string.Format("download/{0}/prefab/uiprefab/uiwindows/{1}.drb", ConstDefine.GAME_NAME, windowName);
            go                    = AssetBundleManager.Instance.LoadAssetBundle <GameObject>(path, windowName);
            go                    = UnityEngine.Object.Instantiate(go);
            windowBase            = go.GetComponent <UIWindowViewBase>();
            m_DicWindow[name]     = windowBase;
            windowBase.WindowName = name;
            Transform transParent = null;
            switch (windowBase.containerType)
            {
            case ContainerType.Center:
                transParent = UIViewManager.Instance.CurrentUIScene.Container_Center;
                break;

            case ContainerType.TopRight:
                transParent = UIViewManager.Instance.CurrentUIScene.Container_TopRight;
                break;

            case ContainerType.Left:
                transParent = UIViewManager.Instance.CurrentUIScene.Container_Left;
                break;
            }
            go.SetParent(transParent);
            go.GetComponent <RectTransform>().sizeDelta = Vector2.zero;
        }
        else
        {
            windowBase = m_DicWindow[name];
            go         = windowBase.gameObject;
            windowBase.Show();
        }
        LayerUIManager.Instance.SetLayer(go);
        StartShowWindow(windowBase, true);
        return(go);
    }
예제 #2
0
    /// <summary>
    /// 加载窗口
    /// </summary>
    /// <param name="name">窗口名称</param>
    /// <param name="onComplete">加载完毕回调</param>
    public void LoadWindowAsync(string name, Action <GameObject> onComplete)
    {
        if (string.IsNullOrEmpty(name))
        {
            return;
        }
        name = name.ToLower();
        if (!m_DicWindow.ContainsKey(name) || m_DicWindow[name] == null)
        {
            string windowName = string.Format("pan_{0}", name);
            string path       = string.Format("download/{0}/prefab/uiprefab/uiwindows/{1}.drb", ConstDefine.GAME_NAME, windowName);
            AssetBundleManager.Instance.LoadOrDownload(path, windowName, (GameObject go) =>
            {
                go = UnityEngine.Object.Instantiate(go);

                UIWindowViewBase windowBase = go.GetComponent <UIWindowViewBase>();
                if (windowBase == null)
                {
                    return;
                }

                m_DicWindow[name] = windowBase;

                windowBase.WindowName = name;
                Transform transParent = null;

                switch (windowBase.containerType)
                {
                case ContainerType.Center:
                    transParent = UIViewManager.Instance.CurrentUIScene.Container_Center;
                    break;

                case ContainerType.TopRight:
                    transParent = UIViewManager.Instance.CurrentUIScene.Container_TopRight;
                    break;

                case ContainerType.Left:
                    transParent = UIViewManager.Instance.CurrentUIScene.Container_Left;
                    break;
                }

                go.SetParent(transParent);
                go.GetComponent <RectTransform>().sizeDelta = Vector2.zero;
                //层级管理
                LayerUIManager.Instance.SetLayer(go);
                go.gameObject.SetActive(false);
                StartShowWindow(windowBase, true);
                if (onComplete != null)
                {
                    onComplete(go);
                }
            });
        }
        else
        {
            UIWindowViewBase windowBase = m_DicWindow[name];
            GameObject       go         = windowBase.gameObject;
            windowBase.Show();
            LayerUIManager.Instance.SetLayer(go);
            StartShowWindow(windowBase, true);
            if (onComplete != null)
            {
                onComplete(go);
            }
        }
    }