Пример #1
0
    private void ExecuteNavigationLogic(UIWindowBase baseWindow, ShowWindowData?showData)
    {
        UIWindowData windowData = baseWindow.windowData;

        if (baseWindow.IsNavigationWindow)
        {
            RefreshBackSequenceData(baseWindow);
        }
        else if (windowData.showMode == UIWindowShowMode.HideOtherWindow)
        {
            bool includeFixed = (showData == null ? true : showData.Value.hideAllOtherWindow);
            HideAllShownWindow(includeFixed);
        }

        // 强制清除窗口导航堆栈
        if (baseWindow.windowData.forceClearNavigation ||
            (showData != null && showData.Value.forceClearBackSeqData))
        {
            Debug.Log("<color=cyan>## [Enter the start window, reset the backSequenceData for the navigation system.]##</color>");
            ClearBackSequence();
        }
        else
        {
            if ((showData != null && showData.Value.checkNavigation))
            {
                CheckBackSequenceData(baseWindow);
            }
        }
    }
Пример #2
0
    private void RealShowWindow(UIWindowBase baseWindow, ShowWindowData?data = null)
    {
        object param = null;

        if (data != null)
        {
            ShowWindowData winData = data.Value;
            param = winData.param;
        }

        baseWindow.ShowWindow(param);
        showWindows [baseWindow.WindowID] = baseWindow;

        if (baseWindow.IsNavigationWindow)
        {
            lastShownWindow = curShownWindow;
            curShownWindow  = baseWindow;

            UIWindowData windowData = curShownWindow.windowData;
            if (lastShownWindow != null && lastShownWindow != curShownWindow && !windowData.forceClearNavigation)
            {
                curShownWindow.PreWindowID = lastShownWindow.WindowID;
            }

            Debug.Log("<color=magenta>### current Navigation window </color>" + baseWindow.WindowID.ToString());
        }
    }
Пример #3
0
    /// <summary>
    /// 初始化当前界面管理类
    /// </summary>
    public void InitWindowManager()
    {
        removedKey.Clear();
        var enumerator = allWindows.GetEnumerator();

        while (enumerator.MoveNext())
        {
            UIWindowBase window = enumerator.Current.Value;
            UIWindowData data   = window.windowData;

            // 自定义窗口不销毁
            if (data.windowType == UIWindowType.Custom)
            {
                continue;
            }

            removedKey.Add(window.WindowID);
        }

        for (int i = 0; i < removedKey.Count; i++)
        {
            allWindows.Remove(removedKey[i]);
            showWindows.Remove(removedKey[i]);
        }

        backSequence.Clear();
    }
Пример #4
0
    /// <summary>
    /// 隐藏所有显示的窗口
    /// </summary>
    /// <param name="includeFixed"></param>
    public void HideAllShownWindow(bool includeFixed)
    {
        if (showWindows.Count <= 0)
        {
            return;
        }

        List <int> removedKey = new List <int>();

        foreach (KeyValuePair <int, UIWindowBase> window in showWindows)
        {
            UIWindowData windowData = window.Value.windowData;
            if (!includeFixed && windowData.windowType == UIWindowType.Fixed)
            {
                continue;
            }

            removedKey.Add(window.Key);
            window.Value.HideWindowDirectly();
        }

        for (int i = 0; i < removedKey.Count; i++)
        {
            showWindows.Remove(removedKey[i]);
        }
    }
Пример #5
0
    /// <summary>
    /// 显示窗口
    /// tips:检查是否是隐藏
    /// </summary>
    /// <param name="name">Name.</param>
    public void ShowWindow(string name)
    {
        // 判断是否是隐藏,如果隐藏,则设置显示,如果已经显示,则不操作
        BaseWindow bw = GetWindow(name);

        if (bw != null)
        {
            if (!IsWindowVisible(bw))
            {
                bw.gameObject.SetActive(true);
                bw.OnShow();
                PushShowingStack(bw);
            }
            return;
        }

        // 获得外部配置数据
        UIWindowData config = UIWindowDataProvider.Instance.GetData(name);

        if (config == null || string.IsNullOrEmpty(config.mPrefabPath))
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s prefab config is null!", name);
            return;
        }

        // 加载prefab,实例化,挂载至root点
        GameObject prefab = Resources.Load(config.mPrefabPath) as GameObject;

        if (null == prefab)
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s prefab cannot Load!", name);
            return;
        }

        prefab = UnityTools.AddChild(UISystem.Instance.GetUICamera(), prefab);

        // 获得BaseWindow对象,调用Init
        bw = prefab.GetComponent <BaseWindow>();
        if (bw == null)
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0} can't get BaseWindow component from prefab!", name);
            return;
        }
        bw.SetConfigData(config);
        if (!bw.Init())
        {
            Debug.LogErrorFormat("UISystem_ShowWindow : {0}'s BaseWindow init failed!", name);
            return;
        }

        // 加入管理队列和栈
        bw.OnShow();
        mManagedWindows.Add(bw);
        PushShowingStack(bw);

        Resources.UnloadUnusedAssets();
        System.GC.Collect();
    }
Пример #6
0
 public IWindow(string name, UIWindowData data)
 {
     mBaseNode = null;
     mIsShow = false;
     mIsLoad = false;
     mName = name;
     mData = data;
     mExtraDatas = new Dictionary<string,string>();
 }
Пример #7
0
    static public UIWindowData Create()
    {
        UIWindowData data = new UIWindowData();

        data.forceClearNavigation = false;
        data.windowType           = UIWindowType.Normal;
        data.showMode             = UIWindowShowMode.DoNothing;

        return(data);
    }
Пример #8
0
    public void CloseWindow(UISettings.UIWindowID id, bool needTransform = true, System.Action onComplate = null)
    {
        SetWindowState(id, false);
        UIWindowBase window;

        allWindows.TryGetValue(id, out window);
        if (window != null)
        {
            if (showingWindows.ContainsKey(id))
            {
                showingWindows.Remove(id);
            }

            popupCollider.GetComponent <FadeIn>().to = 0;
            window.HideWindow(() =>
            {
                UIWindowData windowdata = window.windowData;
                if (windowdata.type == UISettings.UIWindowType.Fixed)
                {
                }
                else if (windowdata.type == UISettings.UIWindowType.PopUp)
                {
                    curPopUpWindow = null;
                    popupCollider.SetActive(false);
                    for (int i = PopUpRoot.childCount - 1; i >= 0; i--)
                    {
                        Transform tf = PopUpRoot.GetChild(i);
                        if (tf.gameObject.activeSelf)
                        {
                            UIWindowBase wd = tf.GetComponent <UIWindowBase>();
                            if (wd != null)
                            {
                                popupCollider.SetActive(true);
                                curPopUpWindow = wd;
                                popupCollider.transform.SetSiblingIndex(Mathf.Max(0, i - 1));

                                break;
                            }
                        }
                    }
                }
                else if (windowdata.type == UISettings.UIWindowType.Normal)
                {
                    hideNavigationWindow(window);
                }
                if (onComplate != null)
                {
                    onComplate();
                }
            }, needTransform);
        }
    }
Пример #9
0
    private void HideOtherWindow(UIWindowBase targetWindow)
    {
        UIWindowData windowData = targetWindow.windowData;

        List <UIWindowBase> sortedHiddenWindows = new List <UIWindowBase>();

        removedKey.Clear();

        var enumerator = showWindows.GetEnumerator();

        while (enumerator.MoveNext())
        {
            UIWindowBase window   = enumerator.Current.Value;
            int          windowId = enumerator.Current.Key;

            removedKey.Add(windowId);

            window.HideWindowDirectly();
            sortedHiddenWindows.Add(window);
        }

        // 从显示窗口集合移除
        for (int i = 0; i < removedKey.Count; i++)
        {
            showWindows.Remove(removedKey[i]);
        }

        // 根据窗口depath排序
        sortedHiddenWindows.Sort(compareWindowFun);

        List <int> navHiddenWindows = new List <int>();

        for (int i = 0; i < sortedHiddenWindows.Count; i++)
        {
            int pushWindowId = sortedHiddenWindows[i].WindowID;
            navHiddenWindows.Add(pushWindowId);
        }

        BackWindowSequenceData backData = new BackWindowSequenceData();

        backData.hideTargetWindow = targetWindow;
        backData.backShowTargets  = navHiddenWindows;
        backSequence.Push(backData);
        Debug.Log("<color=cyan>### !!!Push new Navigation data!!! ###</color>");
    }
Пример #10
0
    // 刷新窗口队列
    private void RefreshBackSequenceData(UIWindowBase targetWindow)
    {
        UIWindowData windowData = targetWindow.windowData;

        if (showWindows == null || windowData.showMode == UIWindowShowMode.DoNothing)
        {
            return;
        }

        if (windowData.showMode == UIWindowShowMode.HideOtherWindow)
        {
            HideOtherWindow(targetWindow);
            return;
        }

        if (windowData.showMode == UIWindowShowMode.DestoryOtherWindow)
        {
            DestoryOtherWindow(targetWindow);
            return;
        }
    }
Пример #11
0
    public void CloseAllWindow()
    {
        if (allWindows != null)
        {
            foreach (KeyValuePair <int, UIWindowBase> window in allWindows)
            {
                UIWindowBase baseWindow = window.Value;
                UIWindowData windowData = baseWindow.windowData;
                // 自定义窗口自己处理
                if (windowData.windowType == UIWindowType.Custom)
                {
                    continue;
                }

                baseWindow.DestroyWindow();
            }
        }

        if (uiNormalWindowRoot.childCount > 0)
        {
            uiNormalWindowRoot.DestroyChildren();
        }

        if (uiPopUpWindowRoot.childCount > 0)
        {
            uiPopUpWindowRoot.DestroyChildren();
        }

        if (uiFixedWidowRoot.childCount > 0)
        {
            uiFixedWidowRoot.DestroyChildren();
        }

        InitWindowManager();

        curShownWindow  = null;
        lastShownWindow = null;
    }
Пример #12
0
    private void DestoryOtherWindow(UIWindowBase targetWindow)
    {
        UIWindowData windowData = targetWindow.windowData;

        removedKey.Clear();

        var enumerator = allWindows.GetEnumerator();

        while (enumerator.MoveNext())
        {
            UIWindowBase window   = enumerator.Current.Value;
            int          windowId = enumerator.Current.Key;

            if (windowId == targetWindow.WindowID ||
                window.windowData.windowType == UIWindowType.Custom)
            {
                continue;
            }

            removedKey.Add(windowId);
        }

        for (int i = 0; i < removedKey.Count; i++)
        {
            showWindows.Remove(removedKey[i]);
        }

        ClearBackSequence();
        curShownWindow  = null;
        lastShownWindow = null;

        if (removedKey.Count > 0)
        {
            StartCoroutine(DestoryOtherWindowCor());
        }

        Debug.Log("<color=red>## [Destory Other Window, reset the backSequenceData for the navigation system.]##</color>");
    }
Пример #13
0
 public static void Init(UIWindowData _uiWindowData)
 {
     uiWindowData = _uiWindowData;
 }
Пример #14
0
    private IEnumerator ConfigureWindow(GameObject go, UISettings.UIWindowID id, bool needTransform = true, System.Action onComplate = null, params object[] data)
    {
        UIWindowBase window;

        allWindows.TryGetValue(id, out window);
        if (window == null)
        {
            GameObject windowGO = GameObject.Instantiate(go);
            windowGO.SetActive(false);
            window = windowGO.GetComponent <UIWindowBase>();
            UIWindowData windowData = window.windowData;
            if (windowData.id != id)
            {
                Debug.LogError("加载的window id和目标id不符");
            }
            allWindows.Add(windowData.id, window);
        }

        RectTransform rt = window.transform as RectTransform;

        switch (window.windowData.type)
        {
        case UISettings.UIWindowType.Fixed:
            window.gameObject.transform.SetParent(FixedRoot);
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.offsetMin = Vector2.zero;
            rt.offsetMax = Vector2.one;
            break;

        case UISettings.UIWindowType.Normal:
            window.transform.SetParent(NormalRoot);
            break;

        case UISettings.UIWindowType.PopUp:
            window.transform.SetParent(PopUpRoot);
            break;

        case UISettings.UIWindowType.Cover:
            window.transform.SetParent(coverRoot);
            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.offsetMin = Vector2.zero;
            rt.offsetMax = Vector2.one;
            break;
        }
        window.transform.localPosition = Vector3.zero;
        window.transform.localScale    = Vector3.one;
        //(window.transform as RectTransform).anchoredPosition = Vector2.zero;
        window.Init();
        yield return(null);

        if (windowsState[id])
        {
            StartOpenWindow(id, needTransform, onComplate, data);
        }
        else
        {
            isOpening = false;
        }
    }
Пример #15
0
    private void StartOpenWindow(UISettings.UIWindowID id, bool needTransform = true, System.Action onComplate = null, params object[] data)
    {
        isOpening = true;
        UIWindowBase window;

        allWindows.TryGetValue(id, out window);
        if (window != null)
        {
            if (!window.canOpen)
            {
                isOpening = false;
                return;
            }
            UIWindowData windowdata = window.windowData;

            if (windowdata.type == UISettings.UIWindowType.Fixed)
            {
                //window.transform.SetSiblingIndex(FixedRoot.childCount);
                SetSiblingIndex(window, FixedRoot);
            }
            else if (windowdata.type == UISettings.UIWindowType.PopUp)
            {
                curPopUpWindow = window;
                popupCollider.SetActive(true);
                popupCollider.transform.SetAsLastSibling();
                SetSiblingIndex(window, PopUpRoot);
                //popupCollider.transform.SetSiblingIndex(PopUpRoot.childCount);
                // window.transform.SetSiblingIndex(PopUpRoot.childCount);

                if (window.windowData.colliderType == UISettings.UIWindowColliderType.Transparent)
                {
                    popupCollider.GetComponent <Image>().color = new Color(0.8f, 0.8f, 0.8f, 0f);
                }
                else
                {
                    popupCollider.GetComponent <Image>().color = new Color(0, 0, 0, 0f);
                    popupCollider.GetComponent <FadeIn>().to   = 0.4f;
                }

                //popupCollider.GetComponent<Image>().color = new Color(0.8f,0.8f,0.8f,0.5f);
            }
            else if (windowdata.type == UISettings.UIWindowType.Normal)
            {
                SetSiblingIndex(window, NormalRoot);
                //window.transform.SetSiblingIndex(NormalRoot.childCount);
                showNavigationWindow(window);
            }
            else if (windowdata.type == UISettings.UIWindowType.Cover)
            {
                SetSiblingIndex(window, coverRoot);
                //window.transform.SetSiblingIndex(coverRoot.childCount);
            }


            if (!showingWindows.ContainsKey(id))
            {
                showingWindows.Add(id, window);
            }
            isOpening = false;
            StartCoroutine(window.ShowWindow(() =>
            {
                if (onComplate != null)
                {
                    onComplate();
                }
            }, needTransform, data));
        }
        else
        {
            string path = FilePathTools.getUIPath(UISettings.getWindowName(id));
            AssetBundleLoadManager.Instance.LoadAsset <GameObject>(path, (go) =>
            {
                StartCoroutine(ConfigureWindow(go, id, needTransform, onComplate, data));
            });
        }
    }
Пример #16
0
 /// <summary>
 /// 设置窗口配置数据
 /// </summary>
 /// <param name="data">Data.</param>
 public void SetConfigData(UIWindowData data)
 {
     mConfigData = data;
 }
Пример #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseWindow"/> class.
 /// </summary>
 public BaseWindow()
 {
     mRegisteredEvents = new List<EventId> ();
     mConfigData = null;
 }
Пример #18
0
 /// <summary>
 /// 设置窗口配置数据
 /// </summary>
 /// <param name="data">Data.</param>
 public void SetConfigData(UIWindowData data)
 {
     mConfigData = data;
 }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseWindow"/> class.
 /// </summary>
 public BaseWindow()
 {
     mRegisteredEvents = new List <EventId> ();
     mConfigData       = null;
 }