Exemple #1
0
        static public T GetWindow <T>() where T : UIWindowBase
        {
            Type         type   = typeof(T);
            UIWindowBase window = UIManager.Instance.GetWindow(type);

            if (window != null)
            {
                return(window as T);
            }

            return(null);
        }
Exemple #2
0
        public void CloseWindow(string uiName, bool bDestroy = false)
        {
            UIWindowBase wnd = GetWindow(uiName);

            if (wnd != null)
            {
                if (wnd.isExclusive)
                {
                    wnd.isExclusive = false;
                    _exclusiveObject.SetActive(false);
                }

                if (bDestroy)
                {
                    wnd.UnInit();
                    DelWindow(uiName);
                    GameObject.Destroy(wnd.gameObject);
                }
                else
                {
                    wnd.Hide();
                }
            }
        }
Exemple #3
0
 public void AddWindow(string uiName, UIWindowBase window)
 {
     _windowList[uiName] = window;
 }
Exemple #4
0
        public UIWindowBase OpenWindow(string uiName, Type uiType, bool bExclusive = false, bool bUseLua = false)
        {
            if (!bUseLua)
            {
                RegisterOneWindow(uiName, uiType);
            }

            UIWindowBase window = GetWindow(uiName);

            if (window == null)
            {
                GameObject         wndObject = null;
                UnityEngine.Object o         = ResourceManager.LoadPrefab($"Core/Res/UI/Prefab/{uiName}");
                if (o == null)
                {
                    string path = $"Game/{CoreEnv._Game}/Res/UI/Prefab/{uiName}";
                    wndObject = GameObject.Instantiate(ResourceManager.LoadPrefab(path) as GameObject);
                }
                else
                {
                    wndObject = GameObject.Instantiate(o) as GameObject;
                }

                wndObject.layer = LayerMask.NameToLayer("UI");

                if (!bUseLua)
                {
                    window = (UIWindowBase)wndObject.AddComponent(GetUIClassTypeByUIName(uiName));
                }
                else
                {
                    //window = (UIWindowBase)wndObject.AddComponent(typeof(LuaUIWindow));
                }
                window.rectTransform = wndObject.GetComponent <RectTransform>();

                if (bExclusive) // 独占
                {
                    window.isExclusive = bExclusive;
                    _exclusiveObject.SetActive(true);
                    window.rectTransform.SetParent(_exclusiveObject.transform);
                    _exclusiveObject.transform.SetAsLastSibling();
                }
                else
                {
                    window.rectTransform.SetParent(_canvas.gameObject.GetComponent <RectTransform>());
                }
                window.rectTransform.anchoredPosition3D = new Vector3(0.0f, 0.0f, 0.0f);    //将UI相对锚点的偏移置为空

                //if (window is LuaUIWindow)   //如果打开的UI选用LUA实现的版本,则需要在寻常的Init流程前先指定LUA脚本路径,以便初始化SLUA相关的组件。否则Init函数无法调用到对应Lua脚本的Init方法。
                //{
                //    (window as LuaUIWindow).UIName = uiName;
                //}
                window.Init();
                AddWindow(uiName, window);
            }

            window.transform.SetAsLastSibling();
            //UIStartLoading.Instance.transform.SetAsLastSibling();
            window.Show();

            return(window);
        }