public GameObject Get(string uiPath, UIConfigChunk cc) { List <GameObject> l; if (_pool.TryGetValue(uiPath, out l)) { if (l.Count != 0) { l[0].SetActive(true); return(l[0]); } } else { _pool[uiPath] = new List <GameObject>(); } GameObject res = AssetBundleMgr.instance.GetAssetBundle(uiPath).LoadAsset <GameObject>(Path.GetFileNameWithoutExtension(uiPath)); var go = GameObject.Instantiate(res); go.name = uiPath; return(go); }
/// <summary> /// 打开ui /// </summary> public void OpenUI(string ui, UIConfigChunk chunk, params object[] args) { if (chunk.UIResType == ResType.ResourceLoad && chunk.UICacheType == CacheType.Cache) { TimeLogger.LogError("ui conflict restype and cache type:" + ui); return; } if (_stack.Count != 0) { var peek = _stack.Peek(); if (peek.UIPath == ui) { return; } if (peek.ConfigChunk.UIWinType == WindowType.PopUp) { _stack.Pop(); Recycle(peek); } else if (peek.ConfigChunk.UIWinType == WindowType.FullScreen) { if (peek.ConfigChunk.UIOpenType == OpenType.Back) { Recycle(peek); } } } UIStackChunk cacheStackChunk = null; foreach (var stackChunk in _stack) { if (stackChunk.UIPath == ui && null != stackChunk.UIBasePlane) { cacheStackChunk = stackChunk; break; } } BasePlane bp = null; if (null == cacheStackChunk) { GameObject bpGo; if (chunk.UIResType == ResType.ResourceLoad) { var res = Resources.Load <GameObject>(ui); bpGo = GameObject.Instantiate(res); } else { if (chunk.UICacheType == CacheType.Cache) { bpGo = _pool.Get(ui, chunk); } else { bpGo = AssetBundleMgr.instance.GetAssetBundle(ui).LoadAsset <GameObject>(Path.GetFileNameWithoutExtension(ui)); } } bpGo.transform.parent = Origin; bp = bpGo.GetComponent <BasePlane>(); var rt = bp.GetComponent <RectTransform>(); rt.offsetMax = Vector2.zero; rt.offsetMin = Vector2.zero; rt.localScale = Vector3.one; bp.UIPath = ui; bp.OnOpen(args); } else { bp = cacheStackChunk.UIBasePlane; cacheStackChunk.UIBasePlane = null; } var uiStackChunk = new UIStackChunk(ui, bp, chunk, args); _stack.Push(uiStackChunk); }
public UIStackChunk(string ui, BasePlane bp, UIConfigChunk cc, params object[] args) { UIPath = ui; UIBasePlane = bp; ConfigChunk = cc; Args = args; }
protected void Config(string uiPath, LayerType lt, WindowType wt, ResType rt, OpenType ot, CacheType ct) { _uiConfigChunkDict[uiPath] = new UIConfigChunk(lt, wt, rt, ot, ct); }