예제 #1
0
    public static WindowBase OpenSubWindow(int type, WindowBase parentWin, params System.Object[] args)
    {
        if (!WindowPrefabsInfo.ContainsKey(type) || m_self == null)
        {
                        #if UNITY_EDITOR
            Debug.LogError("OpenSubWindow,No such type window. TypeID = " + type);
                        #endif
            return(null);
        }

        if (parentWin == null)
        {
                        #if UNITY_EDITOR
            Debug.LogError("OpenSubWindow, must have a parent window");
                        #endif
            return(null);
        }

        //check if exist
        GameObject go    = null;
        WindowBase win   = null;
        int        exist = 0;
        for (int i = 0; i < m_self.m_subWindowGoList.Count; ++i)
        {
            WindowBase window = m_self.m_subWindowGoList[i];
            if (window.WinType == type && window.IsSingleton)
            {
                win   = window;
                go    = win.MainObject;
                exist = 1;
                if (win.ParentWindow == parentWin)
                {
                    go.SetActive(true);
                    return(win);
                }
                break;
            }
        }
        if (0 == exist)
        {
            for (int i = 0; i < m_self.m_windowGoList.Count; ++i)
            {
                WindowBase window = m_self.m_windowGoList[i];
                if (window.WinType == type && window.IsSingleton)
                {
                    win   = window;
                    go    = win.MainObject;
                    exist = 2;
                    break;
                }
            }
        }

        if (0 == exist)
        {
            for (int i = 0; i < m_self.m_windowGoBack.Count; ++i)
            {
                if (m_self.m_windowGoBack[i].WinType == type)
                {
                    win   = m_self.m_windowGoBack[i];
                    go    = win.MainObject;
                    exist = 3;
                    break;
                }
            }
        }

        if (0 == exist)
        {
            //find the resource(prefab) path
            PrefabInfo info = WindowPrefabsInfo[type];

            //intialize gameobject
            Assert.IsTrue(!info.IsInternal, "Not Impl With Bundle");

            if (!info.IsInternal)
            {
                AssetManager.LoadAssetFromResources(info.Path, typeof(GameObject), (AssetManager.Asset asset) =>
                {
                    if (asset.State == AssetManager.State.Loaded)
                    {
                        go = GameObject.Instantiate(asset.AssetObject) as GameObject;
                    }
                });
            }
        }

        go.SetActive(true);
        int depth = parentWin.GetSunWindowCount() + 1;
        go.transform.parent     = parentWin.CatchedTransform;
        go.transform.localScale = Vector3.one;
        //go.transform.localPosition = new Vector3(0,0,-depth);

        if (1 == exist)
        {
            //m_self.m_subWindowGoList.Remove(win);
            //m_self.m_subWindowGoList.Add(win);
        }
        else if (2 == exist)
        {
            m_self.m_windowGoList.Remove(win);
            m_self.m_subWindowGoList.Add(win);
        }
        else if (3 == exist)
        {
            m_self.m_windowGoBack.Remove(win);
            m_self.m_subWindowGoList.Add(win);
        }
        else
        {
            win = go.GetComponent <WindowBase>();
            if (win != null)
            {
                win.WinType = type;
                m_self.m_subWindowGoList.Add(win);
            }
            else
            {
                                #if UNITY_EDITOR
                Debug.LogError("OpenSubWindow: Can't find WindowBase at window root. WinObj = " + go.name);
                                #endif
                Destroy(go);
                return(null);
            }
        }

        if (win != null)
        {
            if (win.ParentWindow != null)
            {
                win.ParentWindow.RemoveSubWindow(win);
            }
            win.IsPreLoad = parentWin.IsPreLoad;
            if (!win.Started)
            {
                win.Init(args);
            }
            win.IsSubWindow = true;

            win.MainCanvas.sortingLayerID = LayerMask.GetMask("UI");
            win.MainCanvas.sortingOrder   = depth;
            parentWin.AddSubWindow(win);
            if (win.Started)
            {
                if (3 == exist && win.Closed)
                {
                    win.OnOpen(args);
                }

                if (!win.Actived)
                {
                    win.OnActive();
                }
            }
        }

        return(win);
    }