//bubble down in the heap void CheckBelow( int i ) { int child2Index = ( i + 1 ) * 2; int child1Index = child2Index - 1; int swapIndex = i; if ( child1Index < StartPackRectList.Count ) { if ( StartPackRectList[child1Index].Height > StartPackRectList[i].Height ) { swapIndex = child1Index; } } if ( child2Index < StartPackRectList.Count ) { if ( StartPackRectList[child2Index].Height > StartPackRectList[( swapIndex == i ) ? i : child1Index].Height ) { swapIndex = child2Index; } } if ( swapIndex != i ) { swapPackRect = StartPackRectList[swapIndex]; StartPackRectList[swapIndex] = StartPackRectList[i]; StartPackRectList[i] = swapPackRect; CheckBelow( swapIndex ); } }
public PackRect( PackRect f ) { this.CI = f.CI; this.CIIndex = f.CIIndex; this.fontIndex = f.fontIndex; this.StartRect = f.StartRect; this.ResultRect = f.ResultRect; this.Height = f.Height; this.SameOrient = f.SameOrient; }
//bubble up in the heap void CheckAbove( int i ) { if ( i == 0 ) { return; } int ParentIndex = (int) Mathf.Floor( ( i + 1 ) / 2 ) - 1; if ( StartPackRectList[i].Height > StartPackRectList[ParentIndex].Height ) { swapPackRect = StartPackRectList[ParentIndex]; StartPackRectList[ParentIndex] = StartPackRectList[i]; StartPackRectList[i] = swapPackRect; CheckBelow( i ); } }
//harvest all charaterinfos from infont, into PackRect classes void HarvestStartPackRectList() { PackRect newPackRect = new PackRect(); StartPackRectList.Clear(); for ( int j = 0; j < inFontList.Length; j++ ) { for ( int i = 0; i < inFontList[j].characterInfo.Length; i++ ) { if ( SpriteEditor && i == 0 ) { continue; } Rect newRect = new Rect( 0, 0, 0, 0 ); newRect.x = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.x * inTexWidth ); newRect.y = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.y * inTexHeight ); newRect.width = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.width * inTexWidth ); newRect.height = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.height * inTexHeight ); if ( newRect.height < 0 ) { newRect.height *= -1; newRect.y -= newRect.height; } newPackRect.StartRect = newRect; newRect = new Rect( 0, 0, 0, 0 ); newRect.x = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.x * inTexWidth ); newRect.y = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.y * inTexHeight ); if ( inFontList[j].characterInfo[i].flipped ) { newRect.width = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.width * inTexWidth ) + PackBuffer; newRect.height = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.height * inTexHeight ) - PackBuffer; } else { newRect.width = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.width * inTexWidth ) + PackBuffer; newRect.height = Mathf.RoundToInt( inFontList[j].characterInfo[i].uv.height * inTexHeight ) + PackBuffer; } if ( newRect.height < 0 ) { newRect.height *= -1; newRect.y -= newRect.height; } newPackRect.ResultRect = newRect; newPackRect.CI = inFontList[j].characterInfo[i]; newPackRect.CIIndex = i; newPackRect.fontIndex = j; StartPackRectList.Add( new PackRect( newPackRect ) ); } } }