void ClearFreeAreas() { DynamicAtlas dynamicAtlas = DynamicAtlasManager.Instance.GetDynamicAtlas(_mGroup); if (AtlasConfig.kUsingCopyTexture) { List <List <IntegerRectangle> > freeLists = dynamicAtlas.GetFreeAreas(); int freeListsCount = freeLists.Count; List <Texture2D> tex2DList = dynamicAtlas.tex2DList; for (int i = 0; i < freeListsCount; i++) { var freeList = freeLists[i]; int freeListCount = freeList.Count; Texture2D dstTex = tex2DList[i]; for (int j = 0; j < freeListCount; j++) { IntegerRectangle item = freeList[j]; Color32[] colors = new Color32[item.width * item.height]; for (int k = 0; k < colors.Length; ++k) { colors[k] = Color.clear; } dstTex.SetPixels32((int)item.x, (int)item.y, item.width, item.height, colors); dstTex.Apply(); } } } else { dynamicAtlas.ClearTextureWithBlit(); } }
void DrawFreeArea(int index, DynamicAtlas dynamicAtlas) { Texture2D tex2D = null; if (texList.Count < index + 1) { tex2D = new Texture2D((int)_mGroup, (int)_mGroup, TextureFormat.ARGB32, false, true); texList.Add(tex2D); if (mFillColor == null) { mFillColor = tex2D.GetPixels32(); for (int i = 0; i < mFillColor.Length; ++i) { mFillColor[i] = Color.clear; } } } else { tex2D = texList[index]; } tex2D.SetPixels32(mFillColor); if (isRefreshFreeAreas) { Color32[] tmpColor; List <IntegerRectangle> freeList = dynamicAtlas.GetFreeAreas()[index]; foreach (IntegerRectangle item in freeList) { int size = item.width * item.height; tmpColor = new Color32[size]; for (int k = 0; k < size; ++k) { tmpColor[k] = Color.green;//画边 } tex2D.SetPixels32(item.x, item.y, item.width, item.height, tmpColor); int outLineSize = 2; if (item.width < outLineSize * 2 || item.height < outLineSize * 2) { outLineSize = 0; } size -= outLineSize * 4; tmpColor = new Color32[size]; for (int k = 0; k < size; ++k) { tmpColor[k] = Color.yellow; } tex2D.SetPixels32(item.x + outLineSize, item.y + outLineSize, item.width - outLineSize * 2, item.height - outLineSize * 2, tmpColor); tex2D.Apply(); } } float poxX = (index + 1) * 10 + index * dynamicAtlas.atlasWidth * scale; GUI.DrawTexture(new Rect(poxX, formPosY, dynamicAtlas.atlasWidth * scale, dynamicAtlas.atlasHeight * scale), tex2D); }