public void ApplyShadow(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, int start, int end, float x, float y) { Color color = mEffectColor; color.a *= finalAlpha; Color32 color2 = (!(bitmapFont != null) || !bitmapFont.premultipliedAlphaShader) ? color : NGUITools.ApplyPMA(color); for (int i = start; i < end; i++) { verts.Add(verts.buffer[i]); uvs.Add(uvs.buffer[i]); cols.Add(cols.buffer[i]); Vector3 vector = verts.buffer[i]; vector.x += x; vector.y += y; verts.buffer[i] = vector; Color32 color3 = cols.buffer[i]; if (color3.a == 255) { cols.buffer[i] = color2; } else { Color color4 = color; color4.a = (float)(int)color3.a / 255f * color.a; cols.buffer[i] = ((!(bitmapFont != null) || !bitmapFont.premultipliedAlphaShader) ? color4 : NGUITools.ApplyPMA(color4)); } } }
/// <summary> /// Draw the label. /// </summary> public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!isValid) { return; } int offset = verts.size; Color col = color; col.a = finalAlpha; if (mFont != null && mFont.premultipliedAlpha) { col = NGUITools.ApplyPMA(col); } string text = processedText; float pixelSize = (mFont != null) ? mFont.pixelSize : 1f; float scale = mScale * pixelSize; bool usePS = usePrintedSize; int start = verts.size; if (usePS) { UpdateNGUIText(mPrintedSize, mWidth, mHeight); } else { UpdateNGUIText(fontSize, Mathf.RoundToInt(mWidth / scale), mHeight); } NGUIText.tint = col; NGUIText.Print(text, verts, uvs, cols); // Center the content within the label Vector2 pos = ApplyOffset(verts, usePS, mScale, start); // Apply an effect if one was requested if (effectStyle != Effect.None) { int end = verts.size; float pixel = pixelSize; pos.x = pixel * mEffectDistance.x; pos.y = pixel * mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, pos.x, -pos.y); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -pos.x, pos.y); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, pos.x, pos.y); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -pos.x, -pos.y); } } }
/// <summary> /// Draw the label. /// </summary> public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mFont == null) { return; } MakePositionPerfect(); Pivot p = pivot; int offset = verts.size; Color col = color; col.a *= mPanel.alpha; if (font.premultipliedAlpha) { col = NGUITools.ApplyPMA(col); } //add by chiuan if (isUsedEmojiSprite && mEmojiSpriteLabel == null) { mEmojiSpriteLabel = EmojiSpriteLabel.create(this); } if (mEmojiSpriteLabel != null && mFont.isDynamic && mFont.dynamicSymbolsFont != null) { mEmojiSpriteLabel.destroy(); mFont.dynamicSymbolLabel = mEmojiSpriteLabel; } // Print the text into the buffers if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft) { mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, NGUIFont.Alignment.Left, 0, mPremultiply); } else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight) { mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, NGUIFont.Alignment.Right, Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply); } else { mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, NGUIFont.Alignment.Center, Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply); } // Apply an effect if one was requested if (effectStyle != Effect.None) { Vector3 scale = cachedTransform.localScale; if (scale.x == 0f || scale.y == 0f) { return; } int end = verts.size; float pixel = 1f / mFont.size; float fx = pixel * mEffectDistance.x; float fy = pixel * mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, fx, -fy); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy); } } //maybe create all symblos if (mEmojiSpriteLabel != null) { mEmojiSpriteLabel.createSymblos(); } MakePixelPerfect(); }
protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture mainTexture = this.material.mainTexture; if (mainTexture != null) { Rect mInner = this.mInner; if (this.atlas.coordinates == UIAtlas.Coordinates.TexCoords) { mInner = NGUIMath.ConvertToPixels(mInner, mainTexture.width, mainTexture.height, true); } Vector2 localScale = base.cachedTransform.localScale; float pixelSize = this.atlas.pixelSize; float num2 = Mathf.Abs((float)(mInner.width / localScale.x)) * pixelSize; float num3 = Mathf.Abs((float)(mInner.height / localScale.y)) * pixelSize; if ((num2 < 0.01f) || (num3 < 0.01f)) { Debug.LogWarning("The tiled sprite (" + NGUITools.GetHierarchy(base.gameObject) + ") is too small.\nConsider using a bigger one."); num2 = 0.01f; num3 = 0.01f; } Vector2 vector2 = new Vector2(mInner.xMin / ((float)mainTexture.width), mInner.yMin / ((float)mainTexture.height)); Vector2 vector3 = new Vector2(mInner.xMax / ((float)mainTexture.width), mInner.yMax / ((float)mainTexture.height)); Vector2 vector4 = vector3; Color c = base.color; c.a *= base.mPanel.alpha; Color32 item = !this.atlas.premultipliedAlpha ? c : NGUITools.ApplyPMA(c); for (float i = 0f; i < 1f; i += num3) { float x = 0f; vector4.x = vector3.x; float num6 = i + num3; if (num6 > 1f) { vector4.y = vector2.y + (((vector3.y - vector2.y) * (1f - i)) / (num6 - i)); num6 = 1f; } while (x < 1f) { float num7 = x + num2; if (num7 > 1f) { vector4.x = vector2.x + (((vector3.x - vector2.x) * (1f - x)) / (num7 - x)); num7 = 1f; } verts.Add(new Vector3(num7, -i, 0f)); verts.Add(new Vector3(num7, -num6, 0f)); verts.Add(new Vector3(x, -num6, 0f)); verts.Add(new Vector3(x, -i, 0f)); uvs.Add(new Vector2(vector4.x, 1f - vector2.y)); uvs.Add(new Vector2(vector4.x, 1f - vector4.y)); uvs.Add(new Vector2(vector2.x, 1f - vector4.y)); uvs.Add(new Vector2(vector2.x, 1f - vector2.y)); cols.Add(item); cols.Add(item); cols.Add(item); cols.Add(item); x += num2; } } } }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = material.mainTexture; if (tex == null) { return; } Rect rect = mInner; if (atlas.coordinates == UIAtlas.Coordinates.TexCoords) { rect = NGUIMath.ConvertToPixels(rect, tex.width, tex.height, true); } Vector2 scale = cachedTransform.localScale; float pixelSize = atlas.pixelSize; float width = Mathf.Abs(rect.width / scale.x) * pixelSize; float height = Mathf.Abs(rect.height / scale.y) * pixelSize; // Safety check. Useful so Unity doesn't run out of memory if the sprites are too small. if (width < 0.01f || height < 0.01f) { Debug.LogWarning("The tiled sprite (" + NGUITools.GetHierarchy(gameObject) + ") is too small.\nConsider using a bigger one."); width = 0.01f; height = 0.01f; } Vector2 min = new Vector2(rect.xMin / tex.width, rect.yMin / tex.height); Vector2 max = new Vector2(rect.xMax / tex.width, rect.yMax / tex.height); Vector2 clipped = max; Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; float y = 0f; while (y < 1f) { float x = 0f; clipped.x = max.x; float y2 = y + height; if (y2 > 1f) { clipped.y = min.y + (max.y - min.y) * (1f - y) / (y2 - y); y2 = 1f; } while (x < 1f) { float x2 = x + width; if (x2 > 1f) { clipped.x = min.x + (max.x - min.x) * (1f - x) / (x2 - x); x2 = 1f; } verts.Add(new Vector3(x2, -y, 0f)); verts.Add(new Vector3(x2, -y2, 0f)); verts.Add(new Vector3(x, -y2, 0f)); verts.Add(new Vector3(x, -y, 0f)); uvs.Add(new Vector2(clipped.x, 1f - min.y)); uvs.Add(new Vector2(clipped.x, 1f - clipped.y)); uvs.Add(new Vector2(min.x, 1f - clipped.y)); uvs.Add(new Vector2(min.x, 1f - min.y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x += width; } y += height; } }
/// <summary> /// Filled sprite fill function. /// </summary> protected void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { float x0 = 0f; float y0 = 0f; float x1 = 1f; float y1 = -1f; float u0 = mOuterUV.xMin; float v0 = mOuterUV.yMin; float u1 = mOuterUV.xMax; float v1 = mOuterUV.yMax; // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { float du = (u1 - u0) * mFillAmount; float dv = (v1 - v0) * mFillAmount; if (fillDirection == FillDirection.Horizontal) { if (mInvert) { x0 = (1f - mFillAmount); u0 = u1 - du; } else { x1 *= mFillAmount; u1 = u0 + du; } } else if (fillDirection == FillDirection.Vertical) { if (mInvert) { y1 *= mFillAmount; v0 = v1 - dv; } else { y0 = -(1f - mFillAmount); v1 = v0 + dv; } } } // Starting quad for the sprite Vector2[] xy = new Vector2[4]; Vector2[] uv = new Vector2[4]; xy[0] = new Vector2(x1, y0); xy[1] = new Vector2(x1, y1); xy[2] = new Vector2(x0, y1); xy[3] = new Vector2(x0, y0); uv[0] = new Vector2(u1, v1); uv[1] = new Vector2(u1, v0); uv[2] = new Vector2(u0, v0); uv[3] = new Vector2(u0, v1); Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; if (fillDirection == FillDirection.Radial90) { // Adjust the quad radially, and if 'false' is returned (it's not visible), just exit if (!AdjustRadial(xy, uv, mFillAmount, mInvert)) { return; } } else if (fillDirection == FillDirection.Radial180) { // Working in 0-1 coordinates is easier Vector2[] oxy = new Vector2[4]; Vector2[] ouv = new Vector2[4]; for (int i = 0; i < 2; ++i) { oxy[0] = new Vector2(0f, 0f); oxy[1] = new Vector2(0f, 1f); oxy[2] = new Vector2(1f, 1f); oxy[3] = new Vector2(1f, 0f); ouv[0] = new Vector2(0f, 0f); ouv[1] = new Vector2(0f, 1f); ouv[2] = new Vector2(1f, 1f); ouv[3] = new Vector2(1f, 0f); // Each half must be rotated 90 degrees clockwise in order for it to fill properly if (mInvert) { if (i > 0) { Rotate(oxy, i); Rotate(ouv, i); } } else if (i < 1) { Rotate(oxy, 1 - i); Rotate(ouv, 1 - i); } // Each half must fill in only a part of the space float x, y; if (i == 1) { x = mInvert ? 0.5f : 1f; y = mInvert ? 1f : 0.5f; } else { x = mInvert ? 1f : 0.5f; y = mInvert ? 0.5f : 1f; } oxy[1].y = Mathf.Lerp(x, y, oxy[1].y); oxy[2].y = Mathf.Lerp(x, y, oxy[2].y); ouv[1].y = Mathf.Lerp(x, y, ouv[1].y); ouv[2].y = Mathf.Lerp(x, y, ouv[2].y); float amount = (mFillAmount) * 2 - i; bool odd = (i % 2) == 1; if (AdjustRadial(oxy, ouv, amount, !odd)) { if (mInvert) { odd = !odd; } // Add every other side in reverse order so they don't come out backface-culled due to rotation if (odd) { for (int b = 0; b < 4; ++b) { x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } else { for (int b = 3; b > -1; --b) { x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } } } return; } else if (fillDirection == FillDirection.Radial360) { float[] matrix = new float[] { // x0 y0 x1 y1 0.5f, 1f, 0f, 0.5f, // quadrant 0 0.5f, 1f, 0.5f, 1f, // quadrant 1 0f, 0.5f, 0.5f, 1f, // quadrant 2 0f, 0.5f, 0f, 0.5f, // quadrant 3 }; Vector2[] oxy = new Vector2[4]; Vector2[] ouv = new Vector2[4]; for (int i = 0; i < 4; ++i) { oxy[0] = new Vector2(0f, 0f); oxy[1] = new Vector2(0f, 1f); oxy[2] = new Vector2(1f, 1f); oxy[3] = new Vector2(1f, 0f); ouv[0] = new Vector2(0f, 0f); ouv[1] = new Vector2(0f, 1f); ouv[2] = new Vector2(1f, 1f); ouv[3] = new Vector2(1f, 0f); // Each quadrant must be rotated 90 degrees clockwise in order for it to fill properly if (mInvert) { if (i > 0) { Rotate(oxy, i); Rotate(ouv, i); } } else if (i < 3) { Rotate(oxy, 3 - i); Rotate(ouv, 3 - i); } // Each quadrant must fill in only a quarter of the space for (int b = 0; b < 4; ++b) { int index = (mInvert) ? (3 - i) * 4 : i * 4; float fx0 = matrix[index]; float fy0 = matrix[index + 1]; float fx1 = matrix[index + 2]; float fy1 = matrix[index + 3]; oxy[b].x = Mathf.Lerp(fx0, fy0, oxy[b].x); oxy[b].y = Mathf.Lerp(fx1, fy1, oxy[b].y); ouv[b].x = Mathf.Lerp(fx0, fy0, ouv[b].x); ouv[b].y = Mathf.Lerp(fx1, fy1, ouv[b].y); } float amount = (mFillAmount) * 4 - i; bool odd = (i % 2) == 1; if (AdjustRadial(oxy, ouv, amount, !odd)) { if (mInvert) { odd = !odd; } // Add every other side in reverse order so they don't come out backface-culled due to rotation if (odd) { for (int b = 0; b < 4; ++b) { float x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); float y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } else { for (int b = 3; b > -1; --b) { float x = Mathf.Lerp(xy[0].x, xy[2].x, oxy[b].x); float y = Mathf.Lerp(xy[0].y, xy[2].y, oxy[b].y); float u = Mathf.Lerp(uv[0].x, uv[2].x, ouv[b].x); float v = Mathf.Lerp(uv[0].y, uv[2].y, ouv[b].y); verts.Add(new Vector3(x, y, 0f)); uvs.Add(new Vector2(u, v)); cols.Add(col); } } } } return; } // Fill the buffer with the quad for the sprite for (int i = 0; i < 4; ++i) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(col); } }
private void ApplyShadow(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, int start, int end, float x, float y) { Color color = this.mEffectColor; color.a *= this.finalAlpha; Color32 color2 = (!(this.bitmapFont != null) || !this.bitmapFont.premultipliedAlphaShader) ? color : NGUITools.ApplyPMA(color); for (int i = start; i < end; i++) { verts.Add(verts.buffer[i]); uvs.Add(uvs.buffer[i]); cols.Add(cols.buffer[i]); Vector3 vector = verts.buffer[i]; vector.x += x; vector.y += y; verts.buffer[i] = vector; cols.buffer[i] = color2; } }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = material.mainTexture; if (tex == null) { return; } Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); size *= atlas.pixelSize; float width = Mathf.Abs(size.x / mWidth); float height = Mathf.Abs(size.y / mHeight); if (width * height < 0.0001f) { width = 0.01f; height = 0.01f; } Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; Vector2 pv = pivotOffset; Vector2 min = new Vector2(mInnerUV.xMin, mInnerUV.yMin); Vector2 max = new Vector2(mInnerUV.xMax, mInnerUV.yMax); Vector2 clipped = max; float y1 = 0f; while (y1 < 1f) { float x1 = 0f; clipped.x = max.x; float y2 = y1 + height; if (y2 > 1f) { clipped.y = min.y + (max.y - min.y) * (1f - y1) / (y2 - y1); y2 = 1f; } while (x1 < 1f) { float x2 = x1 + width; if (x2 > 1f) { clipped.x = min.x + (max.x - min.x) * (1f - x1) / (x2 - x1); x2 = 1f; } // Convert from normalized (0-1 range) coordinates to pixels float fx1 = (x1 - pv.x) * mWidth; float fx2 = (x2 - pv.x) * mWidth; float fy1 = (y1 - pv.y) * mHeight; float fy2 = (y2 - pv.y) * mHeight; verts.Add(new Vector3(fx1, fy1)); verts.Add(new Vector3(fx1, fy2)); verts.Add(new Vector3(fx2, fy2)); verts.Add(new Vector3(fx2, fy1)); uvs.Add(new Vector2(min.x, min.y)); uvs.Add(new Vector2(min.x, clipped.y)); uvs.Add(new Vector2(clipped.x, clipped.y)); uvs.Add(new Vector2(clipped.x, min.y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x1 += width; } y1 += height; } }
public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) #endif { if (mFont == null) { return; } MakePositionPerfect(); Pivot p = pivot; int offset = verts.size; Color col = font.premultipliedAlpha ? NGUITools.ApplyPMA(color) : color; // Print the text into the buffers if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft) { mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, 0, mPremultiply); } else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight) { mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Right, Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply); } else { mFont.Print(processedText, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Center, Mathf.RoundToInt(relativeSize.x * mFont.size), mPremultiply); } // Apply an effect if one was requested if (effectStyle != Effect.None) { Vector3 scale = cachedTransform.localScale; if (scale.x == 0f || scale.y == 0f) { return; } int end = verts.size; float pixel = 1f / mFont.size; float fx = pixel * mEffectDistance.x; float fy = pixel * mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, fx, -fy); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy); } } }
/// <summary> /// Draw the label. /// </summary> public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!isValid) { return; } Pivot p = pivot; int offset = verts.size; Color col = color; col.a *= mPanel.alpha; if (mFont != null && mFont.premultipliedAlpha) { col = NGUITools.ApplyPMA(col); } string text = processedText; float pixelSize = (mFont != null) ? mFont.pixelSize : 1f; float scale = mScale * pixelSize; bool usePS = usePrintedSize; int size = usePS ? mPrintedSize : fontSize; int w = usePS ? width : Mathf.RoundToInt(width / scale); int start = verts.size; TextAlignment alignment = TextAlignment.Center; // Print the text into the buffers if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft) { alignment = TextAlignment.Left; } else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight) { alignment = TextAlignment.Right; } if (mFont != null) { mFont.Print(text, size, col, verts, uvs, cols, mEncoding, mSymbols, alignment, w, mPremultiply); } #if DYNAMIC_FONT else { NGUIText.Print(text, mTrueTypeFont, size, fontStyle, col, mEncoding, alignment, w, mPremultiply, verts, uvs, cols); } #endif Vector2 po = pivotOffset; float fx = Mathf.Lerp(0f, -mWidth, po.x); float fy = Mathf.Lerp(mHeight, 0f, po.y); // Center vertically fy = Mathf.RoundToInt(fy + Mathf.Lerp(mCalculatedSize.y * scale - mHeight, 0f, po.y)); if (usePS || scale == 1f) { #if UNITY_FLASH for (int i = start; i < verts.size; ++i) { Vector3 buff = verts.buffer[i]; buff.x += fx; buff.y += fy; verts.buffer[i] = buff; } #else for (int i = start; i < verts.size; ++i) { verts.buffer[i].x += fx; verts.buffer[i].y += fy; } #endif } else { #if UNITY_FLASH for (int i = start; i < verts.size; ++i) { Vector3 buff = verts.buffer[i]; buff.x = fx + verts.buffer[i].x * scale; buff.y = fy + verts.buffer[i].y * scale; verts.buffer[i] = buff; } #else for (int i = start; i < verts.size; ++i) { verts.buffer[i].x = fx + verts.buffer[i].x * scale; verts.buffer[i].y = fy + verts.buffer[i].y * scale; } #endif } // Apply an effect if one was requested if (effectStyle != Effect.None) { int end = verts.size; float pixel = pixelSize; fx = pixel * mEffectDistance.x; fy = pixel * mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, fx, -fy); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy); } } }
/// <summary> /// Fill the draw buffers. /// </summary> public override void OnFill(List <Vector3> verts, List <Vector2> uvs, List <Color> cols) { var tex = mainTexture; if (tex == null) { return; } int offset = verts.Count; var drawRegion = this.drawRegion; foreach (var pair in mSprites) { var ent = pair.Value; if (!ent.enabled) { continue; } mSprite = ent.sprite; if (mSprite == null) { continue; } Color c = ent.color; c.a = finalAlpha; if (c.a == 0f) { continue; } var outer = new Rect(mSprite.x, mSprite.y, mSprite.width, mSprite.height); var inner = new Rect(mSprite.x + mSprite.borderLeft, mSprite.y + mSprite.borderTop, mSprite.width - mSprite.borderLeft - mSprite.borderRight, mSprite.height - mSprite.borderBottom - mSprite.borderTop); mOuterUV = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height); mInnerUV = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height); mFlip = ent.flip; var v = ent.GetDrawingDimensions(pixelSize); var u = drawingUVs; if (premultipliedAlpha) { c = NGUITools.ApplyPMA(c); } var start = verts.Count; switch (ent.type) { case Type.Simple: SimpleFill(verts, uvs, cols, ref v, ref u, ref c); break; case Type.Sliced: SlicedFill(verts, uvs, cols, ref v, ref u, ref c); break; case Type.Filled: FilledFill(verts, uvs, cols, ref v, ref u, ref c); break; case Type.Tiled: TiledFill(verts, uvs, cols, ref v, ref c); break; case Type.Advanced: AdvancedFill(verts, uvs, cols, ref v, ref u, ref c); break; } if (ent.rot != 0f) { var dz = ent.rot * Mathf.Deg2Rad; var halfZ = dz * 0.5f; var sinz = Mathf.Sin(halfZ); var cosz = Mathf.Cos(halfZ); var num3 = sinz * 2f; var num6 = sinz * num3; var num12 = cosz * num3; for (int i = start, imax = verts.Count; i < imax; ++i) { var pos = verts[i]; pos = new Vector3((1f - num6) * pos.x - num12 * pos.y, num12 * pos.x + (1f - num6) * pos.y, pos.z); pos.x += ent.pos.x; pos.y += ent.pos.y; verts[i] = pos; } } else { for (int i = start, imax = verts.Count; i < imax; ++i) { var pos = verts[i]; pos.x += ent.pos.x; pos.y += ent.pos.y; verts[i] = pos; } } } mSprite = null; if (onPostFill != null) { onPostFill(this, offset, verts, uvs, cols); } }
public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mFont == null) { return; } Pivot pivot = base.pivot; int size = verts.size; Color c = base.color; c.a *= mPanel.alpha; if (font.premultipliedAlpha) { c = NGUITools.ApplyPMA(c); } switch (pivot) { case Pivot.TopLeft: case Pivot.Left: case Pivot.BottomLeft: mFont.Print(this.processedText, c, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, 0, mPremultiply); break; case Pivot.TopRight: case Pivot.Right: case Pivot.BottomRight: { UIFont uIFont2 = mFont; string processedText2 = this.processedText; Color32 color2 = c; bool encoding2 = mEncoding; UIFont.SymbolStyle symbolStyle2 = mSymbols; Vector2 relativeSize2 = this.relativeSize; uIFont2.Print(processedText2, color2, verts, uvs, cols, encoding2, symbolStyle2, UIFont.Alignment.Right, Mathf.RoundToInt(relativeSize2.x * (float)mFont.size), mPremultiply); break; } default: { UIFont uIFont = mFont; string processedText = this.processedText; Color32 color = c; bool encoding = mEncoding; UIFont.SymbolStyle symbolStyle = mSymbols; Vector2 relativeSize = this.relativeSize; uIFont.Print(processedText, color, verts, uvs, cols, encoding, symbolStyle, UIFont.Alignment.Center, Mathf.RoundToInt(relativeSize.x * (float)mFont.size), mPremultiply); break; } } if (effectStyle != 0) { int size2 = verts.size; float num = 1f / (float)mFont.size; float num2 = num * mEffectDistance.x; float num3 = num * mEffectDistance.y; ApplyShadow(verts, uvs, cols, size, size2, num2, 0f - num3); if (effectStyle == Effect.Outline) { size = size2; size2 = verts.size; ApplyShadow(verts, uvs, cols, size, size2, 0f - num2, num3); size = size2; size2 = verts.size; ApplyShadow(verts, uvs, cols, size, size2, num2, num3); size = size2; size2 = verts.size; ApplyShadow(verts, uvs, cols, size, size2, 0f - num2, 0f - num3); } } }
protected unsafe void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { float x = 0f; float y = 0f; float num3 = 1f; float num4 = -1f; float xMin = this.mOuterUV.xMin; float yMin = this.mOuterUV.yMin; float xMax = this.mOuterUV.xMax; float yMax = this.mOuterUV.yMax; if ((this.mFillDirection == FillDirection.Horizontal) || (this.mFillDirection == FillDirection.Vertical)) { float num9 = (xMax - xMin) * this.mFillAmount; float num10 = (yMax - yMin) * this.mFillAmount; if (this.fillDirection == FillDirection.Horizontal) { if (this.mInvert) { x = 1f - this.mFillAmount; xMin = xMax - num9; } else { num3 *= this.mFillAmount; xMax = xMin + num9; } } else if (this.fillDirection == FillDirection.Vertical) { if (this.mInvert) { num4 *= this.mFillAmount; yMin = yMax - num10; } else { y = -(1f - this.mFillAmount); yMax = yMin + num10; } } } Vector2[] xy = new Vector2[4]; Vector2[] uv = new Vector2[4]; xy[0] = new Vector2(num3, y); xy[1] = new Vector2(num3, num4); xy[2] = new Vector2(x, num4); xy[3] = new Vector2(x, y); uv[0] = new Vector2(xMax, yMax); uv[1] = new Vector2(xMax, yMin); uv[2] = new Vector2(xMin, yMin); uv[3] = new Vector2(xMin, yMax); Color c = base.color; c.a *= base.mPanel.alpha; Color32 item = !this.atlas.premultipliedAlpha ? c : NGUITools.ApplyPMA(c); if (this.fillDirection == FillDirection.Radial90) { if (!this.AdjustRadial(xy, uv, this.mFillAmount, this.mInvert)) { return; } } else { if (this.fillDirection == FillDirection.Radial180) { Vector2[] v = new Vector2[4]; Vector2[] vectorArray4 = new Vector2[4]; for (int j = 0; j < 2; j++) { float num12; float num13; v[0] = new Vector2(0f, 0f); v[1] = new Vector2(0f, 1f); v[2] = new Vector2(1f, 1f); v[3] = new Vector2(1f, 0f); vectorArray4[0] = new Vector2(0f, 0f); vectorArray4[1] = new Vector2(0f, 1f); vectorArray4[2] = new Vector2(1f, 1f); vectorArray4[3] = new Vector2(1f, 0f); if (this.mInvert) { if (j > 0) { this.Rotate(v, j); this.Rotate(vectorArray4, j); } } else if (j < 1) { this.Rotate(v, 1 - j); this.Rotate(vectorArray4, 1 - j); } if (j == 1) { num12 = !this.mInvert ? 1f : 0.5f; num13 = !this.mInvert ? 0.5f : 1f; } else { num12 = !this.mInvert ? 0.5f : 1f; num13 = !this.mInvert ? 1f : 0.5f; } v[1].y = Mathf.Lerp(num12, num13, v[1].y); v[2].y = Mathf.Lerp(num12, num13, v[2].y); vectorArray4[1].y = Mathf.Lerp(num12, num13, vectorArray4[1].y); vectorArray4[2].y = Mathf.Lerp(num12, num13, vectorArray4[2].y); float fill = (this.mFillAmount * 2f) - j; bool flag = (j % 2) == 1; if (this.AdjustRadial(v, vectorArray4, fill, !flag)) { if (this.mInvert) { flag = !flag; } if (flag) { for (int k = 0; k < 4; k++) { num12 = Mathf.Lerp(xy[0].x, xy[2].x, v[k].x); num13 = Mathf.Lerp(xy[0].y, xy[2].y, v[k].y); float num16 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray4[k].x); float num17 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray4[k].y); verts.Add(new Vector3(num12, num13, 0f)); uvs.Add(new Vector2(num16, num17)); cols.Add(item); } } else { for (int m = 3; m > -1; m--) { num12 = Mathf.Lerp(xy[0].x, xy[2].x, v[m].x); num13 = Mathf.Lerp(xy[0].y, xy[2].y, v[m].y); float num19 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray4[m].x); float num20 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray4[m].y); verts.Add(new Vector3(num12, num13, 0f)); uvs.Add(new Vector2(num19, num20)); cols.Add(item); } } } } return; } if (this.fillDirection == FillDirection.Radial360) { float[] numArray = new float[] { 0.5f, 1f, 0f, 0.5f, 0.5f, 1f, 0.5f, 1f, 0f, 0.5f, 0.5f, 1f, 0f, 0.5f, 0f, 0.5f }; Vector2[] vectorArray5 = new Vector2[4]; Vector2[] vectorArray6 = new Vector2[4]; for (int n = 0; n < 4; n++) { vectorArray5[0] = new Vector2(0f, 0f); vectorArray5[1] = new Vector2(0f, 1f); vectorArray5[2] = new Vector2(1f, 1f); vectorArray5[3] = new Vector2(1f, 0f); vectorArray6[0] = new Vector2(0f, 0f); vectorArray6[1] = new Vector2(0f, 1f); vectorArray6[2] = new Vector2(1f, 1f); vectorArray6[3] = new Vector2(1f, 0f); if (this.mInvert) { if (n > 0) { this.Rotate(vectorArray5, n); this.Rotate(vectorArray6, n); } } else if (n < 3) { this.Rotate(vectorArray5, 3 - n); this.Rotate(vectorArray6, 3 - n); } for (int num22 = 0; num22 < 4; num22++) { int index = !this.mInvert ? (n * 4) : ((3 - n) * 4); float a = numArray[index]; float b = numArray[index + 1]; float num26 = numArray[index + 2]; float num27 = numArray[index + 3]; vectorArray5[num22].x = Mathf.Lerp(a, b, vectorArray5[num22].x); vectorArray5[num22].y = Mathf.Lerp(num26, num27, vectorArray5[num22].y); vectorArray6[num22].x = Mathf.Lerp(a, b, vectorArray6[num22].x); vectorArray6[num22].y = Mathf.Lerp(num26, num27, vectorArray6[num22].y); } float num28 = (this.mFillAmount * 4f) - n; bool flag2 = (n % 2) == 1; if (this.AdjustRadial(vectorArray5, vectorArray6, num28, !flag2)) { if (this.mInvert) { flag2 = !flag2; } if (flag2) { for (int num29 = 0; num29 < 4; num29++) { float num30 = Mathf.Lerp(xy[0].x, xy[2].x, vectorArray5[num29].x); float num31 = Mathf.Lerp(xy[0].y, xy[2].y, vectorArray5[num29].y); float num32 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray6[num29].x); float num33 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray6[num29].y); verts.Add(new Vector3(num30, num31, 0f)); uvs.Add(new Vector2(num32, num33)); cols.Add(item); } } else { for (int num34 = 3; num34 > -1; num34--) { float num35 = Mathf.Lerp(xy[0].x, xy[2].x, vectorArray5[num34].x); float num36 = Mathf.Lerp(xy[0].y, xy[2].y, vectorArray5[num34].y); float num37 = Mathf.Lerp(uv[0].x, uv[2].x, vectorArray6[num34].x); float num38 = Mathf.Lerp(uv[0].y, uv[2].y, vectorArray6[num34].y); verts.Add(new Vector3(num35, num36, 0f)); uvs.Add(new Vector2(num37, num38)); cols.Add(item); } } } } return; } } for (int i = 0; i < 4; i++) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(item); } }
/// <summary> /// Draw the label. /// </summary> public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!isValid) { return; } int offset = verts.size; Color col = color; col.a = finalAlpha; if (mFont != null && mFont.premultipliedAlpha) { col = NGUITools.ApplyPMA(col); } string text = processedText; float pixelSize = (mFont != null) ? mFont.pixelSize : 1f; float scale = mScale * pixelSize; bool usePS = usePrintedSize; int start = verts.size; UpdateNGUIText(); NGUIText.current.size = usePS ? mPrintedSize : fontSize; NGUIText.current.lineWidth = usePS ? mWidth : Mathf.RoundToInt(mWidth / scale); NGUIText.current.tint = col; if (mFont != null) { mFont.Print(text, verts, uvs, cols); } #if DYNAMIC_FONT else { NGUIText.Print(mTrueTypeFont, text, verts, uvs, cols); } #endif Vector2 po = pivotOffset; float fx = Mathf.Lerp(0f, -mWidth, po.x); float fy = Mathf.Lerp(mHeight, 0f, po.y); // Align vertically fy = Mathf.RoundToInt(fy + Mathf.Lerp(mCalculatedSize.y * scale - mHeight, 0f, po.y)); if (usePS || scale == 1f) { #if UNITY_FLASH for (int i = start; i < verts.size; ++i) { Vector3 buff = verts.buffer[i]; buff.x += fx; buff.y += fy; verts.buffer[i] = buff; } #else for (int i = start; i < verts.size; ++i) { verts.buffer[i].x += fx; verts.buffer[i].y += fy; } #endif } else { #if UNITY_FLASH for (int i = start; i < verts.size; ++i) { Vector3 buff = verts.buffer[i]; buff.x = fx + verts.buffer[i].x * scale; buff.y = fy + verts.buffer[i].y * scale; verts.buffer[i] = buff; } #else for (int i = start; i < verts.size; ++i) { verts.buffer[i].x = fx + verts.buffer[i].x * scale; verts.buffer[i].y = fy + verts.buffer[i].y * scale; } #endif } // Apply an effect if one was requested if (effectStyle != Effect.None) { int end = verts.size; float pixel = pixelSize; fx = pixel * mEffectDistance.x; fy = pixel * mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, fx, -fy); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy); } } }
/// <summary> /// Advanced sprite fill function. Contributed by Nicki Hansen. /// </summary> protected void AdvancedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!mSprite.hasBorder) { SimpleFill(verts, uvs, cols); return; } Texture tex = material.mainTexture; if (tex == null) { return; } Vector4 dr = drawingDimensions; Vector4 br = border * atlas.pixelSize; Vector2 tileSize = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); tileSize *= atlas.pixelSize; if (tileSize.x < 1f) { tileSize.x = 1f; } if (tileSize.y < 1f) { tileSize.y = 1f; } mTempPos[0].x = dr.x; mTempPos[0].y = dr.y; mTempPos[3].x = dr.z; mTempPos[3].y = dr.w; mTempPos[1].x = mTempPos[0].x + br.x; mTempPos[1].y = mTempPos[0].y + br.y; mTempPos[2].x = mTempPos[3].x - br.z; mTempPos[2].y = mTempPos[3].y - br.w; mTempUVs[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin); mTempUVs[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin); mTempUVs[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax); mTempUVs[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax); Color colF = color; colF.a = finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (centerType == AdvancedType.Invisible && x == 1 && y == 1) { continue; } int y2 = y + 1; if (x == 1 && y == 1) // Center { if (centerType == AdvancedType.Tiled) { float startPositionX = mTempPos[x].x; float endPositionX = mTempPos[x2].x; float startPositionY = mTempPos[y].y; float endPositionY = mTempPos[y2].y; float textureStartX = mTempUVs[x].x; float textureStartY = mTempUVs[y].y; float tileStartY = startPositionY; while (tileStartY < endPositionY) { float tileStartX = startPositionX; float textureEndY = mTempUVs[y2].y; float tileEndY = tileStartY + tileSize.y; if (tileEndY > endPositionY) { textureEndY = Mathf.Lerp(textureStartY, textureEndY, (endPositionY - tileStartY) / tileSize.y); tileEndY = endPositionY; } while (tileStartX < endPositionX) { float tileEndX = tileStartX + tileSize.x; float textureEndX = mTempUVs[x2].x; if (tileEndX > endPositionX) { textureEndX = Mathf.Lerp(textureStartX, textureEndX, (endPositionX - tileStartX) / tileSize.x); tileEndX = endPositionX; } FillBuffers(tileStartX, tileEndX, tileStartY, tileEndY, textureStartX, textureEndX, textureStartY, textureEndY, col, verts, uvs, cols); tileStartX += tileSize.x; } tileStartY += tileSize.y; } } else if (centerType == AdvancedType.Sliced) { FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y, mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols); } } else if (x == 1) // Top or bottom { if ((y == 0 && bottomType == AdvancedType.Tiled) || (y == 2 && topType == AdvancedType.Tiled)) { float startPositionX = mTempPos[x].x; float endPositionX = mTempPos[x2].x; float startPositionY = mTempPos[y].y; float endPositionY = mTempPos[y2].y; float textureStartX = mTempUVs[x].x; float textureStartY = mTempUVs[y].y; float textureEndY = mTempUVs[y2].y; float tileStartX = startPositionX; while (tileStartX < endPositionX) { float tileEndX = tileStartX + tileSize.x; float textureEndX = mTempUVs[x2].x; if (tileEndX > endPositionX) { textureEndX = Mathf.Lerp(textureStartX, textureEndX, (endPositionX - tileStartX) / tileSize.x); tileEndX = endPositionX; } FillBuffers(tileStartX, tileEndX, startPositionY, endPositionY, textureStartX, textureEndX, textureStartY, textureEndY, col, verts, uvs, cols); tileStartX += tileSize.x; } } else if ((y == 0 && bottomType == AdvancedType.Sliced) || (y == 2 && topType == AdvancedType.Sliced)) { FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y, mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols); } } else if (y == 1) // Left or right { if ((x == 0 && leftType == AdvancedType.Tiled) || (x == 2 && rightType == AdvancedType.Tiled)) { float startPositionX = mTempPos[x].x; float endPositionX = mTempPos[x2].x; float startPositionY = mTempPos[y].y; float endPositionY = mTempPos[y2].y; float textureStartX = mTempUVs[x].x; float textureEndX = mTempUVs[x2].x; float textureStartY = mTempUVs[y].y; float tileStartY = startPositionY; while (tileStartY < endPositionY) { float textureEndY = mTempUVs[y2].y; float tileEndY = tileStartY + tileSize.y; if (tileEndY > endPositionY) { textureEndY = Mathf.Lerp(textureStartY, textureEndY, (endPositionY - tileStartY) / tileSize.y); tileEndY = endPositionY; } FillBuffers(startPositionX, endPositionX, tileStartY, tileEndY, textureStartX, textureEndX, textureStartY, textureEndY, col, verts, uvs, cols); tileStartY += tileSize.y; } } else if ((x == 0 && leftType == AdvancedType.Sliced) || (x == 2 && rightType == AdvancedType.Sliced)) { FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y, mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols); } } else // Corner { FillBuffers(mTempPos[x].x, mTempPos[x2].x, mTempPos[y].y, mTempPos[y2].y, mTempUVs[x].x, mTempUVs[x2].x, mTempUVs[y].y, mTempUVs[y2].y, col, verts, uvs, cols); } } } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1. /// </summary> protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = mainTexture; if (tex == null || mOuterUV == mInnerUV) { SimpleFill(verts, uvs, cols); return; } Vector4 br = border; Vector2 po = pivotOffset; float fw = 1f / mWidth; float fh = 1f / mHeight; Vector2[] v = new Vector2[4]; v[0] = new Vector2(mSprite.paddingLeft * fw, mSprite.paddingBottom * fh); v[3] = new Vector2(1f - mSprite.paddingRight * fw, 1f - mSprite.paddingTop * fh); v[1].x = v[0].x + fw * br.x; v[1].y = v[0].y + fh * br.y; v[2].x = v[3].x - fw * br.z; v[2].y = v[3].y - fh * br.w; for (int i = 0; i < 4; ++i) { v[i].x -= po.x; v[i].y -= po.y; v[i].x *= mWidth; v[i].y *= mHeight; } Vector2[] u = new Vector2[4]; u[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin); u[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin); u[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax); u[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax); Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!mFillCenter && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(v[x].x, v[y].y)); verts.Add(new Vector3(v[x].x, v[y2].y)); verts.Add(new Vector3(v[x2].x, v[y2].y)); verts.Add(new Vector3(v[x2].x, v[y].y)); uvs.Add(new Vector2(u[x].x, u[y].y)); uvs.Add(new Vector2(u[x].x, u[y2].y)); uvs.Add(new Vector2(u[x2].x, u[y2].y)); uvs.Add(new Vector2(u[x2].x, u[y].y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); } } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1. /// </summary> protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!mSprite.hasBorder) { SimpleFill(verts, uvs, cols); return; } Vector4 dr = drawingDimensions; Vector4 br = border * atlas.pixelSize; mTempPos[0].x = dr.x; mTempPos[0].y = dr.y; mTempPos[3].x = dr.z; mTempPos[3].y = dr.w; mTempPos[1].x = mTempPos[0].x + br.x; mTempPos[1].y = mTempPos[0].y + br.y; mTempPos[2].x = mTempPos[3].x - br.z; mTempPos[2].y = mTempPos[3].y - br.w; mTempUVs[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMin); mTempUVs[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMin); mTempUVs[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMax); mTempUVs[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMax); Color colF = color; colF.a = finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (centerType == AdvancedType.Invisible && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(mTempPos[x].x, mTempPos[y].y)); verts.Add(new Vector3(mTempPos[x].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y2].y)); verts.Add(new Vector3(mTempPos[x2].x, mTempPos[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y].y)); uvs.Add(new Vector2(mTempUVs[x].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y2].y)); uvs.Add(new Vector2(mTempUVs[x2].x, mTempUVs[y].y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); } } }
/// <summary> /// Filled sprite fill function. /// </summary> protected void FilledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mFillAmount < 0.001f) { return; } Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; Vector2[] xy = new Vector2[4]; Vector2[] uv = new Vector2[4]; Vector4 v = drawingDimensions; float tx0 = mOuterUV.xMin; float ty0 = mOuterUV.yMin; float tx1 = mOuterUV.xMax; float ty1 = mOuterUV.yMax; // Horizontal and vertical filled sprites are simple -- just end the sprite prematurely if (mFillDirection == FillDirection.Horizontal || mFillDirection == FillDirection.Vertical) { if (mFillDirection == FillDirection.Horizontal) { float fill = (tx1 - tx0) * mFillAmount; if (mInvert) { v.x = v.z - (v.z - v.x) * mFillAmount; tx0 = tx1 - fill; } else { v.z = v.x + (v.z - v.x) * mFillAmount; tx1 = tx0 + fill; } } else if (mFillDirection == FillDirection.Vertical) { float fill = (ty1 - ty0) * mFillAmount; if (mInvert) { v.y = v.w - (v.w - v.y) * mFillAmount; ty0 = ty1 - fill; } else { v.w = v.y + (v.w - v.y) * mFillAmount; ty1 = ty0 + fill; } } } xy[0] = new Vector2(v.x, v.y); xy[1] = new Vector2(v.x, v.w); xy[2] = new Vector2(v.z, v.w); xy[3] = new Vector2(v.z, v.y); uv[0] = new Vector2(tx0, ty0); uv[1] = new Vector2(tx0, ty1); uv[2] = new Vector2(tx1, ty1); uv[3] = new Vector2(tx1, ty0); if (mFillAmount < 1f) { if (mFillDirection == FillDirection.Radial90) { if (RadialCut(xy, uv, mFillAmount, mInvert, 0)) { for (int i = 0; i < 4; ++i) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(col); } } return; } if (mFillDirection == FillDirection.Radial180) { for (int side = 0; side < 2; ++side) { float fx0, fx1, fy0, fy1; fy0 = 0f; fy1 = 1f; if (side == 0) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } xy[0].x = Mathf.Lerp(v.x, v.z, fx0); xy[1].x = xy[0].x; xy[2].x = Mathf.Lerp(v.x, v.z, fx1); xy[3].x = xy[2].x; xy[0].y = Mathf.Lerp(v.y, v.w, fy0); xy[1].y = Mathf.Lerp(v.y, v.w, fy1); xy[2].y = xy[1].y; xy[3].y = xy[0].y; uv[0].x = Mathf.Lerp(tx0, tx1, fx0); uv[1].x = uv[0].x; uv[2].x = Mathf.Lerp(tx0, tx1, fx1); uv[3].x = uv[2].x; uv[0].y = Mathf.Lerp(ty0, ty1, fy0); uv[1].y = Mathf.Lerp(ty0, ty1, fy1); uv[2].y = uv[1].y; uv[3].y = uv[0].y; float val = !mInvert ? fillAmount * 2f - side : mFillAmount * 2f - (1 - side); if (RadialCut(xy, uv, Mathf.Clamp01(val), !mInvert, NGUIMath.RepeatIndex(side + 3, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(col); } } } return; } if (mFillDirection == FillDirection.Radial360) { for (int corner = 0; corner < 4; ++corner) { float fx0, fx1, fy0, fy1; if (corner < 2) { fx0 = 0f; fx1 = 0.5f; } else { fx0 = 0.5f; fx1 = 1f; } if (corner == 0 || corner == 3) { fy0 = 0f; fy1 = 0.5f; } else { fy0 = 0.5f; fy1 = 1f; } xy[0].x = Mathf.Lerp(v.x, v.z, fx0); xy[1].x = xy[0].x; xy[2].x = Mathf.Lerp(v.x, v.z, fx1); xy[3].x = xy[2].x; xy[0].y = Mathf.Lerp(v.y, v.w, fy0); xy[1].y = Mathf.Lerp(v.y, v.w, fy1); xy[2].y = xy[1].y; xy[3].y = xy[0].y; uv[0].x = Mathf.Lerp(tx0, tx1, fx0); uv[1].x = uv[0].x; uv[2].x = Mathf.Lerp(tx0, tx1, fx1); uv[3].x = uv[2].x; uv[0].y = Mathf.Lerp(ty0, ty1, fy0); uv[1].y = Mathf.Lerp(ty0, ty1, fy1); uv[2].y = uv[1].y; uv[3].y = uv[0].y; float val = mInvert ? mFillAmount * 4f - NGUIMath.RepeatIndex(corner + 2, 4) : mFillAmount * 4f - (3 - NGUIMath.RepeatIndex(corner + 2, 4)); if (RadialCut(xy, uv, Mathf.Clamp01(val), mInvert, NGUIMath.RepeatIndex(corner + 2, 4))) { for (int i = 0; i < 4; ++i) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(col); } } } return; } } // Fill the buffer with the quad for the sprite for (int i = 0; i < 4; ++i) { verts.Add(xy[i]); uvs.Add(uv[i]); cols.Add(col); } }
/// <summary> /// Tiled sprite fill function. /// </summary> protected void TiledFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { Texture tex = material.mainTexture; if (tex == null) { return; } Vector4 dr = drawingDimensions; Vector2 size = new Vector2(mInnerUV.width * tex.width, mInnerUV.height * tex.height); size *= atlas.pixelSize; Color colF = color; colF.a = finalAlpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; float x0 = dr.x; float y0 = dr.y; float u0 = mInnerUV.xMin; float v0 = mInnerUV.yMin; while (y0 < dr.w) { x0 = dr.x; float y1 = y0 + size.y; float v1 = mInnerUV.yMax; if (y1 > dr.w) { v1 = Mathf.Lerp(mInnerUV.yMin, mInnerUV.yMax, (dr.w - y0) / size.y); y1 = dr.w; } while (x0 < dr.z) { float x1 = x0 + size.x; float u1 = mInnerUV.xMax; if (x1 > dr.z) { u1 = Mathf.Lerp(mInnerUV.xMin, mInnerUV.xMax, (dr.z - x0) / size.x); x1 = dr.z; } verts.Add(new Vector3(x0, y0)); verts.Add(new Vector3(x0, y1)); verts.Add(new Vector3(x1, y1)); verts.Add(new Vector3(x1, y0)); uvs.Add(new Vector2(u0, v0)); uvs.Add(new Vector2(u0, v1)); uvs.Add(new Vector2(u1, v1)); uvs.Add(new Vector2(u1, v0)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); x0 += size.x; } y0 += size.y; } }
/// <summary> /// Sliced sprite fill function is more complicated as it generates 9 quads instead of 1. /// </summary> protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mOuterUV == mInnerUV) { SimpleFill(verts, uvs, cols); return; } Vector2[] v = new Vector2[4]; Vector2[] uv = new Vector2[4]; Texture tex = mainTexture; v[0] = Vector2.zero; v[1] = Vector2.zero; v[2] = new Vector2(1f, -1f); v[3] = new Vector2(1f, -1f); if (tex != null) { float pixelSize = atlas.pixelSize; float borderLeft = (mInnerUV.xMin - mOuterUV.xMin) * pixelSize; float borderRight = (mOuterUV.xMax - mInnerUV.xMax) * pixelSize; float borderTop = (mInnerUV.yMax - mOuterUV.yMax) * pixelSize; float borderBottom = (mOuterUV.yMin - mInnerUV.yMin) * pixelSize; Vector3 scale = cachedTransform.localScale; scale.x = Mathf.Max(0f, scale.x); scale.y = Mathf.Max(0f, scale.y); Vector2 sz = new Vector2(scale.x / tex.width, scale.y / tex.height); Vector2 tl = new Vector2(borderLeft / sz.x, borderTop / sz.y); Vector2 br = new Vector2(borderRight / sz.x, borderBottom / sz.y); Pivot pv = pivot; // We don't want the sliced sprite to become smaller than the summed up border size if (pv == Pivot.Right || pv == Pivot.TopRight || pv == Pivot.BottomRight) { v[0].x = Mathf.Min(0f, 1f - (br.x + tl.x)); v[1].x = v[0].x + tl.x; v[2].x = v[0].x + Mathf.Max(tl.x, 1f - br.x); v[3].x = v[0].x + Mathf.Max(tl.x + br.x, 1f); } else { v[1].x = tl.x; v[2].x = Mathf.Max(tl.x, 1f - br.x); v[3].x = Mathf.Max(tl.x + br.x, 1f); } if (pv == Pivot.Bottom || pv == Pivot.BottomLeft || pv == Pivot.BottomRight) { v[0].y = Mathf.Max(0f, -1f - (br.y + tl.y)); v[1].y = v[0].y + tl.y; v[2].y = v[0].y + Mathf.Min(tl.y, -1f - br.y); v[3].y = v[0].y + Mathf.Min(tl.y + br.y, -1f); } else { v[1].y = tl.y; v[2].y = Mathf.Min(tl.y, -1f - br.y); v[3].y = Mathf.Min(tl.y + br.y, -1f); } uv[0] = new Vector2(mOuterUV.xMin, mOuterUV.yMax); uv[1] = new Vector2(mInnerUV.xMin, mInnerUV.yMax); uv[2] = new Vector2(mInnerUV.xMax, mInnerUV.yMin); uv[3] = new Vector2(mOuterUV.xMax, mOuterUV.yMin); } else { // No texture -- just use zeroed out texture coordinates for (int i = 0; i < 4; ++i) { uv[i] = Vector2.zero; } } Color colF = color; colF.a *= mPanel.alpha; Color32 col = atlas.premultipliedAlpha ? NGUITools.ApplyPMA(colF) : colF; for (int x = 0; x < 3; ++x) { int x2 = x + 1; for (int y = 0; y < 3; ++y) { if (!mFillCenter && x == 1 && y == 1) { continue; } int y2 = y + 1; verts.Add(new Vector3(v[x2].x, v[y].y, 0f)); verts.Add(new Vector3(v[x2].x, v[y2].y, 0f)); verts.Add(new Vector3(v[x].x, v[y2].y, 0f)); verts.Add(new Vector3(v[x].x, v[y].y, 0f)); uvs.Add(new Vector2(uv[x2].x, uv[y].y)); uvs.Add(new Vector2(uv[x2].x, uv[y2].y)); uvs.Add(new Vector2(uv[x].x, uv[y2].y)); uvs.Add(new Vector2(uv[x].x, uv[y].y)); cols.Add(col); cols.Add(col); cols.Add(col); cols.Add(col); } } }
/// <summary> /// Draw the label. /// </summary> public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (!isValid) { return; } int offset = verts.size; Color col = color; col.a = finalAlpha; if (mFont != null && mFont.premultipliedAlphaShader) { col = NGUITools.ApplyPMA(col); } string text = processedText; int start = verts.size; UpdateNGUIText(); NGUIText.tint = col; NGUIText.Print(text, verts, uvs, cols); // Center the content within the label vertically Vector2 pos = ApplyOffset(verts, start); // Effects don't work with packed fonts if (mFont != null && mFont.packedFontShader) { return; } // Apply an effect if one was requested if (effectStyle != Effect.None) { int end = verts.size; pos.x = mEffectDistance.x; pos.y = mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, pos.x, -pos.y); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -pos.x, pos.y); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, pos.x, pos.y); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -pos.x, -pos.y); } } }
/// <summary> /// Draw the label. /// </summary> public override void OnFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (mFont == null) { return; } Pivot p = pivot; int offset = verts.size; Color col = color; col.a *= mPanel.alpha; if (font.premultipliedAlpha) { col = NGUITools.ApplyPMA(col); } string text = processedText; float scale = mScale * mFont.pixelSize; int w = Mathf.RoundToInt(width / scale); int start = verts.size; // Print the text into the buffers if (p == Pivot.Left || p == Pivot.TopLeft || p == Pivot.BottomLeft) { mFont.Print(text, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Left, w, mPremultiply); } else if (p == Pivot.Right || p == Pivot.TopRight || p == Pivot.BottomRight) { mFont.Print(text, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Right, w, mPremultiply); } else { mFont.Print(text, col, verts, uvs, cols, mEncoding, mSymbols, UIFont.Alignment.Center, w, mPremultiply); } Vector2 po = pivotOffset; float fx = Mathf.Lerp(0f, -mWidth, po.x); float fy = Mathf.Lerp(mHeight, 0f, po.y); // Center vertically fy += Mathf.Lerp(mSize.y * scale - mHeight, 0f, po.y); if (scale == 1f) { for (int i = start; i < verts.size; ++i) { verts.buffer[i].x += fx; verts.buffer[i].y += fy; } } else { for (int i = start; i < verts.size; ++i) { verts.buffer[i].x = fx + verts.buffer[i].x * scale; verts.buffer[i].y = fy + verts.buffer[i].y * scale; } } // Apply an effect if one was requested if (effectStyle != Effect.None) { int end = verts.size; float pixel = mFont.pixelSize; fx = pixel * mEffectDistance.x; fy = pixel * mEffectDistance.y; ApplyShadow(verts, uvs, cols, offset, end, fx, -fy); if (effectStyle == Effect.Outline) { offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, fx, fy); offset = end; end = verts.size; ApplyShadow(verts, uvs, cols, offset, end, -fx, -fy); } } }
/// <summary> /// Apply a shadow effect to the buffer. /// </summary> void ApplyShadow(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, int start, int end, float x, float y) { Color c = mEffectColor; c.a *= finalAlpha; Color32 col = (bitmapFont != null && bitmapFont.premultipliedAlphaShader) ? NGUITools.ApplyPMA(c) : c; for (int i = start; i < end; ++i) { verts.Add(verts.buffer[i]); uvs.Add(uvs.buffer[i]); cols.Add(cols.buffer[i]); Vector3 v = verts.buffer[i]; v.x += x; v.y += y; verts.buffer[i] = v; Color32 uc = cols.buffer[i]; if (uc.a == 255) { cols.buffer[i] = col; } else { Color fc = c; fc.a = (uc.a / 255f * c.a); cols.buffer[i] = (bitmapFont != null && bitmapFont.premultipliedAlphaShader) ? NGUITools.ApplyPMA(fc) : fc; } } }
/// <summary> /// Create a list of sprites using the specified list of textures. /// </summary> static public List <SpriteEntry> CreateSprites(List <Texture> textures) { List <SpriteEntry> list = new List <SpriteEntry>(); foreach (Texture tex in textures) { Texture2D oldTex = NGUIEditorTools.ImportTexture(tex, true, false, true); if (oldTex == null) { oldTex = tex as Texture2D; } if (oldTex == null) { continue; } // If we aren't doing trimming, just use the texture as-is if (!NGUISettings.atlasTrimming && !NGUISettings.atlasPMA) { SpriteEntry sprite = new SpriteEntry(); sprite.SetRect(0, 0, oldTex.width, oldTex.height); sprite.tex = oldTex; sprite.name = oldTex.name; sprite.temporaryTexture = false; list.Add(sprite); continue; } // If we want to trim transparent pixels, there is more work to be done Color32[] pixels = oldTex.GetPixels32(); int xmin = oldTex.width; int xmax = 0; int ymin = oldTex.height; int ymax = 0; int oldWidth = oldTex.width; int oldHeight = oldTex.height; // Find solid pixels if (NGUISettings.atlasTrimming) { for (int y = 0, yw = oldHeight; y < yw; ++y) { for (int x = 0, xw = oldWidth; x < xw; ++x) { Color32 c = pixels[y * xw + x]; if (c.a != 0) { if (y < ymin) { ymin = y; } if (y > ymax) { ymax = y; } if (x < xmin) { xmin = x; } if (x > xmax) { xmax = x; } } } } } else { xmin = 0; xmax = oldWidth - 1; ymin = 0; ymax = oldHeight - 1; } int newWidth = (xmax - xmin) + 1; int newHeight = (ymax - ymin) + 1; if (newWidth > 0 && newHeight > 0) { SpriteEntry sprite = new SpriteEntry(); sprite.x = 0; sprite.y = 0; sprite.width = oldTex.width; sprite.height = oldTex.height; // If the dimensions match, then nothing was actually trimmed if (!NGUISettings.atlasPMA && (newWidth == oldWidth && newHeight == oldHeight)) { sprite.tex = oldTex; sprite.name = oldTex.name; sprite.temporaryTexture = false; } else { // Copy the non-trimmed texture data into a temporary buffer Color32[] newPixels = new Color32[newWidth * newHeight]; for (int y = 0; y < newHeight; ++y) { for (int x = 0; x < newWidth; ++x) { int newIndex = y * newWidth + x; int oldIndex = (ymin + y) * oldWidth + (xmin + x); if (NGUISettings.atlasPMA) { newPixels[newIndex] = NGUITools.ApplyPMA(pixels[oldIndex]); } else { newPixels[newIndex] = pixels[oldIndex]; } } } // Create a new texture sprite.name = oldTex.name; sprite.SetTexture(newPixels, newWidth, newHeight); // Remember the padding offset sprite.SetPadding(xmin, ymin, oldWidth - newWidth - xmin, oldHeight - newHeight - ymin); } list.Add(sprite); } } return(list); }
protected void SlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols) { if (this.mOuterUV == this.mInnerUV) { this.SimpleFill(verts, uvs, cols); } else { Vector2[] vectorArray = new Vector2[4]; Vector2[] vectorArray2 = new Vector2[4]; Texture mainTexture = this.mainTexture; vectorArray[0] = Vector2.zero; vectorArray[1] = Vector2.zero; vectorArray[2] = new Vector2(1f, -1f); vectorArray[3] = new Vector2(1f, -1f); if (mainTexture == null) { for (int j = 0; j < 4; j++) { vectorArray2[j] = Vector2.zero; } } else { float pixelSize = this.atlas.pixelSize; float num2 = (this.mInnerUV.xMin - this.mOuterUV.xMin) * pixelSize; float num3 = (this.mOuterUV.xMax - this.mInnerUV.xMax) * pixelSize; float num4 = (this.mInnerUV.yMax - this.mOuterUV.yMax) * pixelSize; float num5 = (this.mOuterUV.yMin - this.mInnerUV.yMin) * pixelSize; Vector3 localScale = base.cachedTransform.localScale; localScale.x = Mathf.Max(0f, localScale.x); localScale.y = Mathf.Max(0f, localScale.y); Vector2 vector2 = new Vector2(localScale.x / ((float)mainTexture.width), localScale.y / ((float)mainTexture.height)); Vector2 vector3 = new Vector2(num2 / vector2.x, num4 / vector2.y); Vector2 vector4 = new Vector2(num3 / vector2.x, num5 / vector2.y); UIWidget.Pivot pivot = base.pivot; switch (pivot) { case UIWidget.Pivot.Right: case UIWidget.Pivot.TopRight: case UIWidget.Pivot.BottomRight: vectorArray[0].x = Mathf.Min((float)0f, (float)(1f - (vector4.x + vector3.x))); vectorArray[1].x = vectorArray[0].x + vector3.x; vectorArray[2].x = vectorArray[0].x + Mathf.Max(vector3.x, 1f - vector4.x); vectorArray[3].x = vectorArray[0].x + Mathf.Max((float)(vector3.x + vector4.x), (float)1f); break; default: vectorArray[1].x = vector3.x; vectorArray[2].x = Mathf.Max(vector3.x, 1f - vector4.x); vectorArray[3].x = Mathf.Max((float)(vector3.x + vector4.x), (float)1f); break; } switch (pivot) { case UIWidget.Pivot.Bottom: case UIWidget.Pivot.BottomLeft: case UIWidget.Pivot.BottomRight: vectorArray[0].y = Mathf.Max((float)0f, (float)(-1f - (vector4.y + vector3.y))); vectorArray[1].y = vectorArray[0].y + vector3.y; vectorArray[2].y = vectorArray[0].y + Mathf.Min(vector3.y, -1f - vector4.y); vectorArray[3].y = vectorArray[0].y + Mathf.Min((float)(vector3.y + vector4.y), (float)-1f); break; default: vectorArray[1].y = vector3.y; vectorArray[2].y = Mathf.Min(vector3.y, -1f - vector4.y); vectorArray[3].y = Mathf.Min((float)(vector3.y + vector4.y), (float)-1f); break; } vectorArray2[0] = new Vector2(this.mOuterUV.xMin, this.mOuterUV.yMax); vectorArray2[1] = new Vector2(this.mInnerUV.xMin, this.mInnerUV.yMax); vectorArray2[2] = new Vector2(this.mInnerUV.xMax, this.mInnerUV.yMin); vectorArray2[3] = new Vector2(this.mOuterUV.xMax, this.mOuterUV.yMin); } Color c = base.color; c.a *= base.mPanel.alpha; Color32 item = !this.atlas.premultipliedAlpha ? c : NGUITools.ApplyPMA(c); for (int i = 0; i < 3; i++) { int index = i + 1; for (int k = 0; k < 3; k++) { if ((this.mFillCenter || (i != 1)) || (k != 1)) { int num10 = k + 1; verts.Add(new Vector3(vectorArray[index].x, vectorArray[k].y, 0f)); verts.Add(new Vector3(vectorArray[index].x, vectorArray[num10].y, 0f)); verts.Add(new Vector3(vectorArray[i].x, vectorArray[num10].y, 0f)); verts.Add(new Vector3(vectorArray[i].x, vectorArray[k].y, 0f)); uvs.Add(new Vector2(vectorArray2[index].x, vectorArray2[k].y)); uvs.Add(new Vector2(vectorArray2[index].x, vectorArray2[num10].y)); uvs.Add(new Vector2(vectorArray2[i].x, vectorArray2[num10].y)); uvs.Add(new Vector2(vectorArray2[i].x, vectorArray2[k].y)); cols.Add(item); cols.Add(item); cols.Add(item); cols.Add(item); } } } } }