Example #1
0
        public GameObject AddChild(GameObject parentUI, GameObject childUI)
        {
            var ch       = NGUITools.AddChild(parentUI, childUI);
            var up       = parentUI.GetComponent <UIPanel>().depth;
            var allPanel = Util.GetAllPanel(ch);
            var oldDepth = allPanel[0].depth;

            foreach (var uiPanel in allPanel)
            {
                uiPanel.depth = up + (uiPanel.depth - oldDepth);
            }
            return(ch);
        }
Example #2
0
        /// <summary>
        /// 最顶层显示一个UI界面
        /// </summary>
        /// <returns>The top notify.</returns>
        /// <param name="viewName">View name.</param>
        public GameObject PushTopNotify(string viewName)
        {
            if (uiRoot == null)
            {
                uiRoot = GameObject.FindGameObjectWithTag("UIRoot");
            }
            if (uiRoot == null)
            {
                return(null);
            }
            GameObject bag;

            if (uiMap.TryGetValue(viewName, out bag))
            {
                if (bag == null)
                {
                    return(null);
                }
                bag.SetActive(true);
            }
            else
            {
                bag = NGUITools.AddChild(uiRoot, Resources.Load <GameObject>(viewName));
                uiMap [viewName] = bag;
            }
            if (bag == null)
            {
                Debug.LogError("can't Find UI " + viewName);
            }


            var allPanel = Util.GetAllPanel(bag);
            int oldDepth = allPanel [0].depth;

            foreach (UIPanel p in allPanel)
            {
                p.depth = (int)UIDepth.Window + 100 + 1 + (p.depth - oldDepth);
            }

            Log.GUI("Push Notify UI " + bag.name);
#if UNITY_EDITOR
            foreach (GameObject g in stack)
            {
                if (g != null)
                {
                    Log.GUI("Stack UI is " + g.name);
                }
            }
#endif
            return(bag);
        }
Example #3
0
        public GameObject PushView(string viewName, bool needAlpha = true)
        {
            Log.Important("Push UI View " + viewName + " " + needAlpha);
            if (uiRoot == null)
            {
                uiRoot = GameObject.FindGameObjectWithTag("UIRoot");
            }
            Log.GUI("UIRoot " + uiRoot);
            if (needAlpha)
            {
                if (back == null)
                {
                    back = NGUITools.AddChild(uiRoot, background);
                }
                else
                {
                    if (stack.Count == 0)
                    {
                        back.SetActive(true);
                    }
                }
            }

            GameObject bag = null;

            uiMap.TryGetValue(viewName, out bag);
            if (bag != null)
            {
                //bag.GetComponent<IUserInterface>().RegEvent();
                bag.SetActive(true);
            }
            else
            {
                bag = NGUITools.AddChild(uiRoot, Resources.Load <GameObject>(viewName));
                uiMap [viewName] = bag;
                bag.SetActive(true);
            }
            if (bag == null)
            {
                Debug.LogError("can't Find UI " + viewName);
            }
            if (needAlpha)
            {
                var alpha = NGUITools.AddChild(uiRoot, alphaBlock);
                alpha.GetComponent <UIPanel>().depth = (int)UIDepth.Window + stack.Count * 10;
                alphaStack.Add(alpha);
            }
            else
            {
                var just = NGUITools.AddChild(uiRoot, justBlock);
                just.GetComponent <UIPanel>().depth = (int)UIDepth.Window + stack.Count * 10;
                alphaStack.Add(just);
            }

            var allPanel = Util.GetAllPanel(bag);
            int oldDepth = allPanel [0].depth;

            foreach (UIPanel p in allPanel)
            {
                p.depth = (int)UIDepth.Window + stack.Count * 10 + 1 + (p.depth - oldDepth);
            }

            //bag.GetComponent<UIPanel> ().depth = (int)UIDepth.Window+stack.Count*10+1;
            stack.Add(bag);
            Log.GUI("Push UI " + bag.name);
#if UNITY_EDITOR
            foreach (GameObject g in stack)
            {
                if (g != null)
                {
                    Log.GUI("Stack UI is " + g.name);
                }
            }
#endif
            BackgroundSound.Instance.PlayEffect("sheet_opencenter");
            return(bag);
        }