/// <summary> /// 关闭一个系统的窗口 /// </summary> /// <param name="winName"></param> /// <param name="isPlayMainMapAni"></param> public void CloseSysWindow(string winName, bool isPlayMainMapAni = true) { UIBaseWindow win = null; win = this.GetWindow(winName); //mWindows.TryGetValue(winName, out win); if (mOpeningSysWin.Contains(winName)) { mOpeningSysWin.Remove(winName); } if (win == null) { return; } ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CLOSE_SYS_WIN, new CEventBaseArgs(winName)); // 如果在弹出当前窗口的时候,打开了其他系统窗口,则不需要显示主UI bool open_other_sys_window = UINavgationCtrl.Instance.Pop(winName); if (!open_other_sys_window && isPlayMainMapAni && winName.CompareTo(MainPanelName) != 0 && UINavgationCtrl.Instance.GetStackLen() == 0) { if (IsOpeningSysWinExceptMainmapWin() == false) { ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_MAINMAP_SWITCH_ANIMATION, new CEventBaseArgs(true)); } } UpdateSysUIMaskBg(); ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CLOSE_WIN, new CEventBaseArgs(winName)); }
public void CreateAndCheckRefundBtn(UIBaseWindow baseWin, GameObject parentGo, string windName, float scale, bool is_force_update) { if (Const.Region != RegionType.KOREA) { return; } if (baseWin == null) { return; } string param1_str = ""; if (baseWin.ShowParam != null && baseWin.ShowParam.Length > 0 && baseWin.ShowParam[0] != null) { param1_str = baseWin.ShowParam[0].ToString(); } if (is_force_update || (baseWin.Param1_str != param1_str)) { baseWin.Param1_str = param1_str; if (baseWin.RefundBtnObj != null) { GameObject.DestroyImmediate(baseWin.RefundBtnObj); } baseWin.RefundBtnObj = UIWidgetHelp.Instance.CreateAndCheckRefundBtn(parentGo, windName, scale, param1_str); } }
/// <summary> /// 打开一个系统的窗口 /// </summary> /// <param name="winName">窗口的名字</param> /// <param name="mainmap_switch">是否触发主UI的动画</param> /// <param name="param">窗口的参数</param> public void ShowSysWindowEx(string winName, bool mainmap_switch, params object[] param) { if (CheckWindowDownloaded(winName) == false) { return; } if (ModalWindow != null && ModalWindow.IsShow) { GameDebug.LogWarning(string.Format("当前有模态窗口{0}打开,所以{1}无法打开", ModalWindow.mWndName, winName)); } UIBaseWindow win = null; mWindows.TryGetValue(winName, out win); // 显示其他窗口的时候,需要发消息触发主UI的关闭动画 if (winName.CompareTo(MainPanelName) != 0 && (win == null || (win != null && win.IsShow == false))) { if (mainmap_switch) { if (IsOpeningSysWinExceptMainmapWin() == false) { ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CE_MAINMAP_SWITCH_ANIMATION, new CEventBaseArgs(false)); } } } // 当前需要显示的是主UI时,需要将IsBackMainMapShowWin指定的窗口也显示出来 else if (winName.CompareTo(MainPanelName) == 0 && IsBackMainMapShowWin.CompareTo("") != 0 && SceneHelp.Instance.IsInInstance == false) { ShowSysWindow(IsBackMainMapShowWin); } ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.OPEN_SYS_WIN, new CEventBaseArgs(winName)); UINavgationCtrl.Instance.Push(winName, param); mWindows.TryGetValue(winName, out win); if (win != null) { win.IsSystemWindow = true; win.IsMainmapSwitch = mainmap_switch; } if (winName != "UIChatWindow") //聊天框特殊处理,不算作系统窗口 { mOpenedSysWindow[winName] = true; } if (!mOpeningSysWin.Contains(winName)) { mOpeningSysWin.Add(winName); } UpdateSysUIMaskBg(); }
/// <summary> /// 移除动态面板所在层级的堆栈信息 /// </summary> /// <param name="win"></param> public void RemoveWindowDynOrder(UIBaseWindow win) { if (win.staticLayerIndex != -1) { return; } UILayerInfo info = this.GetLayerInfo(win.WindowType); info.RemoveDynamicLayerIndex(win); }
public UILuaBehaviour(UIBaseWindow win, string lua_script) { Window = win; mLuaScript = lua_script; mLuaTable = LuaScriptMgr.Instance.Require(lua_script) as LuaTable; if (!CallLuaFunc <IUIBehaviour>("ctor", (IUIBehaviour)this)) { GameDebug.LogError(string.Format("({0}) Must Define ctor Function!", lua_script)); } }
/// <summary> /// 拿这个面板所在层级的新的动态层次 /// </summary> /// <param name="win"></param> /// <returns></returns> public int GetNewDynamicLayerIndex(UIBaseWindow win) { if (win.staticLayerIndex != -1) { return(win.staticLayerIndex); } string wndName = win.mWndName; if (dynLayerStack.Count == 0) { DynamicLayerIndexStackInfo first = new DynamicLayerIndexStackInfo(); first.index = layerDynMin; first.windowName = wndName; dynLayerStack.Add(first); return(first.index); } var info = GetDynLayerInfo(wndName); var top = dynLayerStack[dynLayerStack.Count - 1]; if (info == null) { //没有取栈顶index info = new DynamicLayerIndexStackInfo(); info.index = top.index + DYN_INTERN; info.windowName = wndName; dynLayerStack.Add(info); } else { //有的话移动到栈顶 if (top != info) { int topIndex = top.index + DYN_INTERN; info.index = topIndex; dynLayerStack.Remove(info); dynLayerStack.Add(info); } } return(info.index); }
/// <summary> /// 根据传入的layer强制设置window层级 /// </summary> /// <param name="winName">window名字</param> /// <param name="layer">window层级</param> /// <param name="param">window参数</param> public void ShowWindowLayer(string winName, int layer, params object[] param) { ShowWindow(winName, param); UIBaseWindow baseWindow = null; mWindows.TryGetValue(winName, out baseWindow); if (baseWindow != null && layer != 0) { baseWindow.SetLayerDirectIndex(layer); } }
/// <summary> /// 在面板显示之前和初始化之前设置好面板的层级,动态层级的前后关系由ShowWindow的调用顺序来决定,每个层级会有10个层的间隔用来给粒子特效使用 /// </summary> /// <param name="baseWin"></param> public void SetWindowDynOrder(UIBaseWindow baseWin) { //静态面板不设置 if (baseWin.staticLayerIndex != -1) { return; } UILayerInfo info = this.GetLayerInfo(baseWin.WindowType); int index = info.GetNewDynamicLayerIndex(baseWin); baseWin.SetDynamicLayerIndex(index); }
/// <summary> /// 删除掉这个面板的动态层级 /// </summary> /// <param name="win"></param> /// <returns></returns> public void RemoveDynamicLayerIndex(UIBaseWindow win) { if (win.staticLayerIndex != -1) { return; } var info = this.GetDynLayerInfo(win.mWndName); if (info == null) { return; } this.dynLayerStack.Remove(info); }
public static Material LoadMaterialByBaseWindow(UIBaseWindow win, string materialName) { if (win == null) { GameDebug.LogError("UIHelper.LoadMaterialByBaseWindow UIBaseWindow is null"); return(null); } if (win.mUIObject == null) { return(null); } CanvasInfo info = win.mUIObject.GetComponent <CanvasInfo>(); if (info == null) { GameDebug.LogError(string.Format("UIHelper.LoadMaterialByBaseWindow {0} CanvasInfo is null", win.mWndName)); return(null); } return(info.LoadMaterial(materialName)); }
public static AudioClip LoadAudioClipByBaseWindow(UIBaseWindow win, string audioClipName) { if (null == win) { GameDebug.LogError("UIHelper.LoadAudioClipByBaseWindow UIBaseWindow is null"); return(null); } if (null == win.mUIObject) { return(null); } SoundInfo info = win.mUIObject.GetComponent <SoundInfo>(); if (null == info) { GameDebug.LogError(string.Format("UIHelper.LoadAudioClipByBaseWindow {0} CanvasInfo is null", win.mWndName)); return(null); } return(info.LoadAudioClip(audioClipName)); }
/// <summary> /// 关闭窗口 /// </summary> /// <param name="name"></param> public void CloseWindow(string name) { string info = string.Format("close window: {0}", name); BuglyAgent.PrintLog(LogSeverity.LogInfo, info); //************************************ // 这里调用navgationctr 处理面板的队列已经面板的zOrder以及SetSiblingIndex //************************************ UIBaseWindow baseWin; if (mWindows.TryGetValue(name, out baseWin)) { //把资源没有下载完成的面板加入关闭列表,资源下载完成时自动关闭 for (int i = 0; i < baseWin.SubWindow.Count; i++) { string subWindow = baseWin.SubWindow[i]; if (loadingWindows.ContainsKey(subWindow) && !needCloseWindowsAfterResLoad.Contains(subWindow)) { needCloseWindowsAfterResLoad.Add(subWindow); } } if (loadingWindows.ContainsKey(name) && !needCloseWindowsAfterResLoad.Contains(name)) { needCloseWindowsAfterResLoad.Add(name); RemoveWindowDynOrder(baseWin); return; } if (!baseWin.IsShow) { return; } baseWin.Close(); if (baseWin.IsModal) { ModalWindow = null; } //查找是否含有子面板 并且保存 baseWin.BackupOpenSubWindows.Clear(); for (int i = 0; i < baseWin.SubWindow.Count; i++) { string winName = baseWin.SubWindow[i]; UIBaseWindow subWindw = null; mWindows.TryGetValue(winName, out subWindw); if (subWindw != null) { if (subWindw.IsShow && winName != "UIGoodsTipsWindow" && winName != "UIEquipmentTipsWindow") { UIBaseWindow.BackupWin back_struct = new UIBaseWindow.BackupWin(); back_struct.WinName = winName; back_struct.ShowParam = subWindw.ShowParam; baseWin.BackupOpenSubWindows.Add(back_struct); } subWindw.Close(); } } ClientEventMgr.GetInstance().FireEvent((int)ClientEvent.CLOSE_WIN, new CEventBaseArgs(name)); } }
//************************************ // 打开单个指定面板(不包含子面板) //************************************ public void ShowWindow(string winName, params object[] param) { if (MainCtrl == null) { return; } if (CheckWindowDownloaded(winName) == false) { return; } if (ModalWindow != null && ModalWindow.IsShow) { GameDebug.LogWarning(string.Format("当前有模态窗口{0}打开,所以{1}无法打开", ModalWindow.mWndName, winName)); } if (loadingWindows.ContainsKey(winName)) { GameDebug.Log("当前窗口正在加载中:" + winName); if (needCloseWindowsAfterResLoad.Contains(winName)) { needCloseWindowsAfterResLoad.Remove(winName); SetWindowDynOrder(GetExistingWindow(winName)); } return; } string info = string.Format("show window: {0}", winName); BuglyAgent.PrintLog(LogSeverity.LogInfo, info); UIBaseWindow baseWin = null; if (mWindows.TryGetValue(winName, out baseWin)) { if (baseWin.WinState == WinowState.ResLoadDone) { baseWin.ShowParam = param; if (MainCtrl != null) { MainCtrl.CreateAndCheckMoneyBar(baseWin, baseWin.mUIObject, winName, baseWin.CurrencyScale, false); //创建概率公示按钮 MainCtrl.CreateAndCheckProbabilityBtn(baseWin, baseWin.mUIObject, winName, baseWin.CurrencyScale, false); //创建七日退款按钮 MainCtrl.CreateAndCheckRefundBtn(baseWin, baseWin.mUIObject, winName, baseWin.CurrencyScale, false); } baseWin.Show(); } } else { #if !DISABLE_LUA string lua_script = ""; string path = UIHelper.GetLuaWindowPath(winName); if (path.CompareTo(string.Empty) == 0) { lua_script = string.Format("newUI.{0}", winName); } else { lua_script = string.Format("newUI.{0}.{1}", path, winName); } //Debug.Log(lua_script); if (IsLuaScriptExist(lua_script)) { baseWin = new UILuaBaseWindow(winName, lua_script); } else #endif { System.Type t = System.Type.GetType("xc.ui.ugui." + winName); if (t != null) { if (t.IsSubclassOf(typeof(UIBaseWindow))) { baseWin = (UIBaseWindow)System.Activator.CreateInstance(t); } else { GameDebug.Log("use reflection create ugui panel :" + winName); FieldInfo prefabNameField = t.GetField("mWndName", BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Public); if (prefabNameField == null) { Debug.LogError(string.Format("the type {0} should cantains a static string field named mPrefabName", t)); return; } string prefabName = prefabNameField.GetValue(null) as string; baseWin = new UIBaseWindow(prefabName); } } } if (baseWin == null) { Debug.LogError("UIManager.CreateWindow error:" + winName); return; } if (baseWin.WinState == WinowState.ResNoLoad) { ///这里如果面板时动态的,则预先计算好动态层级 this.SetWindowDynOrder(baseWin); baseWin.ShowParam = param; mWindows.Add(winName, baseWin); baseWin.WinState = WinowState.ResLoading; loadingWindows.Add(winName, true); MainCtrl.StartCoroutine(MainCtrl.CreateWindowFromPrefab(baseWin.mWndName, baseWin)); } } if (baseWin != null) { baseWin.IsSystemWindow = false; } // 如果之前已经设置为true,而在Pop窗口的时候会又调用ShowWindow // 此处需要判断下之前是否设置过 if (!mOpenedSysWindow.ContainsKey(winName)) { mOpenedSysWindow[winName] = false; } }
/// <summary> /// 面板资源完成的回调 /// </summary> /// <param name="args"></param> private void OnResourceLoadDone(xc.ClientEventBaseArgs args) { if (args.Arg == null) { return; } UIBaseWindow baseWin = (UIBaseWindow)args.Arg; //移除加载窗口 loadingWindows.Remove(baseWin.mWndName); //如果资源加载发现字典没有改面板表面是野窗口 if (mWindows.ContainsValue(baseWin) == false) { // 如果在字典中找不到,则说明之前进行了销毁操作,不需要再次调用Destroy @fix by raorui //baseWin.Destroy(); DestroyWindowGameObject((GameObject)baseWin.mUIObject); return; } //断线重连中直接销毁窗口 if (NetReconnect.Instance.IsReconnect && baseWin.mWndName != "UIAutoConnectWindow") { DestroyWindowGameObject((GameObject)baseWin.mUIObject); if (needCloseWindowsAfterResLoad.Contains(baseWin.mWndName)) { needCloseWindowsAfterResLoad.Remove(baseWin.mWndName); } if (mWindows.ContainsKey(baseWin.mWndName)) { mWindows.Remove(baseWin.mWndName); } return; } //************************************ // 资源加载完开始初始化数据调用InitData 跟show同时调整Zorder //************************************ //AddZOrder(baseWin); //var go = baseWin.mUIObject; //go.SetActive(true); baseWin.InitData(); if (ModalWindow != null && ModalWindow.mWndName != baseWin.mWndName) { return; } if (baseWin.IsModal)//模態窗口衹能唯一如果未銷毀不會打開新的模態 { ModalWindow = baseWin; } baseWin.Show(); for (int i = 0; i < needCloseWindowsAfterResLoad.Count; i++) { if (baseWin.mWndName == needCloseWindowsAfterResLoad[i]) { needCloseWindowsAfterResLoad.RemoveAt(i); CloseWindow(baseWin.mWndName); return; } } }
/// <summary> /// 加载UI资源 /// </summary> /// <param name="wndName"></param> /// <param name="baseWin"></param> /// <returns></returns> public IEnumerator CreateWindowFromPrefab(string wndName, UIBaseWindow baseWin) { float start_time = Time.unscaledTime; if (delay > 0) { yield return(new WaitForSeconds(delay)); } bool _reserve_asset = (wndName == UIManager.MainPanelName); // 是否保存ui界面的assetbundle资源 // 根据窗口类型设置不同的挂点 UIType type = UIHelper.GetUITypeByWindowName(wndName); Transform parent_trans = null; switch (type) { case UIType.Hud: { parent_trans = mHudRoot; break; } case UIType.Pop: { parent_trans = mPopRoot; break; } case UIType.Normal: { parent_trans = mNormalRoot; break; } default: { //只有loading parent_trans = mLoadingRoot; break; } } // 加载ui界面 PrefabResource pr = new PrefabResource(); var res_prefix = UIResPrefix; // if (Const.Language == LanguageType.KOREAN) // { // res_prefix = UIKoreanResPrefix; // } #if UNITY_IPHONE if (string.IsNullOrEmpty(baseWin.mPrefabName) == false && SDKHelper.GetSDKWinList().Contains(baseWin.mPrefabName)) { res_prefix = UICopyBagResPrefix; } #endif if (baseWin.mPrefabName != null) { yield return(StartCoroutine(ResourceLoader.Instance.load_prefab(string.Format("{0}{1}.prefab", res_prefix, baseWin.mPrefabName), pr, false, _reserve_asset, parent_trans))); } else { yield return(StartCoroutine(ResourceLoader.Instance.load_prefab(string.Format("{0}{1}.prefab", res_prefix, wndName), pr, false, _reserve_asset, parent_trans))); } GameObject obj = pr.obj_; if (obj == null) { yield break; } //设置Canvas组件的参数 Canvas canvas = obj.GetComponent <Canvas>(); if (canvas == null) { Debug.LogError("ui not have canvas " + wndName); canvas = obj.AddComponent <Canvas>(); } //canvas.pixelPerfect = true; canvas.renderMode = RenderMode.ScreenSpaceCamera; canvas.worldCamera = mCam; //canvas.additionalShaderChannels = AdditionalCanvasShaderChannels.None;// AdditionalCanvasShaderChannels.TexCoord1;// | AdditionalCanvasShaderChannels.Tangent; canvas.sortingLayerName = "Default"; // 检查GraphicRaycaster组件 var ray_caster = obj.GetComponent <GraphicRaycaster>(); if (ray_caster == null) { Debug.LogError("ui not have canvas raycaster " + wndName); obj.AddComponent <GraphicRaycaster>(); } // 设置CanvasScaler组件的参数 var canvas_scaler = obj.GetComponent <CanvasScaler>(); if (canvas_scaler == null) { Debug.LogError("ui not have canvas scalar " + wndName); canvas_scaler = obj.AddComponent <CanvasScaler>(); } canvas_scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; canvas_scaler.referencePixelsPerUnit = 100; float currency_scale = 1; currency_scale = canvas_scaler.referenceResolution.x / 1920; if (canvas_scaler.referenceResolution.x != 1920 && canvas_scaler.referenceResolution.x != 1334) { canvas_scaler.referenceResolution = new Vector2(1280, 720); } if (Screen.width / (float)Screen.height > 1.778f) { canvas_scaler.matchWidthOrHeight = 1; } else { canvas_scaler.matchWidthOrHeight = 0; } baseWin.CurrencyScale = currency_scale; // 设置界面的外部参数 string param1_str = ""; if (baseWin.ShowParam != null && baseWin.ShowParam.Length > 0 && baseWin.ShowParam[0] != null) { param1_str = baseWin.ShowParam[0].ToString(); } baseWin.Param1_str = param1_str; obj.transform.localPosition = Vector3.zero; obj.transform.localScale = Vector3.one; if (!obj.activeSelf) { obj.SetActive(true); } obj.name = obj.name.Replace("(Clone)", ""); baseWin.mUIObject = obj; //从ui加载出来的原始prefab有标志Atlas资源是否可以被回收的作用,不能删除,详见host_res_to_gameobj的代码 //GameObject.Destroy(obj); float cost_time = Time.unscaledTime - start_time; // 创建界面的货币栏 if (mCurrencyRes == null) { mCurrencyRes = new PrefabResource(); yield return(StartCoroutine(ResourceLoader.Instance.load_prefab("Assets/Res/UI/Widget/Preset/UICurrencyWindow.prefab", mCurrencyRes, true))); if (mCurrencyRes.obj_ == null) { yield break; } mCurrencyRes.obj_.SetActive(false); } CreateAndCheckMoneyBar(baseWin, obj, wndName, currency_scale, true); if (Const.Region == RegionType.KOREA) { //创建概率展示按钮 if (mProbabilityRes == null) { mProbabilityRes = new PrefabResource(); yield return(StartCoroutine(ResourceLoader.Instance.load_prefab( "Assets/Res/UI/Widget/Preset/UIProbabilityPublish.prefab", mProbabilityRes, true))); if (mProbabilityRes.obj_ == null) { yield break; } mProbabilityRes.obj_.SetActive(false); } CreateAndCheckProbabilityBtn(baseWin, obj, wndName, currency_scale, true); //创建七日退款按钮 if (mRefundRes == null) { mRefundRes = new PrefabResource(); yield return(StartCoroutine(ResourceLoader.Instance.load_prefab( "Assets/Res/UI/Widget/Preset/UIPolicyStatement.prefab", mRefundRes, true))); if (mRefundRes.obj_ == null) { yield break; } mRefundRes.obj_.SetActive(false); } CreateAndCheckRefundBtn(baseWin, obj, wndName, currency_scale, true); } //Debug.LogError("load window " + wndName + " cost: " + cost_time); xc.ClientEventManager <ClientEventType.ugui.UICoreEvent> .Instance.FireEvent(ClientEventType.ugui.UICoreEvent.UILOADDONE, new xc.ClientEventBaseArgs(baseWin)); }
public virtual void DestroyBehaviour() { isInit = false; Window = null; }