private void _addAsbInfo(string asbName, string name, string extral, bool isOrdered) { if (null == OnLoadCallbcak) { return; } AsbInfo info = ObjPools.GetAsbInfo(); info.Set(asbName, name, extral); if (isOrdered) { if (!mQueue.Contains(info)) { mQueue.Enqueue(info); return; } } else { if (!mList.Contains(info)) { mList.Add(info); return; } } //如果已经在list或者队列里则回收 ObjPools.Recover(info); return; }
/// <summary> /// 从prefab显示UI,慎用,建议使用ShowView /// </summary> /// <param name="prefab">Prefab.</param> /// <param name="luaTable">Lua table.</param> /// <param name="asbName">Asb name.</param> /// <param name="prefabName">Prefab name.</param> public void ShowViewPrefab(GameObject prefab, LuaTable luaTable = null, string asbName = null, string prefabName = null) { if (null != prefab) { GameObject uiObj = Instantiate(prefab); UIBase ui = uiObj.GetComponent <UIBase>(); if (null != luaTable) { ui.SetLuaStatusListeners(luaTable); } _addUIObj(ui); if (ui.IsStatic) { if (mStaticViewInfos.Count == mStaticViews.Count) { AsbInfo info = ObjPools.GetAsbInfo(); info.Set(asbName, prefabName); mStaticViewInfos.Add(info); mStaticViews.Add(ui); } else { LogFile.Error("GameUIManager error ==> showViewPrefab mStaticViewInfos.Count != mStaticViews.Count"); } } //要显示UI先SetActive(true),防止有UIprefab中没有启用,不会进入Start方法 uiObj.SetActive(true); //UI初始化后才Show(播放显示动画) ui.OnInitCallbcak = (bool hasInit) => { if (ui.IsInStack) { if (ui.HideBefor && mStackViews.Count > 0) { UIBase curView = mStackViews.Peek(); if (curView.isActiveAndEnabled) { HideView(curView, (bool ret) => { _pushUI(ui as UIView); ShowViewObj(ui, null); }); return; } } //之前的UI隐藏或者本UI被设置为不隐藏之前的UI则不隐藏之前的UI直接push { _pushUI(ui as UIView); ShowViewObj(ui, null); } } else { ShowViewObj(ui, null); } }; } }
private void _onLoadPrefab(GameObject prefab, AsbInfo info) { LuaTable table = null; if (!string.IsNullOrEmpty(info.extral) && mViewListeners.TryGetValue(info.extral, out table)) { mViewListeners.Remove(info.extral); } ShowViewPrefab(prefab, table, info.asbName, info.assetName); }
/// <summary> /// 当有AudioClip被加载的回调 /// </summary> /// <param name="audioClip">Arg1.</param> /// <param name="info">Arg2.</param> private void _onAudioClipLoad(AudioClip audioClip, AsbInfo info) { if (info.extral.Equals(STR_BGM)) { //异步的快速播放,想要淡入淡出可以后期做优化 _playBgm(audioClip, 0f); } else if (info.extral.Equals(STR_SOUND)) { _playSound(audioClip); } }
private bool _onLoad(string asbName, string assetName, T t) { bool ret = mDict.AddObj(asbName, assetName, t); if (null != OnLoadCallbcak) { if (mList.Count > 0) { for (int i = mList.Count - 1; i > -1; --i) { AsbInfo info = mList[i]; if (info.Equals(asbName, assetName)) { OnLoadCallbcak(t, info); mList.Remove(info); ObjPools.Recover(info); } } } if (mQueue.Count > 0) { AsbInfo info = mQueue.Peek(); if (info.Equals(asbName, assetName)) { OnLoadCallbcak(t, info); mQueue.Dequeue(); ObjPools.Recover(info); for (int i = 0; i < mQueue.Count; i++) { AsbInfo head = mQueue.Peek(); T obj = Get(head.asbName, head.assetName); if (null != obj) { OnLoadCallbcak(obj, head); mQueue.Dequeue(); ObjPools.Recover(head); } else { //不是调用序列的第一个直接返回 return(ret); } } } } } return(ret); }
public static bool Recover(AsbInfo obj) { checkInit(); return(sPoolAsbInfo.Recover(obj)); }
public static void Init() { //sDict = new Dictionary<string, System.Object>(); sPoolLS = new ObjPool <List <string> >( delegate(ref List <string> l) { if (null == l) { l = new List <string>(); } else { l.Clear(); } return(true); } , delegate(List <string> l) { l.Clear(); return(true); } ); //sDict[listStr.GetType().ToString()] = listStr; sPoolLI = new ObjPool <List <int> >( delegate(ref List <int> l) { if (null == l) { l = new List <int>(); } else { l.Clear(); } return(true); } , delegate(List <int> l) { l.Clear(); return(true); } ); //sDict[listInt.GetType().ToString()] = listInt; sPoolLF = new ObjPool <List <float> >( delegate(ref List <float> l) { if (null == l) { l = new List <float>(); } else { l.Clear(); } return(true); } , delegate(List <float> l) { l.Clear(); return(true); } ); //sDict[listFloat.GetType().ToString()] = listFloat; sPoolLB = new ObjPool <List <bool> >( delegate(ref List <bool> l) { if (null == l) { l = new List <bool>(); } else { l.Clear(); } return(true); } , delegate(List <bool> l) { l.Clear(); return(true); } ); sPoolAsbInfo = new ObjPool <AsbInfo>( delegate(ref AsbInfo info) { if (null == info) { info = new AsbInfo(); } return(true); } , null ); //sDict[asbInfo.GetType().ToString()] = asbInfo; }