public void GetTeture(string name, OnCallBackTexRect callback) { if (m_UsingTexture.ContainsKey(name)) { if (callback != null) { SaveTextureData data = m_UsingTexture[name]; data.referenceCount++; Texture2D tex2D = m_PageList[data.texIndex].texture; callback(tex2D, data.rect); } } else { //FIXME! 这里需要改成自己的加载方式 var texture = Resources.Load <Texture2D>(name); //--------------- if (texture == null) { Debug.LogError("Failed To load Texture:" + name); callback(null, new Rect(0, 0, 0, 0)); return; } GetTextureData data = DynamicAtlasMgr.S.AllocateGetTextureData(); data.name = texture.name; data.callback = callback; m_GetTextureTaskList.Add(data); OnRenderTexture(data.name, texture); } }
private void OnRenderTexture(string name, Texture2D texture2D) { if (texture2D == null) { for (int i = m_GetTextureTaskList.Count - 1; i >= 0; i--) { GetTextureData task = m_GetTextureTaskList[i]; if (task.name.Equals(name)) { if (task.callback != null) { task.callback(null, new Rect(0, 0, 0, 0)); } } DynamicAtlasMgr.S.ReleaseGetTextureData(task); m_GetTextureTaskList.RemoveAt(i); } return; } int index = 0; IntegerRectangle useArea = InsertArea(texture2D.width, texture2D.height, out index); // Debug.LogError(name + ":Index:" + index); if (useArea == null) { Debug.LogError("No Area"); return; } Rect uv = new Rect((useArea.x), (useArea.y), texture2D.width, texture2D.height); m_PageList[index].AddTexture(useArea.x, useArea.y, texture2D); SaveTextureData saveTextureData = DynamicAtlasMgr.S.AllocateSaveTextureData(); saveTextureData.texIndex = index; saveTextureData.rect = uv; m_UsingTexture[name] = saveTextureData; for (int i = m_GetTextureTaskList.Count - 1; i >= 0; i--) { GetTextureData task = m_GetTextureTaskList[i]; if (task.name.Equals(name)) { m_UsingTexture[name].referenceCount++; if (task != null) { // Texture2D dstTex = m_Page.texture;//m_Tex2DLst[index]; Texture2D dstTex = m_PageList[index].texture; task.callback(dstTex, uv); } } DynamicAtlasMgr.S.ReleaseGetTextureData(task); m_GetTextureTaskList.RemoveAt(i); } }
public SaveTextureData AllocateSaveTextureData() { if (m_SaveTextureDataList.Count > 0) { return(m_SaveTextureDataList.Pop()); } SaveTextureData data = new SaveTextureData(); return(data); }
/// <summary> /// Image组件用完之后 /// </summary> /// <param name="name"></param> public void RemoveTexture(string name, bool clearRange = false) { if (m_UsingTexture.ContainsKey(name)) { SaveTextureData data = m_UsingTexture[name]; data.referenceCount--; if (data.referenceCount <= 0)//引用计数0 { if (clearRange) { Debug.Log("Remove Texture:" + name); m_PageList[data.texIndex].RemoveTexture(data.rect); } m_UsingTexture.Remove(name); DynamicAtlasMgr.S.ReleaseSaveTextureData(data); } } }
public void SetTexture(Texture texture, OnCallBackTexRect callBack) { if (texture == null) { Debug.Log("Texture is Null"); callBack(null, new Rect(0, 0, 0, 0)); return; } if (texture.width > m_Width || texture.height > m_Height) { Debug.Log("Texture is too big"); callBack(null, new Rect(0, 0, 0, 0)); return; } if (m_UsingTexture.ContainsKey(texture.name)) { if (callBack != null) { SaveTextureData textureData = m_UsingTexture[texture.name]; textureData.referenceCount++; Texture2D tex2D = m_PageList[textureData.texIndex].texture; callBack(tex2D, textureData.rect); } return; } GetTextureData data = DynamicAtlasMgr.S.AllocateGetTextureData(); data.name = texture.name; data.callback = callBack; m_GetTextureTaskList.Add(data); OnRenderTexture(data.name, (Texture2D)texture); }
public void ReleaseSaveTextureData(SaveTextureData data) { m_SaveTextureDataList.Add(data); }