/// <summary> /// 定期检查过期UI /// </summary> void CheckRedundantUI_CallBack() { DateTime now = DateTime.Now; //检查冗余窗体 Dictionary <string, DateTime> newList = new Dictionary <string, DateTime>(); foreach (KeyValuePair <string, DateTime> curr in m_wndLastHideTime) { string wndname = curr.Key; Wnd wnd = m_wndInstances[wndname]; wndInfo wInfo = m_wndInfos[wndname]; if ( (now - curr.Value).TotalSeconds > wInfo.cacheTime//超时 ) { DestroyWnd(wnd); } else { newList.Add(curr.Key, curr.Value); } } m_wndLastHideTime = newList; //继续定时 { new MonoEX.Timer(15.0f).Play().OnComplete(CheckRedundantUI_CallBack); } }
public void DestroyWnd(Wnd wnd) { if (OnWndDestroy != null) { try { OnWndDestroy(wnd); } catch (Exception ex) { Debug.LogError(ex); } } wnd.Dispose(); //卸载窗体对象 m_wndInstances.Remove(wnd.Name); //从管理器移除引用 //引用计数减少 { wndInfo wInfo = m_wndInfos[wnd.Name]; foreach (string packet in wInfo.dependPackets) { ResourceRefManage.Single.SubRef(packet); } } }
IEnumerator LoadDepend(string wndName) { if (!m_wndInfos.ContainsKey(wndName)) { throw new Exception(); } wndInfo wInfo = m_wndInfos[wndName]; //加载界面所需资源包 PacketLoader packloader = new PacketLoader(); packloader.Start(PackType.Res, wInfo.dependPackets, null); //等待包装载完成 while (packloader.Wait().MoveNext()) { yield return(null); } //引用计数增加 foreach (string packet in wInfo.dependPackets) { ResourceRefManage.Single.AddRef(packet); } }
static int _CreateWnd(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3) { UnityEngine.GameObject arg0 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 1, typeof(UnityEngine.GameObject)); UnityEngine.GameObject arg1 = (UnityEngine.GameObject)ToLua.CheckUnityObject(L, 2, typeof(UnityEngine.GameObject)); wndInfo arg2 = (wndInfo)ToLua.CheckObject(L, 3, typeof(wndInfo)); Wnd obj = new Wnd(arg0, arg1, arg2); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Wnd.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public Wnd(GameObject panelObj, GameObject baffleObj, wndInfo wInfo) { m_panelObj = panelObj; m_baffleObj = baffleObj; m_wInfo = wInfo; m_wndObj = panelObj.transform.GetChild(0).gameObject; }
/// <summary> /// 获取窗体依赖包 /// </summary> /// <param name="wndName"></param> /// <returns></returns> public HashSet <string> GetDependPackets(List <string> wndNames) { HashSet <string> re = new HashSet <string>(); foreach (string wndName in wndNames) { if (!m_wndInfos.ContainsKey(wndName)) { continue; } wndInfo wInfo = m_wndInfos[wndName]; foreach (string packet in wInfo.dependPackets) { if (!re.Contains(packet)) { re.Add(packet); } } } return(re); }
IEnumerator coDoCmd() { while (m_Cmds.Count > 0) { var aInfo = m_Cmds[0]; m_Cmds.RemoveAt(0); var wndName = aInfo.name; var subID = ""; string[] sArray = aInfo.name.Split('&'); if (sArray.Length == 2) { wndName = sArray[0]; subID = '&' + sArray[1]; } if (!m_wndInfos.ContainsKey(aInfo.name)) { if (sArray.Length == 2) { wndInfo wInfo2 = (wndInfo)m_wndInfos[wndName].Clone(); wInfo2.name = aInfo.name; m_wndInfos.Add(wInfo2.name, wInfo2); } else { Debug.LogError("窗体注册信息不存在 " + wndName); continue; } } if (aInfo.needVisible != WShowType.hide && aInfo.needVisible != WShowType.destroy) { //标记是否第一次打开(包括释放后再打开) bool isFirstShow = false; //从最近隐藏记录中清除 if (m_wndLastHideTime.ContainsKey(wndName + subID)) { m_wndLastHideTime.Remove(wndName + subID); } isFirstShow = !m_wndInstances.ContainsKey(wndName + subID); //窗体不存在,则创建 if (isFirstShow) { IEnumerator it = LoadDepend(wndName); while (it.MoveNext()) { yield return(null); } wndInfo wInfo = m_wndInfos[wndName + subID]; //创建一个uipanel GameObject uipanel = new GameObject(wInfo.name + "_panel"); uipanel.transform.parent = UIRootObj.transform; uipanel.transform.localScale = new Vector3(1, 1, 1); uipanel.transform.localRotation = new Quaternion(0, 0, 0, 1); uipanel.transform.localPosition = new Vector3(0, 0, 0); uipanel.layer = LayerMask.NameToLayer("UI");//设置层 UIPanel cmpanel = uipanel.AddComponent <UIPanel>(); GameObject wnd_Obj = GameObjectExtension.InstantiateFromPacket(wInfo.dependPackets[1], wndName + ".prefab", uipanel); if (wnd_Obj == null) { //删除刚创建的uipanel GameObject.Destroy(uipanel); Debug.LogError(String.Format("实例化窗体错误, packet:{0} wndName:{1}", wInfo.dependPackets[1], wInfo.name)); throw new Exception(); } //设置新创建的panel锚点 { UIRect rectCM = uipanel.GetComponent <UIRect>(); rectCM.SetAnchor(UIRootObj, 0, 0, 0, 0); rectCM.updateAnchors = UIRect.AnchorUpdate.OnStart; } //设置预置锚点 const int safev = 1; { UIRect rectCM = wnd_Obj.GetComponent <UIRect>(); rectCM.SetAnchor(uipanel, -safev, -safev, safev, safev); rectCM.updateAnchors = UIRect.AnchorUpdate.OnStart; } //创建挡板 GameObject uibaffle; { uibaffle = new GameObject(wInfo.name + "_baffle"); uibaffle.layer = LayerMask.NameToLayer("UI");//设置层 uibaffle.transform.parent = uipanel.transform; uibaffle.transform.localScale = Vector3.one; uibaffle.transform.localRotation = Quaternion.identity; uibaffle.transform.localPosition = Vector3.zero; //增加碰撞盒 var cl = uibaffle.AddComponent <BoxCollider>(); //增加UIWidget组件 var cmBaffleWidget = uibaffle.AddComponent <UIWidget>(); cl.isTrigger = true; cmBaffleWidget.autoResizeBoxCollider = true; cmBaffleWidget.updateAnchors = UIRect.AnchorUpdate.OnStart; cmBaffleWidget.SetAnchor(uipanel, -safev, -safev, safev, safev);//设置锚点 cmBaffleWidget.depth = -99; } wnd_Obj.name = wndName + subID; wnd_Obj.SetActive(true); uipanel.SetActive(false); m_wndInstances.Add(wndName + subID, new Wnd(uipanel, uibaffle, wInfo)); if (aInfo.isWithBg)//再加一个gameobject的原因是如果做动画底板需要层级高于预制,底板会压在预制上 { //TODODO 图片放到了Resources目录 UITexture ut = NGUITools.AddWidget <UITexture>(uipanel, -99); Texture texure = Resources.Load <Texture>("zanting_jiashenceng"); ut.mainTexture = texure; UIStretch stretch = ut.gameObject.AddComponent <UIStretch>(); stretch.style = UIStretch.Style.Both; // set relative size bigger stretch.relativeSize = new Vector2(3, 3); } } //显示 Wnd wnd = m_wndInstances[wndName + subID]; if (aInfo.needVisible == WShowType.preLoad) { yield return(null); Wnd.OnPreLoadFinish.Call(wnd); } else if (aInfo.needVisible == WShowType.show) { wnd._Show(aInfo.duration); //等待窗体组件准备就绪 yield return(null); if (isFirstShow) { Wnd.OnShowFinish.Call(wnd); } else { Wnd.OnReOpenWnd.Call(wnd); } if (OnWndOpen != null) { OnWndOpen.Call(wndName); } } } else { if (m_wndInstances.ContainsKey(wndName + subID)) { //从最近隐藏记录中清除 if (aInfo.needVisible == WShowType.destroy && m_wndLastHideTime.ContainsKey(wndName + subID)) { m_wndLastHideTime.Remove(wndName + subID); } Wnd wnd = m_wndInstances[wndName + subID]; wnd._Hide(aInfo.duration, aInfo.needVisible, aInfo.PlantfromDetph); if (aInfo.needVisible == WShowType.hide) { Wnd.OnHideFinish.Call(wnd); } else if (aInfo.needVisible == WShowType.destroy) { Wnd.OnDestroyFinish.Call(wnd); } } } yield return(null); } m_coIsRuning = false; }