Exemplo n.º 1
0
        public override void InitWindowManager()
        {
            base.InitWindowManager();
            InitWindowControl();
            isNeedWaitHideOver = true;

            // test
            DontDestroyOnLoad(UIRoot);

            if (UIFixedWidowRoot == null)
            {
                UIFixedWidowRoot = new GameObject("UIFixedWidowRoot").transform;
                GameUtility.AddChildToTarget(UIRoot, UIFixedWidowRoot);
                GameUtility.ChangeChildLayer(UIFixedWidowRoot, UIRoot.gameObject.layer);
            }
            if (UIPopUpWindowRoot == null)
            {
                UIPopUpWindowRoot = new GameObject("UIPopUpWindowRoot").transform;
                GameUtility.AddChildToTarget(UIRoot, UIPopUpWindowRoot);
                GameUtility.ChangeChildLayer(UIPopUpWindowRoot, UIRoot.gameObject.layer);
            }
            if (UINormalWindowRoot == null)
            {
                UINormalWindowRoot = new GameObject("UINormalWindowRoot").transform;
                GameUtility.AddChildToTarget(UIRoot, UINormalWindowRoot);
                GameUtility.ChangeChildLayer(UINormalWindowRoot, UIRoot.gameObject.layer);
            }

            ShowWindow(WindowID.WindowID_MainMenu);
            ShowWindow(WindowID.WindowID_TopBar);
        }
Exemplo n.º 2
0
        protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null)
        {
            // 检测控制权限
            if (!this.IsWindowInControl(id))
            {
                Debug.Log("UIManager has no control power of " + id.ToString());
                return(null);
            }
            if (shownWindows.ContainsKey(id))
            {
                return(null);
            }

            UIBaseWindow baseWindow = GetGameWindow(id);
            bool         newAdded   = false;

            if (!baseWindow)
            {
                newAdded = true;
                // 窗口不存在从内存进行加载
                if (UIResourceDefine.windowPrefabPath.ContainsKey(id))
                {
                    string     prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[id];
                    GameObject prefab     = Resources.Load <GameObject>(prefabPath);
                    if (prefab != null)
                    {
                        GameObject uiObject = (GameObject)GameObject.Instantiate(prefab);
                        NGUITools.SetActive(uiObject, true);
                        baseWindow = uiObject.GetComponent <UIBaseWindow>();
                        // 需要动态添加对应的控制界面,prefab不用添加脚本
                        Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType);
                        GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform);
                        allWindows[id] = baseWindow;
                    }
                }
            }

            if (baseWindow == null)
            {
                Debug.LogError("[window instance is null.]" + id.ToString());
            }

            // 重置界面(第一次添加,强制Reset)
            if (newAdded || (showData != null && showData.forceResetWindow))
            {
                baseWindow.ResetWindow();
            }

            // 显示界面固定内容


            // 导航系统数据更新
            RefreshBackSequenceData(baseWindow);
            // 调整层级depth
            AdjustBaseWindowDepth(baseWindow);
            // 添加背景Collider
            AddColliderBgForWindow(baseWindow);
            return(baseWindow);
        }
Exemplo n.º 3
0
        // <summary>
        /// 给目标添加Collider背景
        /// Add Collider Background for target
        /// </summary>
        public static GameObject AddColliderBgToTarget(GameObject target, string maskName, UIAtlas altas, bool isTransparent)
        {
            // 添加UIPaneldepth最小上面
            // 保证添加的Collider放置在屏幕中间
            Transform windowBg = GameUtility.FindDeepChild(target, "WindowBg");

            if (windowBg == null)
            {
                GameObject targetParent = GameUtility.GetPanelDepthMaxMin(target, false, true);
                if (targetParent == null)
                {
                    targetParent = target;
                }

                windowBg = (new GameObject("WindowBg")).transform;
                GameUtility.AddChildToTarget(targetParent.transform, windowBg);
            }

            Transform bg = GameUtility.FindDeepChild(target, "WindowColliderBg(Cool)");

            if (bg == null)
            {
                // add sprite or widget to ColliderBg
                UIWidget widget = null;
                if (!isTransparent)
                {
                    widget = NGUITools.AddSprite(windowBg.gameObject, altas, maskName);
                }
                else
                {
                    widget = NGUITools.AddWidget <UIWidget>(windowBg.gameObject);
                }

                widget.name = "WindowColliderBg(Cool)";
                bg          = widget.transform;

                // fill the screen
                // You can use the new Anchor system
                UIStretch stretch = bg.gameObject.AddComponent <UIStretch>();
                stretch.style = UIStretch.Style.Both;
                // set relative size bigger
                stretch.relativeSize = new Vector2(1.5f, 1.5f);

                // set a lower depth
                widget.depth = -5;

                // set alpha
                widget.alpha = 0.6f;

                // add collider
                NGUITools.AddWidgetCollider(bg.gameObject);
            }
            return(bg.gameObject);
        }
Exemplo n.º 4
0
        protected override UIBaseWindow ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null)
        {
            // Check the window control state
            if (!this.IsWindowInControl(id))
            {
                Debuger.Log("## UIManager has no control power of " + id.ToString());
                return(null);
            }

            // If the window in shown list just return
            if (dicShownWindows.ContainsKey((int)id))
            {
                return(null);
            }

            UIBaseWindow baseWindow = GetGameWindow(id);

            // If window not in scene start Instantiate new window to scene
            bool newAdded = false;

            if (!baseWindow)
            {
                newAdded = true;
                if (UIResourceDefine.windowPrefabPath.ContainsKey((int)id))
                {
                    string     prefabPath = UIResourceDefine.UIPrefabPath + UIResourceDefine.windowPrefabPath[(int)id];
                    GameObject prefab     = Resources.Load <GameObject>(prefabPath);
                    if (prefab != null)
                    {
                        GameObject uiObject = (GameObject)GameObject.Instantiate(prefab);
                        NGUITools.SetActive(uiObject, true);
                        // NOTE: You can add component to the window in the inspector
                        // Or just AddComponent<UIxxxxWindow>() to the target
                        baseWindow = uiObject.GetComponent <UIBaseWindow>();
                        if (baseWindow.ID != id)
                        {
                            Debuger.LogError(string.Format("<color=cyan>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id));
                            return(null);
                        }
                        // Get the window target root parent
                        Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType);
                        GameUtility.AddChildToTarget(targetRoot, baseWindow.gameObject.transform);
                        dicAllWindows[(int)id] = baseWindow;
                    }
                }
            }

            if (baseWindow == null)
            {
                Debuger.LogError("[window instance is null.]" + id.ToString());
            }

            // Call reset window when first load new window
            // Or get forceResetWindow param
            if (newAdded || (showData != null && showData.forceResetWindow))
            {
                baseWindow.ResetWindow();
            }

            if (showData == null || (showData != null && showData.executeNavLogic))
            {
                // refresh the navigation data
                ExecuteNavigationLogic(baseWindow, showData);
            }

            // Adjust the window depth
            AdjustBaseWindowDepth(baseWindow);

            // Add common background collider to window
            AddColliderBgForWindow(baseWindow);
            return(baseWindow);
        }