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); }
public void CloseLayerBelow(EUISortingLayer uiSortingLayer) { for (int i = (int)EUISortingLayer.MainUI; i <= (int)uiSortingLayer; i++) { Close((EUISortingLayer)i); } }
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"); }
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); }
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]); } } }
public int GetOpenUICount(EUISortingLayer layer = EUISortingLayer.MainUI) { int count = 0; foreach (var value in _uiDic) { if (_goLayerDic[value.Value] == layer) { count++; } } return(count); }
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); }
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; } }
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>()); }
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); }