private WindowRequest loadWindowAsync(string windowName) { WindowRequest wr = new WindowRequest(); wr.source = WindowResSource.Unknown; ZGame.Res.AsyncOperation ao = new ZGame.Res.AsyncOperation(); wr.source = WindowResSource.Newborn; if (windowResType == WindowResType.AssetBundle) { //uiObj = ABManager.Instance.LoadWindow(info.resName); } else if (windowResType == WindowResType.Prefab) { ResHelper.Instance.LoadModelAsync("Window/" + windowName, (uiObj) => { Type t = Type.GetType(windowName); Window target = Activator.CreateInstance(t, new object[] { uiObj, windowName }) as Window; wr.asset = target; ao.isDone = true; wr.OnComplete(ao); }); } return(wr); }
public void ShowWindowAsync(string name, string layerName, bool neverClose, bool isCache, Action onWindowShowed, params object[] datas) { //TODO:forbidUIListener WindowRequest wr = genTargetWindowAsync(name); wr.onCompleted += (ao) => { if (ao.isDone) { Window window = wr.asset as Window; window.isCache = isCache; window.neverClose = neverClose; if (wr.source == WindowResSource.Cache) { updateCachedWindows(window, false); updateOpenedWindows(window, true); } else if (wr.source == WindowResSource.Newborn) { updateOpenedWindows(window, true); } GameObject windowObj = window.rootObj; windowObj.transform.SetParent(LayerDic[layerName]); window.Show(layerName, datas); if (onWindowShowed != null) { onWindowShowed(); } } }; }
WindowRequest genTargetWindowAsync(string windowName) { WindowRequest wr = new WindowRequest(); wr.source = WindowResSource.Unknown; ZGame.Res.AsyncOperation ao = new ZGame.Res.AsyncOperation(); WindowInfos.TryGetValue(windowName, out WindowInfo info); if (info == null) { Debug.LogError("error, " + windowName + " is not registed"); wr.source = WindowResSource.Unknown; return(wr); } Window target = null; if (openedWindows.ContainsKey(windowName)) { Debug.LogError("window: " + windowName + ", has already opened!"); wr.source = WindowResSource.Opened; target = openedWindows[windowName]; wr.asset = target; ao.isDone = true; wr.OnComplete(ao); return(wr); } else { if (cachedWindows.ContainsKey(windowName)) { wr.source = WindowResSource.Cache; target = cachedWindows[windowName]; wr.asset = target; ao.isDone = true; wr.OnComplete(ao); return(wr); } else { return(loadWindowAsync(windowName)); } } }