/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="layerName">layer to host this window</param> /// <param name="neverClose">can the window be close</param> /// <param name="isCache">whether cache, if not,after window close,we will destroy it</param> /// <param name="onWindowShowed"></param> /// <param name="datas"></param> /// <returns></returns> public Window ShowWindow(string name, string layerName, bool neverClose, bool isCache, Action onWindowShowed, params object[] datas) { WindowResSource source = WindowResSource.Unknown; Window window = genTargetWindow(name, ref source); window.isCache = isCache; window.neverClose = neverClose; if (source == WindowResSource.Cache) { updateCachedWindows(window, false); updateOpenedWindows(window, true); } else if (source == WindowResSource.Newborn) { updateOpenedWindows(window, true); } //set parent layer GameObject windowObj = window.rootObj; windowObj.transform.SetParent(LayerDic[layerName]); window.Show(layerName, datas); onWindowShowed?.Invoke(); return(window); }
/// <summary> /// /// </summary> /// <param name="windowName"></param> /// <param name="source"></param> /// <returns></returns> Window genTargetWindow(string windowName, ref WindowResSource source) { WindowInfo info = null; WindowInfos.TryGetValue(windowName, out info); if (info == null) { Debug.LogError("error, " + windowName + " is not registed"); return(null); } Window target = null; if (openedWindows.ContainsKey(windowName)) { Debug.LogError("window: " + windowName + ", has already opened!"); source = WindowResSource.Opened; target = openedWindows[windowName]; } else { if (cachedWindows.ContainsKey(windowName)) { source = WindowResSource.Cache; target = cachedWindows[windowName]; } else { GameObject uiObj = null; if (windowResType == WindowResType.AssetBundle) { uiObj = ABManager.Instance.LoadWindow(info.resName); } else if (windowResType == WindowResType.Prefab) { uiObj = ResHelper.Instance.LoadModel("Window/" + info.resName); } source = WindowResSource.Newborn; if (info.isLuaWindow) { target = new LuaBridgeWindow(uiObj, windowName); } else { Type t = Type.GetType(windowName); target = Activator.CreateInstance(t, new object[] { uiObj, windowName }) as Window; } } } if (target == null) { source = WindowResSource.Unknown; Debug.LogError("can not get target window:" + windowName); } return(target); }