/// <summary> /// 移除该精灵引用的次数,如果该图集中精灵数量超过30,则释放该精灵资源 /// </summary> /// <param name="atlasName"></param> /// <param name="textureName"></param> /// <param name="callBack"></param> public void RemoveRefCount(string atlasName, string textureName, DynamicAtlasManager.PrepareAtlasCallBack callBack) { if (this.ContainsTexture(atlasName, textureName)) { this.m_dicUIAtlas[atlasName].RemoveRefCount(textureName, callBack); } }
/// <summary> /// 增加该精灵引用次数 /// </summary> /// <param name="atlasName"></param> /// <param name="textureName"></param> /// <param name="callBack"></param> public void AddRefCount(string atlasName, string textureName, DynamicAtlasManager.PrepareAtlasCallBack callBack) { if (string.IsNullOrEmpty(atlasName) || string.IsNullOrEmpty(textureName)) { return; } //如果不存在该图集,就动态创建一个图集 if (!this.m_dicUIAtlas.ContainsKey(atlasName)) { this.m_dicUIAtlas[atlasName] = new DynamicAtlas(atlasName); } this.m_dicUIAtlas[atlasName].AddRefCount(textureName, callBack); }
/// <summary> /// 增加精灵引用次数,如果不存在就动态创建加载 /// </summary> /// <param name="texName"></param> /// <param name="callBack"></param> public void AddRefCount(string texName, DynamicAtlasManager.PrepareAtlasCallBack callBack) { if (string.IsNullOrEmpty(texName)) { return; } //如果该动态图集不存在该精灵,就创建一个该精灵 if (!this.m_dicSpriteEntrys.ContainsKey(texName)) { this.m_dicSpriteEntrys[texName] = new DynamicAtlas.SpriteEntry(texName); } //精灵引用次数加一 this.m_dicSpriteEntrys[texName].AddRef(); if (this.m_dicSpriteEntrys[texName].IsPrepared) { if (callBack != null) { try { callBack(this.AtlasName, texName, this.m_uiAtlas); } catch (Exception exception) { Debug.LogException(exception); } } } else { if (callBack != null) { //如果精灵准备好的回调函数不为空的话,就加入到缓存中 if (!this.m_dicPrepareCallBack.ContainsKey(texName)) { this.m_dicPrepareCallBack[texName] = callBack; } else { DynamicAtlasManager.PrepareAtlasCallBack a = this.m_dicPrepareCallBack[texName]; this.m_dicPrepareCallBack[texName] = (DynamicAtlasManager.PrepareAtlasCallBack)Delegate.Combine(a, callBack); } } //加载该精灵资源 if (!this.m_dicAssetRequestTexture.ContainsKey(texName)) { string url = string.Format("Texture/{0}/{1}", this.m_strAtlasName, texName); IAssetRequest value = XUITool.Instance.LoadResAsyn(url, new AssetRequestFinishedEventHandler(this.OnLoadTextureFinished), AssetPRI.DownloadPRI_Low); this.m_dicAssetRequestTexture[texName] = value; } } }
/// <summary> /// 移除该精灵引用 /// </summary> /// <param name="texName"></param> /// <param name="callBack"></param> public void RemoveRefCount(string texName, DynamicAtlasManager.PrepareAtlasCallBack callBack) { if (this.m_dicPrepareCallBack.ContainsKey(texName)) { Delegate.Remove(this.m_dicPrepareCallBack[texName], callBack); } else { Debug.LogError("m_dicPrepareCallBack.ContainsKey(texName) == false:" + texName); } this.m_dicSpriteEntrys[texName].DelRef(); //当图集中精灵数量超过30张,并且该精灵没有被引用,就释放该精灵 if (this.m_dicSpriteEntrys[texName].refCount <= 0 && this.m_dicSpriteEntrys.Count > 30) { this.ReleaseExtraSprites(); } }