DynamicAtlasPage CreateNewPage() { var page = DynamicAtlasPage.OnCreate(m_PageList.Count, m_Width, m_Height, m_TempColor); m_PageList.Add(page); return(page); }
private IntegerRectangle InsertArea(int width, int height, out int index) { IntegerRectangle result = null; IntegerRectangle freeArea = null; DynamicAtlasPage page = null; for (int i = 0; i < m_PageList.Count; i++) { int fIndex = m_PageList[i].GetFreeAreaIndex(width, height, m_Padding); if (fIndex >= 0) { page = m_PageList[i]; freeArea = page.freeAreasList[fIndex]; break; } } if (freeArea == null) { Log.Error("No Free Area----Create New Page"); page = CreateNewPage(); freeArea = page.freeAreasList[0]; } result = IntegerRectangle.Create(freeArea.x, freeArea.y, width, height); GenerateNewFreeAreas(result, page); page.RemoveFreeArea(freeArea); index = page.index; return(result); }
static async ETTask PreLoad() { for (int i = 0; i < 2; i++)//看情况提前预加载,加载会卡顿 { await TimerComponent.Instance.WaitAsync(1); var temp = DynamicAtlasPage.OnCreate(i, DynamicAtlasGroup.Size_2048, DynamicAtlasGroup.Size_2048, null); temp.Dispose(); } }
private void GenerateNewFreeAreas(IntegerRectangle target, DynamicAtlasPage page) { int x = target.x; int y = target.y; int right = target.right + 1 + m_Padding; int top = target.top + 1 + m_Padding; IntegerRectangle targetWithPadding = null; if (m_Padding == 0) { targetWithPadding = target; } for (int i = page.freeAreasList.Count - 1; i >= 0; i--) { IntegerRectangle area = page.freeAreasList[i]; if (!(x >= area.right || right <= area.x || y >= area.top || top <= area.y)) { if (targetWithPadding == null) { targetWithPadding = IntegerRectangle.Create(target.x, target.y, target.width + m_Padding, target.height + m_Padding); } GenerateDividedAreas(targetWithPadding, area, m_WaitAddNewAreaList); IntegerRectangle topOfStack = page.freeAreasList.Pop(); if (i < page.freeAreasList.Count) { // Move the one on the top to the freed position page.freeAreasList[i] = topOfStack; } } } if (targetWithPadding != null && targetWithPadding != target) { targetWithPadding.Dispose(); } FilterSelfSubAreas(m_WaitAddNewAreaList); while (m_WaitAddNewAreaList.Count > 0) { var free = m_WaitAddNewAreaList.Pop(); page.AddFreeArea(free); } // if (target.right > m_PackedWidth) // m_PackedWidth = target.right; // if (target.top > m_PackedHeight) // m_PackedHeight = target.top; }