Exemple #1
0
        /// <summary>
        /// Calculate right depth with windowType
        /// </summary>
        /// <param name="baseWindow"></param>
        private void AdjustBaseWindowDepth(UIWindowBase baseWindow)
        {
            UIWindowType windowType = baseWindow.windowData.windowType;
            int          needDepth  = 1;

            if (windowType == UIWindowType.NormalLayer)
            {
                needDepth = Mathf.Clamp(UGUITools.GetMaxTargetDepth(UINormalLayerRoot.gameObject, false) + 1, normalWindowDepth, int.MaxValue);
                Debug.Log(string.Format("<color=#2a5caa>[UIWindowType.Normal] maxDepth is {0} , {1}.</color>", needDepth.ToString(), baseWindow.ID.ToString()));
            }
            else if (windowType == UIWindowType.ForegroundLayer)
            {
                needDepth = Mathf.Clamp(UGUITools.GetMaxTargetDepth(UIForegroundLayerRoot.gameObject) + 1, popUpWindowDepth, int.MaxValue);
                Debug.Log(string.Format("<color=#2a5caa>[UIWindowType.PopUp] maxDepth is {0} , {1}.</color>", needDepth.ToString(), baseWindow.ID.ToString()));
            }
            else if (windowType == UIWindowType.BackgroundLayer)
            {
                needDepth = Mathf.Clamp(UGUITools.GetMaxTargetDepth(UIBackgroundLayerRoot.gameObject) + 1, fixedWindowDepth, int.MaxValue);
                Debug.Log(string.Format("<color=#2a5caa>[UIWindowType.Fixed] maxDepth is {0} , {1}.</color>", needDepth.ToString(), baseWindow.ID.ToString()));
            }
            if (baseWindow.MinDepth != needDepth)
            {
                UGUITools.SetTargetMinPanelDepth(baseWindow.gameObject, needDepth);
            }

            // send window added message to game client
            if (baseWindow.windowData.windowType == UIWindowType.ForegroundLayer)
            {
                // trigger the window PopRoot added window event
                // EventDispatcher.GetInstance().UIFrameWorkEventManager.TriggerEvent(EventId.PopRootWindowAdded);
                //暂时不需要事件系统
            }
            baseWindow.MinDepth = needDepth;
        }
Exemple #2
0
        /// <summary>
        /// Find component in Target Child
        /// </summary>
        public static T FindDeepChild <T>(GameObject _target, string _childName) where T : Component
        {
            Transform resultTrs = UGUITools.FindDeepChild(_target, _childName);

            if (resultTrs != null)
            {
                return(resultTrs.gameObject.GetComponent <T>());
            }
            return((T)((object)null));
        }
Exemple #3
0
        // Push target GameObject to top depth
        // Case: when you open multi PopWindow
        // You want one of these PopWindow stay at the Top
        // You can register the EventSystemDefine.EventUIFrameWorkPopRootWindowAdded
        // Call this method to push window to top
        public static void AdjustTargetWindowDepthToTop(UIWindowBase targetWindow)
        {
            if (targetWindow == null)
            {
                return;
            }

            Transform windowRoot = Instance.GetTargetRoot(targetWindow.windowData.windowType);
            int       needDepth  = Mathf.Clamp(UGUITools.GetMaxTargetDepth(windowRoot.gameObject, true) + 1, popUpWindowDepth, int.MaxValue);

            UGUITools.SetTargetMinPanelDepth(targetWindow.gameObject, needDepth);
            targetWindow.MinDepth = needDepth;
        }
Exemple #4
0
        /// <summary>
        /// Find Deep child with name
        /// </summary>
        public static Transform FindDeepChild(GameObject _target, string _childName)
        {
            Transform resultTrs = null;

            resultTrs = _target.transform.Find(_childName);
            if (resultTrs == null)
            {
                foreach (Transform trs in _target.transform)
                {
                    resultTrs = UGUITools.FindDeepChild(trs.gameObject, _childName);
                    if (resultTrs != null)
                    {
                        return(resultTrs);
                    }
                }
            }

            return(resultTrs);
        }
Exemple #5
0
        /// <summary>
        /// Add Collider and BgTexture for target window
        /// </summary>
        private void AddColliderBgForWindow(UIWindowBase baseWindow)
        {
            UIWindowColliderMode colliderMode = baseWindow.windowData.colliderMode;

            if (colliderMode == UIWindowColliderMode.None)
            {
                return;
            }
            GameObject bgObj = null;

            if (colliderMode == UIWindowColliderMode.Normal)
            {
                bgObj = UGUITools.AddColliderBgToTarget(baseWindow.gameObject, "Mask02", true);
            }
            if (colliderMode == UIWindowColliderMode.WithBg)
            {
                bgObj = UGUITools.AddColliderBgToTarget(baseWindow.gameObject, "Mask02", false);
            }
            baseWindow.OnAddColliderBg(bgObj);
        }
Exemple #6
0
        public override void InitWindowManager()
        {
            base.InitWindowManager();
            InitWindowControl();
            isNeedWaitHideOver = true;


            if (UIBackgroundLayerRoot == null)
            {
                GameObject BackgroundLayerRoot = new GameObject("UIBackgroundLayerRoot");
                UIBackgroundLayerRoot           = BackgroundLayerRoot.gameObject.AddComponent <RectTransform>();
                UIBackgroundLayerRoot.anchorMax = new Vector2(1f, 1f);
                UIBackgroundLayerRoot.anchorMin = new Vector2(0f, 0f);
                UIBackgroundLayerRoot.offsetMax = new Vector2(0, 0);
                UIBackgroundLayerRoot.offsetMin = new Vector2(0, 0);
                UGUITools.AddChildToTarget(UIRoot, UIBackgroundLayerRoot);
                UGUITools.ChangeChildLayer(UIBackgroundLayerRoot, UIRoot.gameObject.layer);
            }
            if (UINormalLayerRoot == null)
            {
                GameObject NormalLayerRoot = new GameObject("UINormalWindowRoot");
                UINormalLayerRoot           = NormalLayerRoot.gameObject.AddComponent <RectTransform>();
                UINormalLayerRoot.anchorMax = new Vector2(1f, 1f);
                UINormalLayerRoot.anchorMin = new Vector2(0f, 0f);
                UINormalLayerRoot.offsetMax = new Vector2(0, 0);
                UINormalLayerRoot.offsetMin = new Vector2(0, 0);
                UGUITools.AddChildToTarget(UIRoot, UINormalLayerRoot);
                UGUITools.ChangeChildLayer(UINormalLayerRoot, UIRoot.gameObject.layer);
            }
            if (UIForegroundLayerRoot == null)
            {
                GameObject ForegroundLayerRoot = new GameObject("UIForegroundLayerRoot");
                UIForegroundLayerRoot           = ForegroundLayerRoot.gameObject.AddComponent <RectTransform>();
                UIForegroundLayerRoot.anchorMax = new Vector2(1f, 1f);
                UIForegroundLayerRoot.anchorMin = new Vector2(0f, 0f);
                UIForegroundLayerRoot.offsetMax = new Vector2(0, 0);
                UIForegroundLayerRoot.offsetMin = new Vector2(0, 0);
                UGUITools.AddChildToTarget(UIRoot, UIForegroundLayerRoot);
                UGUITools.ChangeChildLayer(UIForegroundLayerRoot, UIRoot.gameObject.layer);
            }
        }
Exemple #7
0
        // <summary>
        /// 给目标添加Collider背景
        /// Add Collider Background for target
        /// </summary>
        public static GameObject AddColliderBgToTarget(GameObject target, string maskNames, bool isTransparent)
        {
            // 添加UIPaneldepth最小上面
            // 保证添加的Collider放置在屏幕中间
            Transform windowBg = UGUITools.FindDeepChild(target, "WindowBg");

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

                GameObject temp = new GameObject("WindowBg");
                UGUITools.AddChildToTarget(target.transform, temp.transform);
                RectTransform rt = temp.AddComponent <RectTransform>();
                rt.offsetMax = Vector2.zero;
                rt.offsetMin = Vector2.zero;
                rt.anchorMax = Vector2.one;
                rt.anchorMin = Vector2.zero;
                windowBg     = rt.transform;
                windowBg.SetAsFirstSibling();
            }

            Transform Masker = UGUITools.FindDeepChild(target, "WindowColliderBg(Cool)");

            if (Masker == null)
            {
                Transform  root = UICenterMasterManager.Instance.GetTargetRoot(UIWindowType.ForegroundLayer);
                GameObject res  = Resources.Load("UIPrefab/Mask/" + maskNames) as GameObject;
                Masker      = UGUITools.AddChild(root.gameObject, res).transform;
                Masker.name = "WindowColliderBg(Cool)";
                SetRectTransformOffset(Masker.gameObject, Vector2.zero, Vector2.zero);
                res = null;
                UGUITools.AddChildToTarget(windowBg, Masker.transform);

                if (isTransparent)
                {
                    Masker.GetComponent <UnityEngine.UI.Image>().color = new Color(1, 1, 1, 0.1f);
                }
                else
                {
                    Masker.GetComponent <UnityEngine.UI.Image>().color = new Color(1, 1, 1, 0.5f);
                }


                // 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(Masker.gameObject);
        }
Exemple #8
0
        protected override UIWindowBase ReadyToShowBaseWindow(WindowID id, ShowWindowData showData = null)
        {
            // Check the window control state
            if (!this.IsWindowInControl(id))
            {
                Debug.Log("## UIManager has no control power of " + id.ToString());
                return(null);
            }

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

            UIWindowBase 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(id))
                {
                    GameObject prefab = Resources.Load <GameObject>(UIResourceDefine.windowPrefabPath[id]);
                    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 <UIWindowBase>();
                        if (baseWindow.ID != id)
                        {
                            Debug.LogError(string.Format("<color=#2a5caa>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id));
                            return(null);
                        }

                        // Get the window target root parent
                        Transform targetRoot = GetTargetRoot(baseWindow.windowData.windowType);
                        Transform t          = uiObject.transform;
                        t.SetParent(targetRoot.transform);
                        t.localPosition = Vector3.zero;
                        t.localRotation = Quaternion.identity;
                        t.localScale    = Vector3.one;
                        uiObject.layer  = targetRoot.gameObject.layer;
                        RectTransform _targetRectTransform = uiObject.GetComponent <RectTransform>();
                        if (_targetRectTransform.anchorMax == Vector2.one && _targetRectTransform.anchorMin == Vector2.zero)
                        {
                            //如果是拉伸就吧边角设置成0
                            UGUITools.SetRectTransformOffset(uiObject, Vector2.zero, Vector2.zero);
                        }
                        UGUITools.SetRectTransformAnchoredPosition(uiObject, Vector2.zero);
                        //  baseWindow = UGUITools.AddChild(targetRoot.gameObject, prefab).GetComponent<UIWindowBase>();
                        if (baseWindow.ID != id)
                        {
                            Debug.LogError(string.Format("<color=#2a5caa>[BaseWindowId :{0} != shownWindowId :{1}]</color>", baseWindow.ID, id));
                            return(null);
                        }
                        dicAllWindows[id] = baseWindow;
                        prefab            = null;
                    }
                }
            }

            if (baseWindow == null)
            {
                Debug.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);
        }