示例#1
0
        private float GetTopPlaneDistance(EUISortingLayer uiSortingLayer)
        {
            float         topPlaneDistance = 0;
            List <string> layerUIPathList  = null;

            if (_layerDic.TryGetValue(uiSortingLayer, out layerUIPathList))
            {
                if (layerUIPathList.Count > 0)
                {
                    Canvas canvas = _uiDic[layerUIPathList.Last()].GetComponent <Canvas>();
                    if (canvas != null)
                    {
                        if (topPlaneDistance > canvas.planeDistance)
                        {
                            topPlaneDistance = canvas.planeDistance;
                        }
                    }
                }
                else
                {
                    topPlaneDistance = (int)uiSortingLayer * -1000;
                }
            }
            else
            {
                topPlaneDistance = (int)uiSortingLayer * -1000;
            }
            topPlaneDistance -= 10;
            return(topPlaneDistance);
        }
示例#2
0
 public void CloseLayerBelow(EUISortingLayer uiSortingLayer)
 {
     for (int i = (int)EUISortingLayer.MainUI; i <= (int)uiSortingLayer; i++)
     {
         Close((EUISortingLayer)i);
     }
 }
示例#3
0
        private void Close(string uiPath, bool immediate)
        {
            GameObject go;

            if (!_uiDic.TryGetValue(uiPath, out go))
            {
                return;
            }
            _uiDic.Remove(uiPath);

            if (_goLayerDic.ContainsKey(go))
            {
                _goLayerDic.Remove(go);
            }
            foreach (var kv in _layerDic)
            {
                if (kv.Value.Contains(uiPath))
                {
                    kv.Value.Remove(uiPath);
                    break;
                }
            }

            EUISortingLayer uiSortingLayer = EUISortingLayer.MainUI;

            if (_goLayerDic.TryGetValue(go, out uiSortingLayer))
            {
                Dictionary <string, UIOpenMode> openModeDic = null;
                if (_layerUIOpenModeDic.TryGetValue(uiSortingLayer, out openModeDic))
                {
                    openModeDic.TryDelete(uiPath);
                }
            }

            if (immediate)
            {
                UnityEngine.Object.DestroyImmediate(go);
            }
            else
            {
                UnityEngine.Object.Destroy(go);
            }

            if (uiSortingLayer == EUISortingLayer.MainUI)
            {
                RecalulateMainUIlayer();
            }
            if (LuaInterface.LuaScriptMgr.Instance != null)
            {
                LuaInterface.LuaScriptMgr.Instance.CallLuaFunction("uimanager.CloseView", uiPath);
            }
            Observers.Facade.Instance.SendNotification(uiPath, null, "close");
            Observers.Facade.Instance.SendNotification(string.Format("{0}::{1}", uiPath, "OnViewClose"));
            Observers.Facade.Instance.SendNotification("CloseUIView", uiPath, "close");
        }
示例#4
0
        public GameObject Open(string uiPath, EUISortingLayer uiSortingLayer = EUISortingLayer.MainUI, UIOpenMode uiOpenMode = UIOpenMode.Replace)
        {
            GameObject result = null;

            if (!_uiDic.TryGetValue(uiPath, out result))
            {
                GameObject prefab = ResMgr.instance.Load <GameObject>(uiPath);
                if (prefab == null)
                {
                    return(null);
                }
                result = GameObject.Instantiate(prefab);
                result.transform.SetParent(ui2DRoot, false);
                result.name = uiPath;

                RectTransform rectTransform = result.GetComponent <RectTransform>();
                if (rectTransform != null)
                {
                    rectTransform.anchorMin          = Vector2.zero;
                    rectTransform.anchorMax          = Vector3.one;
                    rectTransform.anchoredPosition3D = Vector3.zero;
                    rectTransform.offsetMin          = Vector2.zero;
                    rectTransform.offsetMax          = Vector2.zero;
                    rectTransform.pivot      = new Vector2(0.5f, 0.5f);
                    rectTransform.localScale = Vector3.one;
                }
            }
            SetLayerAndOrder(result, uiSortingLayer, GetTopSortingOrderAtLayer(uiSortingLayer), GetTopPlaneDistance(uiSortingLayer));

            _uiDic.AddOrReplace(uiPath, result);
            _goLayerDic.AddOrReplace(result, uiSortingLayer);

            if (!_layerDic.ContainsKey(uiSortingLayer))
            {
                _layerDic[uiSortingLayer] = new List <string>();
            }
            _layerDic[uiSortingLayer].Remove(uiPath);
            _layerDic[uiSortingLayer].Add(uiPath);

            if (!_layerUIOpenModeDic.ContainsKey(uiSortingLayer))
            {
                _layerUIOpenModeDic[uiSortingLayer] = new Dictionary <string, UIOpenMode>();
            }
            _layerUIOpenModeDic[uiSortingLayer].AddOrReplace(uiPath, uiOpenMode);

            Observers.Facade.Instance.SendNotification(uiPath, result, "open");
            Observers.Facade.Instance.SendNotification("OpenUIView", uiPath, "open");

            if (uiSortingLayer == EUISortingLayer.MainUI)
            {
                RecalulateMainUIlayer();
            }
            return(result);
        }
示例#5
0
        public void Close(EUISortingLayer uiSortingLayer)
        {
            List <string> uiPathList;

            if (_layerDic.TryGetValue(uiSortingLayer, out uiPathList))
            {
                List <string> uiPathListCopy = new List <string>(uiPathList);
                for (int index = 0, count = uiPathListCopy.Count; index < count; index++)
                {
                    Close(uiPathListCopy[index]);
                }
            }
        }
示例#6
0
        public int GetOpenUICount(EUISortingLayer layer = EUISortingLayer.MainUI)
        {
            int count = 0;

            foreach (var value in _uiDic)
            {
                if (_goLayerDic[value.Value] == layer)
                {
                    count++;
                }
            }
            return(count);
        }
示例#7
0
        private int GetTopSortingOrderAtLayer(EUISortingLayer uiSortingLayer)
        {
            int           result          = 0;
            List <string> layerUIPathList = null;

            if (_layerDic.TryGetValue(uiSortingLayer, out layerUIPathList))
            {
                if (layerUIPathList.Count > 0)
                {
                    Canvas canvas = _uiDic[layerUIPathList.Last()].GetComponent <Canvas>();
                    if (canvas != null)
                    {
                        result += canvas.sortingOrder;
                    }
                }
            }
            result += SORT_ORDER_INTERVAL;
            return(result);
        }
示例#8
0
        private void SetLayerAndOrder(GameObject target, EUISortingLayer uiSortingLayer, int sortingOrder, float planeDistance)
        {
            Canvas[] canvases = target.GetComponentsInChildren <Canvas>(true);
            Canvas   canvas   = null;

            for (int index = 0, count = canvases.Length; index < count; index++)
            {
                canvas = canvases[index];
                canvas.sortingLayerName = uiSortingLayer.ToString();
                canvas.sortingOrder     = sortingOrder + canvas.sortingOrder;
            }

            Common.Components.SortingOrderChanger[] sortingOrderChangers = target.GetComponentsInChildren <Common.Components.SortingOrderChanger>(true);
            Common.Components.SortingOrderChanger   sortingOrderChanger  = null;
            for (int index = 0, count = sortingOrderChangers.Length; index < count; index++)
            {
                sortingOrderChanger = sortingOrderChangers[index];
                sortingOrderChanger.sortingOrder += sortingOrder;
            }

            Renderer[] renderers = target.GetComponentsInChildren <Renderer>(true);
            Renderer   renderer  = null;

            for (int index = 0, count = renderers.Length; index < count; index++)
            {
                renderer = renderers[index];
                renderer.sortingLayerName = uiSortingLayer.ToString();
                renderer.sortingOrder     = sortingOrder + renderer.sortingOrder;
            }

            Canvas targetCanvas = target.GetComponent <Canvas>();

            if (targetCanvas != null)
            {
                targetCanvas.overrideSorting  = true;
                targetCanvas.sortingLayerName = uiSortingLayer.ToString();
                targetCanvas.sortingOrder     = sortingOrder;
                //				targetCanvas.transform.localPosition = new Vector3(targetCanvas.transform.localPosition.x, targetCanvas.transform.localPosition.y, z);
                targetCanvas.planeDistance = planeDistance;
            }
        }
示例#9
0
        public T Open <T>(string uiPath, EUISortingLayer uiSortingLayer = EUISortingLayer.MainUI, UIOpenMode uiOpenMode = UIOpenMode.Replace) where T : MonoBehaviour
        {
            GameObject go = Open(uiPath, uiSortingLayer, uiOpenMode);

            return(go.GetComponent <T>());
        }
示例#10
0
        public static CommonErrorTipsView Open(string tipsString, System.Action callback = null, EUISortingLayer uiSortingLayer = EUISortingLayer.Tips)
        {
            CommonErrorTipsView tips = UIMgr.instance.Open <CommonErrorTipsView>(PREFAB_PATH, uiSortingLayer);

            tips.SetTips(tipsString);
            tips._callback = callback;
            return(tips);
        }