using UnityEngine;
using System.Collections;
using System;
public class UISpritePlus : UISprite
{
/*
* This class doesn't really do all that much more than what the parent does.
* Only about a 10-15 lines are tweaked, and not tweaked that much.
*/
protected void SlicedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, Rect mOuterUV, Rect mInnerUV)
{
Vector4 br = border * pixelSize;
Color32 c = drawingColor;
Vector4 v = drawingDimensions;
float perc = fillAmount; // drawRegion.z - drawRegion.x;
float percentMaxLeft = br.x / mWidth;
float percentMaxRight = br.z / mWidth;
float percentMaxMiddle = 1F - (percentMaxLeft + percentMaxRight);
float[] percentActual = {
Mathf.Clamp01(perc / percentMaxLeft),
Mathf.Clamp01((perc - percentMaxLeft) / percentMaxMiddle),
Mathf.Clamp01((perc - percentMaxLeft - percentMaxMiddle) / percentMaxRight),
};
mTempPos[0].x = v.x;
mTempPos[1].x = v.x + br.x * percentActual[0];
mTempPos[2].x = mTempPos[1].x + (v.z - v.x - br.x - br.z) * percentActual[1];
mTempPos[3].x = v.z - br.z * (1F - percentActual[2]);
mTempUVs[0].x = mOuterUV.xMin;
mTempUVs[1].x = mOuterUV.xMin + (mInnerUV.xMin - mOuterUV.xMin) * percentActual[0];
mTempUVs[2].x = mInnerUV.xMax;
mTempUVs[3].x = mInnerUV.xMax + (mOuterUV.xMax - mInnerUV.xMax) * percentActual[2];
mTempPos[0].y = v.y;
mTempPos[1].y = mTempPos[0].y + br.y;
mTempPos[2].y = mTempPos[3].y - br.w;
mTempPos[3].y = v.w;
mTempUVs[0].y = mOuterUV.yMin;
mTempUVs[1].y = mInnerUV.yMin;
mTempUVs[2].y = mInnerUV.yMax;
mTempUVs[3].y = mOuterUV.yMax;
for (int x = 0; x < 3; ++x)
{
if (percentActual[x] <= 0) continue;
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(c);
cols.Add(c);
cols.Add(c);
cols.Add(c);
}
}
}
// below method is MOSTLY a copy/paste from parent class.
// if SlicedFill was overrideable in the parent class, this could be removed
public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
{
if (type == Type.Filled)
{
Texture tex = mainTexture;
if (tex == null) return;
if (mSprite == null) mSprite = atlas.GetSprite(spriteName);
if (mSprite == null) return;
Rect outer
= new Rect
(mSprite
.x, mSprite
.y, mSprite
.width, mSprite
.height); Rect inner
= new Rect
(mSprite
.x + mSprite
.borderLeft, mSprite
.y + mSprite
.borderTop,
mSprite.width - mSprite.borderLeft - mSprite.borderRight,
mSprite.height - mSprite.borderBottom - mSprite.borderTop);
outer = NGUIMath.ConvertToTexCoords(outer, tex.width, tex.height);
inner = NGUIMath.ConvertToTexCoords(inner, tex.width, tex.height);
int offset = verts.size;
SlicedFill(verts, uvs, cols, outer, inner);
if (onPostFill != null)
onPostFill(this, offset, verts, uvs, cols);
}
else
{
base.OnFill(verts, uvs, cols);
}
}
// below method is purely a copy/paste from parent class.
// if drawingColor was "protected" in the parent class, this could be removed
Color32 drawingColor
{
get
{
Color colF = color;
colF.a = finalAlpha;
if (premultipliedAlpha) colF = NGUITools.ApplyPMA(colF);
if (QualitySettings.activeColorSpace == ColorSpace.Linear)
{
colF.r = Mathf.Pow(colF.r, 2.2f);
colF.g = Mathf.Pow(colF.g, 2.2f);
colF.b = Mathf.Pow(colF.b, 2.2f);
}
return colF;
}
}
}