Exemple #1
0
        /// <summary>
        /// 界面弹至最后
        /// </summary>
        public void PushBack(CGUIWindow window)
        {
            if (window.transform.parent == null)
            {
                Debug.LogError("Can't find parent's UIPanel.");
                return;
            }
            UIPanel parent = window.transform.parent.GetComponentInParent <UIPanel>();

            if (parent == null)
            {
                Debug.LogError("Can't find parent's UIPanel.");
                return;
            }

            int min_depth = 0;

            UIPanel[] panels = parent.GetComponentsInChildren <UIPanel>();
            for (int i = 0; i < panels.Length; ++i)
            {
                if (min_depth > panels[i].depth)
                {
                    min_depth = panels[i].depth;
                }
            }

            //设置新的depth
            window.Depth = min_depth - 1;

            //调整所有depth
            AdjustPanelDepth(parent);
        }
Exemple #2
0
        /// <summary>
        /// 界面弹至最前
        /// </summary>
        public void BringForward(CGUIWindow window)
        {
            if (window.transform.parent == null)
            {
                Debug.LogError("Can't find parent's UIPanel.");
                return;
            }
            UIPanel parent = window.transform.parent.GetComponentInParent <UIPanel>();

            if (parent == null)
            {
                Debug.LogError("Can't find parent's UIPanel.");
                return;
            }

            int max_depth = 0;

            UIPanel[] panels = parent.gameObject.GetComponentsInChildren <UIPanel>();
            for (int i = 0; i < panels.Length; ++i)
            {
                if (max_depth < panels[i].depth)
                {
                    max_depth = panels[i].depth;
                }
            }

            //设置新的depth
            window.Depth = max_depth + 1;
            //调整窗口的depth
            AdjustPanelDepth((UIPanel)window);
            //调整所有depth
            AdjustPanelDepth(parent);
        }
Exemple #3
0
        /// <summary>
        /// 获得一个界面
        /// </summary>
        public T GetWindow <T>(string name = null) where T : CGUIWindow
        {
            List <CGUIWindow> list;

            windows_.TryGetValue(typeof(T), out list);
            if (list == null || list.Count == 0)
            {
                return(default(T));
            }

            CGUIWindow window = null;

            if (string.IsNullOrEmpty(name))
            {
                window = list[0];
            }
            else
            {
                for (int i = 0; i < list.Count; ++i)
                {
                    if (list[i].name == name)
                    {
                        window = list[i];
                        break;
                    }
                }
            }

            return(window as T);
        }
Exemple #4
0
        /// <summary>
        ///   载入
        /// </summary>
        public CGUIWindow Load(string name)
        {
            //载入与类同名的Prefab
            GameObject prefab = Resources.Load <GameObject>(WINDOW_PREFAB_DEFAULT_LOAD_PATH + name);

            if (prefab == null)
            {
                Debug.LogError("Can't find window's prefab, window type is " + name);
                return(default(CGUIWindow));
            }

            //创建实例
            GameObject obj = UnityEngine.Object.Instantiate(prefab) as GameObject;

            if (obj == null)
            {
                Debug.LogError("Can't instantiate window's prefab, window type is " + name);
                return(default(CGUIWindow));
            }
            CGUIWindow window = obj.GetComponent <CGUIWindow>();

            if (window == null)
            {
                Debug.LogError("Don't get GameObject's component, component type is " + name);
                return(default(CGUIWindow));
            }

            return(window);
        }
Exemple #5
0
        /// <summary>
        /// 删除界面
        /// </summary>
        public void DeleteWindow(CGUIWindow window, bool hide_window = true)
        {
            if (window != null)
            {
                if (hide_window)
                {
                    window.Hide();
                    if (window.HidePlan != CGUI.WindowHidePlan.Delete)
                    {
                        return;
                    }
                }

                System.Type key = window.GetType();
                if (windows_.ContainsKey(key))
                {
                    windows_[key].Remove(window);
                }

                UnityEngine.Object.Destroy(window.gameObject);
            }
        }
Exemple #6
0
 /// <summary>
 /// 获得指定Component
 /// </summary>
 private static T _GetComponent <T>(CGUIWindow w) where T : Component
 {
     return(w != null?w.GetComponent <T>() : null);
 }