123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921 |
- using System;
- using UnityEngine;
- public abstract class UIBasicSprite : UIWidget
- {
- public virtual UIBasicSprite.Type type
- {
- get
- {
- return this.mType;
- }
- set
- {
- if (this.mType != value)
- {
- this.mType = value;
- this.MarkAsChanged();
- }
- }
- }
- public UIBasicSprite.Flip flip
- {
- get
- {
- return this.mFlip;
- }
- set
- {
- if (this.mFlip != value)
- {
- this.mFlip = value;
- this.MarkAsChanged();
- }
- }
- }
- public UIBasicSprite.FillDirection fillDirection
- {
- get
- {
- return this.mFillDirection;
- }
- set
- {
- if (this.mFillDirection != value)
- {
- this.mFillDirection = value;
- this.mChanged = true;
- }
- }
- }
- public float fillAmount
- {
- get
- {
- return this.mFillAmount;
- }
- set
- {
- float num = Mathf.Clamp01(value);
- if (this.mFillAmount != num)
- {
- this.mFillAmount = num;
- this.mChanged = true;
- }
- }
- }
- public override int minWidth
- {
- get
- {
- if (this.type == UIBasicSprite.Type.Sliced || this.type == UIBasicSprite.Type.Advanced)
- {
- Vector4 vector = this.border * this.pixelSize;
- int num = Mathf.RoundToInt(vector.x + vector.z);
- return Mathf.Max(base.minWidth, ((num & 1) != 1) ? num : (num + 1));
- }
- return base.minWidth;
- }
- }
- public override int minHeight
- {
- get
- {
- if (this.type == UIBasicSprite.Type.Sliced || this.type == UIBasicSprite.Type.Advanced)
- {
- Vector4 vector = this.border * this.pixelSize;
- int num = Mathf.RoundToInt(vector.y + vector.w);
- return Mathf.Max(base.minHeight, ((num & 1) != 1) ? num : (num + 1));
- }
- return base.minHeight;
- }
- }
- public bool invert
- {
- get
- {
- return this.mInvert;
- }
- set
- {
- if (this.mInvert != value)
- {
- this.mInvert = value;
- this.mChanged = true;
- }
- }
- }
- public bool hasBorder
- {
- get
- {
- Vector4 border = this.border;
- return border.x != 0f || border.y != 0f || border.z != 0f || border.w != 0f;
- }
- }
- public virtual bool premultipliedAlpha
- {
- get
- {
- return false;
- }
- }
- public virtual float pixelSize
- {
- get
- {
- return 1f;
- }
- }
- private Vector4 drawingUVs
- {
- get
- {
- switch (this.mFlip)
- {
- case UIBasicSprite.Flip.Horizontally:
- return new Vector4(this.mOuterUV.xMax, this.mOuterUV.yMin, this.mOuterUV.xMin, this.mOuterUV.yMax);
- case UIBasicSprite.Flip.Vertically:
- return new Vector4(this.mOuterUV.xMin, this.mOuterUV.yMax, this.mOuterUV.xMax, this.mOuterUV.yMin);
- case UIBasicSprite.Flip.Both:
- return new Vector4(this.mOuterUV.xMax, this.mOuterUV.yMax, this.mOuterUV.xMin, this.mOuterUV.yMin);
- default:
- return new Vector4(this.mOuterUV.xMin, this.mOuterUV.yMin, this.mOuterUV.xMax, this.mOuterUV.yMax);
- }
- }
- }
- private Color32 drawingColor
- {
- get
- {
- Color c = base.color;
- c.a = this.finalAlpha;
- if (this.premultipliedAlpha)
- {
- c = NGUITools.ApplyPMA(c);
- }
- if (QualitySettings.activeColorSpace == ColorSpace.Linear)
- {
- c.r = Mathf.Pow(c.r, 2.2f);
- c.g = Mathf.Pow(c.g, 2.2f);
- c.b = Mathf.Pow(c.b, 2.2f);
- }
- return c;
- }
- }
- protected void Fill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, Rect outer, Rect inner)
- {
- this.mOuterUV = outer;
- this.mInnerUV = inner;
- switch (this.type)
- {
- case UIBasicSprite.Type.Simple:
- this.SimpleFill(verts, uvs, cols);
- break;
- case UIBasicSprite.Type.Sliced:
- this.SlicedFill(verts, uvs, cols);
- break;
- case UIBasicSprite.Type.Tiled:
- this.TiledFill(verts, uvs, cols);
- break;
- case UIBasicSprite.Type.Filled:
- this.FilledFill(verts, uvs, cols);
- break;
- case UIBasicSprite.Type.Advanced:
- this.AdvancedFill(verts, uvs, cols);
- break;
- }
- }
- private void SimpleFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- Vector4 drawingDimensions = this.drawingDimensions;
- Vector4 drawingUVs = this.drawingUVs;
- Color32 drawingColor = this.drawingColor;
- verts.Add(new Vector3(drawingDimensions.x, drawingDimensions.y));
- verts.Add(new Vector3(drawingDimensions.x, drawingDimensions.w));
- verts.Add(new Vector3(drawingDimensions.z, drawingDimensions.w));
- verts.Add(new Vector3(drawingDimensions.z, drawingDimensions.y));
- uvs.Add(new Vector2(drawingUVs.x, drawingUVs.y));
- uvs.Add(new Vector2(drawingUVs.x, drawingUVs.w));
- uvs.Add(new Vector2(drawingUVs.z, drawingUVs.w));
- uvs.Add(new Vector2(drawingUVs.z, drawingUVs.y));
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- }
- private void SlicedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- Vector4 vector = this.border * this.pixelSize;
- if (vector.x == 0f && vector.y == 0f && vector.z == 0f && vector.w == 0f)
- {
- this.SimpleFill(verts, uvs, cols);
- return;
- }
- Color32 drawingColor = this.drawingColor;
- Vector4 drawingDimensions = this.drawingDimensions;
- UIBasicSprite.mTempPos[0].x = drawingDimensions.x;
- UIBasicSprite.mTempPos[0].y = drawingDimensions.y;
- UIBasicSprite.mTempPos[3].x = drawingDimensions.z;
- UIBasicSprite.mTempPos[3].y = drawingDimensions.w;
- if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both)
- {
- UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.z;
- UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.x;
- UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMin;
- UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMin;
- UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMax;
- UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMax;
- }
- else
- {
- UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.x;
- UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.z;
- UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMin;
- UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMin;
- UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMax;
- UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMax;
- }
- if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both)
- {
- UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.w;
- UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.y;
- UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMin;
- UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMin;
- UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMax;
- UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMax;
- }
- else
- {
- UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.y;
- UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.w;
- UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMin;
- UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMin;
- UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMax;
- UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMax;
- }
- for (int i = 0; i < 3; i++)
- {
- int num = i + 1;
- for (int j = 0; j < 3; j++)
- {
- if (this.centerType != UIBasicSprite.AdvancedType.Invisible || i != 1 || j != 1)
- {
- int num2 = j + 1;
- verts.Add(new Vector3(UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[j].y));
- verts.Add(new Vector3(UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num2].y));
- verts.Add(new Vector3(UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[num2].y));
- verts.Add(new Vector3(UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y));
- uvs.Add(new Vector2(UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[j].y));
- uvs.Add(new Vector2(UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num2].y));
- uvs.Add(new Vector2(UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[num2].y));
- uvs.Add(new Vector2(UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y));
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- }
- }
- }
- }
- private void TiledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- Texture mainTexture = this.mainTexture;
- if (mainTexture == null)
- {
- return;
- }
- Vector2 a = new Vector2(this.mInnerUV.width * (float)mainTexture.width, this.mInnerUV.height * (float)mainTexture.height);
- a *= this.pixelSize;
- if (mainTexture == null || a.x < 2f || a.y < 2f)
- {
- return;
- }
- Color32 drawingColor = this.drawingColor;
- Vector4 drawingDimensions = this.drawingDimensions;
- Vector4 vector;
- if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both)
- {
- vector.x = this.mInnerUV.xMax;
- vector.z = this.mInnerUV.xMin;
- }
- else
- {
- vector.x = this.mInnerUV.xMin;
- vector.z = this.mInnerUV.xMax;
- }
- if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both)
- {
- vector.y = this.mInnerUV.yMax;
- vector.w = this.mInnerUV.yMin;
- }
- else
- {
- vector.y = this.mInnerUV.yMin;
- vector.w = this.mInnerUV.yMax;
- }
- float num = drawingDimensions.x;
- float num2 = drawingDimensions.y;
- float x = vector.x;
- float y = vector.y;
- while (num2 < drawingDimensions.w)
- {
- num = drawingDimensions.x;
- float num3 = num2 + a.y;
- float y2 = vector.w;
- if (num3 > drawingDimensions.w)
- {
- y2 = Mathf.Lerp(vector.y, vector.w, (drawingDimensions.w - num2) / a.y);
- num3 = drawingDimensions.w;
- }
- while (num < drawingDimensions.z)
- {
- float num4 = num + a.x;
- float x2 = vector.z;
- if (num4 > drawingDimensions.z)
- {
- x2 = Mathf.Lerp(vector.x, vector.z, (drawingDimensions.z - num) / a.x);
- num4 = drawingDimensions.z;
- }
- verts.Add(new Vector3(num, num2));
- verts.Add(new Vector3(num, num3));
- verts.Add(new Vector3(num4, num3));
- verts.Add(new Vector3(num4, num2));
- uvs.Add(new Vector2(x, y));
- uvs.Add(new Vector2(x, y2));
- uvs.Add(new Vector2(x2, y2));
- uvs.Add(new Vector2(x2, y));
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- cols.Add(drawingColor);
- num += a.x;
- }
- num2 += a.y;
- }
- }
- private void FilledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- if (this.mFillAmount < 0.001f)
- {
- return;
- }
- Vector4 drawingDimensions = this.drawingDimensions;
- Vector4 drawingUVs = this.drawingUVs;
- Color32 drawingColor = this.drawingColor;
- if (this.mFillDirection == UIBasicSprite.FillDirection.Horizontal || this.mFillDirection == UIBasicSprite.FillDirection.Vertical)
- {
- if (this.mFillDirection == UIBasicSprite.FillDirection.Horizontal)
- {
- float num = (drawingUVs.z - drawingUVs.x) * this.mFillAmount;
- if (this.mInvert)
- {
- drawingDimensions.x = drawingDimensions.z - (drawingDimensions.z - drawingDimensions.x) * this.mFillAmount;
- drawingUVs.x = drawingUVs.z - num;
- }
- else
- {
- drawingDimensions.z = drawingDimensions.x + (drawingDimensions.z - drawingDimensions.x) * this.mFillAmount;
- drawingUVs.z = drawingUVs.x + num;
- }
- }
- else if (this.mFillDirection == UIBasicSprite.FillDirection.Vertical)
- {
- float num2 = (drawingUVs.w - drawingUVs.y) * this.mFillAmount;
- if (this.mInvert)
- {
- drawingDimensions.y = drawingDimensions.w - (drawingDimensions.w - drawingDimensions.y) * this.mFillAmount;
- drawingUVs.y = drawingUVs.w - num2;
- }
- else
- {
- drawingDimensions.w = drawingDimensions.y + (drawingDimensions.w - drawingDimensions.y) * this.mFillAmount;
- drawingUVs.w = drawingUVs.y + num2;
- }
- }
- }
- UIBasicSprite.mTempPos[0] = new Vector2(drawingDimensions.x, drawingDimensions.y);
- UIBasicSprite.mTempPos[1] = new Vector2(drawingDimensions.x, drawingDimensions.w);
- UIBasicSprite.mTempPos[2] = new Vector2(drawingDimensions.z, drawingDimensions.w);
- UIBasicSprite.mTempPos[3] = new Vector2(drawingDimensions.z, drawingDimensions.y);
- UIBasicSprite.mTempUVs[0] = new Vector2(drawingUVs.x, drawingUVs.y);
- UIBasicSprite.mTempUVs[1] = new Vector2(drawingUVs.x, drawingUVs.w);
- UIBasicSprite.mTempUVs[2] = new Vector2(drawingUVs.z, drawingUVs.w);
- UIBasicSprite.mTempUVs[3] = new Vector2(drawingUVs.z, drawingUVs.y);
- if (this.mFillAmount < 1f)
- {
- if (this.mFillDirection == UIBasicSprite.FillDirection.Radial90)
- {
- if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, this.mFillAmount, this.mInvert, 0))
- {
- for (int i = 0; i < 4; i++)
- {
- verts.Add(UIBasicSprite.mTempPos[i]);
- uvs.Add(UIBasicSprite.mTempUVs[i]);
- cols.Add(drawingColor);
- }
- }
- return;
- }
- if (this.mFillDirection == UIBasicSprite.FillDirection.Radial180)
- {
- for (int j = 0; j < 2; j++)
- {
- float t = 0f;
- float t2 = 1f;
- float t3;
- float t4;
- if (j == 0)
- {
- t3 = 0f;
- t4 = 0.5f;
- }
- else
- {
- t3 = 0.5f;
- t4 = 1f;
- }
- UIBasicSprite.mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t3);
- UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x;
- UIBasicSprite.mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t4);
- UIBasicSprite.mTempPos[3].x = UIBasicSprite.mTempPos[2].x;
- UIBasicSprite.mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t);
- UIBasicSprite.mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t2);
- UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[1].y;
- UIBasicSprite.mTempPos[3].y = UIBasicSprite.mTempPos[0].y;
- UIBasicSprite.mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t3);
- UIBasicSprite.mTempUVs[1].x = UIBasicSprite.mTempUVs[0].x;
- UIBasicSprite.mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t4);
- UIBasicSprite.mTempUVs[3].x = UIBasicSprite.mTempUVs[2].x;
- UIBasicSprite.mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t);
- UIBasicSprite.mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t2);
- UIBasicSprite.mTempUVs[2].y = UIBasicSprite.mTempUVs[1].y;
- UIBasicSprite.mTempUVs[3].y = UIBasicSprite.mTempUVs[0].y;
- float value = this.mInvert ? (this.mFillAmount * 2f - (float)(1 - j)) : (this.fillAmount * 2f - (float)j);
- if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, Mathf.Clamp01(value), !this.mInvert, NGUIMath.RepeatIndex(j + 3, 4)))
- {
- for (int k = 0; k < 4; k++)
- {
- verts.Add(UIBasicSprite.mTempPos[k]);
- uvs.Add(UIBasicSprite.mTempUVs[k]);
- cols.Add(drawingColor);
- }
- }
- }
- return;
- }
- if (this.mFillDirection == UIBasicSprite.FillDirection.Radial360)
- {
- for (int l = 0; l < 4; l++)
- {
- float t5;
- float t6;
- if (l < 2)
- {
- t5 = 0f;
- t6 = 0.5f;
- }
- else
- {
- t5 = 0.5f;
- t6 = 1f;
- }
- float t7;
- float t8;
- if (l == 0 || l == 3)
- {
- t7 = 0f;
- t8 = 0.5f;
- }
- else
- {
- t7 = 0.5f;
- t8 = 1f;
- }
- UIBasicSprite.mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t5);
- UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x;
- UIBasicSprite.mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t6);
- UIBasicSprite.mTempPos[3].x = UIBasicSprite.mTempPos[2].x;
- UIBasicSprite.mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t7);
- UIBasicSprite.mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t8);
- UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[1].y;
- UIBasicSprite.mTempPos[3].y = UIBasicSprite.mTempPos[0].y;
- UIBasicSprite.mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t5);
- UIBasicSprite.mTempUVs[1].x = UIBasicSprite.mTempUVs[0].x;
- UIBasicSprite.mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t6);
- UIBasicSprite.mTempUVs[3].x = UIBasicSprite.mTempUVs[2].x;
- UIBasicSprite.mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t7);
- UIBasicSprite.mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t8);
- UIBasicSprite.mTempUVs[2].y = UIBasicSprite.mTempUVs[1].y;
- UIBasicSprite.mTempUVs[3].y = UIBasicSprite.mTempUVs[0].y;
- float value2 = (!this.mInvert) ? (this.mFillAmount * 4f - (float)(3 - NGUIMath.RepeatIndex(l + 2, 4))) : (this.mFillAmount * 4f - (float)NGUIMath.RepeatIndex(l + 2, 4));
- if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, Mathf.Clamp01(value2), this.mInvert, NGUIMath.RepeatIndex(l + 2, 4)))
- {
- for (int m = 0; m < 4; m++)
- {
- verts.Add(UIBasicSprite.mTempPos[m]);
- uvs.Add(UIBasicSprite.mTempUVs[m]);
- cols.Add(drawingColor);
- }
- }
- }
- return;
- }
- }
- for (int n = 0; n < 4; n++)
- {
- verts.Add(UIBasicSprite.mTempPos[n]);
- uvs.Add(UIBasicSprite.mTempUVs[n]);
- cols.Add(drawingColor);
- }
- }
- private void AdvancedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- Texture mainTexture = this.mainTexture;
- if (mainTexture == null)
- {
- return;
- }
- Vector4 vector = this.border * this.pixelSize;
- if (vector.x == 0f && vector.y == 0f && vector.z == 0f && vector.w == 0f)
- {
- this.SimpleFill(verts, uvs, cols);
- return;
- }
- Color32 drawingColor = this.drawingColor;
- Vector4 drawingDimensions = this.drawingDimensions;
- Vector2 a = new Vector2(this.mInnerUV.width * (float)mainTexture.width, this.mInnerUV.height * (float)mainTexture.height);
- a *= this.pixelSize;
- if (a.x < 1f)
- {
- a.x = 1f;
- }
- if (a.y < 1f)
- {
- a.y = 1f;
- }
- UIBasicSprite.mTempPos[0].x = drawingDimensions.x;
- UIBasicSprite.mTempPos[0].y = drawingDimensions.y;
- UIBasicSprite.mTempPos[3].x = drawingDimensions.z;
- UIBasicSprite.mTempPos[3].y = drawingDimensions.w;
- if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both)
- {
- UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.z;
- UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.x;
- UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMin;
- UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMin;
- UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMax;
- UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMax;
- }
- else
- {
- UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.x;
- UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.z;
- UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMin;
- UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMin;
- UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMax;
- UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMax;
- }
- if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both)
- {
- UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.w;
- UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.y;
- UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMin;
- UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMin;
- UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMax;
- UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMax;
- }
- else
- {
- UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.y;
- UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.w;
- UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMin;
- UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMin;
- UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMax;
- UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMax;
- }
- for (int i = 0; i < 3; i++)
- {
- int num = i + 1;
- for (int j = 0; j < 3; j++)
- {
- if (this.centerType != UIBasicSprite.AdvancedType.Invisible || i != 1 || j != 1)
- {
- int num2 = j + 1;
- if (i == 1 && j == 1)
- {
- if (this.centerType == UIBasicSprite.AdvancedType.Tiled)
- {
- float x = UIBasicSprite.mTempPos[i].x;
- float x2 = UIBasicSprite.mTempPos[num].x;
- float y = UIBasicSprite.mTempPos[j].y;
- float y2 = UIBasicSprite.mTempPos[num2].y;
- float x3 = UIBasicSprite.mTempUVs[i].x;
- float y3 = UIBasicSprite.mTempUVs[j].y;
- for (float num3 = y; num3 < y2; num3 += a.y)
- {
- float num4 = x;
- float num5 = UIBasicSprite.mTempUVs[num2].y;
- float num6 = num3 + a.y;
- if (num6 > y2)
- {
- num5 = Mathf.Lerp(y3, num5, (y2 - num3) / a.y);
- num6 = y2;
- }
- while (num4 < x2)
- {
- float num7 = num4 + a.x;
- float num8 = UIBasicSprite.mTempUVs[num].x;
- if (num7 > x2)
- {
- num8 = Mathf.Lerp(x3, num8, (x2 - num4) / a.x);
- num7 = x2;
- }
- UIBasicSprite.Fill(verts, uvs, cols, num4, num7, num3, num6, x3, num8, y3, num5, drawingColor);
- num4 += a.x;
- }
- }
- }
- else if (this.centerType == UIBasicSprite.AdvancedType.Sliced)
- {
- UIBasicSprite.Fill(verts, uvs, cols, UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y, UIBasicSprite.mTempPos[num2].y, UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y, UIBasicSprite.mTempUVs[num2].y, drawingColor);
- }
- }
- else if (i == 1)
- {
- if ((j == 0 && this.bottomType == UIBasicSprite.AdvancedType.Tiled) || (j == 2 && this.topType == UIBasicSprite.AdvancedType.Tiled))
- {
- float x4 = UIBasicSprite.mTempPos[i].x;
- float x5 = UIBasicSprite.mTempPos[num].x;
- float y4 = UIBasicSprite.mTempPos[j].y;
- float y5 = UIBasicSprite.mTempPos[num2].y;
- float x6 = UIBasicSprite.mTempUVs[i].x;
- float y6 = UIBasicSprite.mTempUVs[j].y;
- float y7 = UIBasicSprite.mTempUVs[num2].y;
- for (float num9 = x4; num9 < x5; num9 += a.x)
- {
- float num10 = num9 + a.x;
- float num11 = UIBasicSprite.mTempUVs[num].x;
- if (num10 > x5)
- {
- num11 = Mathf.Lerp(x6, num11, (x5 - num9) / a.x);
- num10 = x5;
- }
- UIBasicSprite.Fill(verts, uvs, cols, num9, num10, y4, y5, x6, num11, y6, y7, drawingColor);
- }
- }
- else if ((j == 0 && this.bottomType == UIBasicSprite.AdvancedType.Sliced) || (j == 2 && this.topType == UIBasicSprite.AdvancedType.Sliced))
- {
- UIBasicSprite.Fill(verts, uvs, cols, UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y, UIBasicSprite.mTempPos[num2].y, UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y, UIBasicSprite.mTempUVs[num2].y, drawingColor);
- }
- }
- else if (j == 1)
- {
- if ((i == 0 && this.leftType == UIBasicSprite.AdvancedType.Tiled) || (i == 2 && this.rightType == UIBasicSprite.AdvancedType.Tiled))
- {
- float x7 = UIBasicSprite.mTempPos[i].x;
- float x8 = UIBasicSprite.mTempPos[num].x;
- float y8 = UIBasicSprite.mTempPos[j].y;
- float y9 = UIBasicSprite.mTempPos[num2].y;
- float x9 = UIBasicSprite.mTempUVs[i].x;
- float x10 = UIBasicSprite.mTempUVs[num].x;
- float y10 = UIBasicSprite.mTempUVs[j].y;
- for (float num12 = y8; num12 < y9; num12 += a.y)
- {
- float num13 = UIBasicSprite.mTempUVs[num2].y;
- float num14 = num12 + a.y;
- if (num14 > y9)
- {
- num13 = Mathf.Lerp(y10, num13, (y9 - num12) / a.y);
- num14 = y9;
- }
- UIBasicSprite.Fill(verts, uvs, cols, x7, x8, num12, num14, x9, x10, y10, num13, drawingColor);
- }
- }
- else if ((i == 0 && this.leftType == UIBasicSprite.AdvancedType.Sliced) || (i == 2 && this.rightType == UIBasicSprite.AdvancedType.Sliced))
- {
- UIBasicSprite.Fill(verts, uvs, cols, UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y, UIBasicSprite.mTempPos[num2].y, UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y, UIBasicSprite.mTempUVs[num2].y, drawingColor);
- }
- }
- else
- {
- UIBasicSprite.Fill(verts, uvs, cols, UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y, UIBasicSprite.mTempPos[num2].y, UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y, UIBasicSprite.mTempUVs[num2].y, drawingColor);
- }
- }
- }
- }
- }
- private static bool RadialCut(Vector2[] xy, Vector2[] uv, float fill, bool invert, int corner)
- {
- if (fill < 0.001f)
- {
- return false;
- }
- if ((corner & 1) == 1)
- {
- invert = !invert;
- }
- if (!invert && fill > 0.999f)
- {
- return true;
- }
- float num = Mathf.Clamp01(fill);
- if (invert)
- {
- num = 1f - num;
- }
- num *= 1.5707964f;
- float cos = Mathf.Cos(num);
- float sin = Mathf.Sin(num);
- UIBasicSprite.RadialCut(xy, cos, sin, invert, corner);
- UIBasicSprite.RadialCut(uv, cos, sin, invert, corner);
- return true;
- }
- private static void RadialCut(Vector2[] xy, float cos, float sin, bool invert, int corner)
- {
- int num = NGUIMath.RepeatIndex(corner + 1, 4);
- int num2 = NGUIMath.RepeatIndex(corner + 2, 4);
- int num3 = NGUIMath.RepeatIndex(corner + 3, 4);
- if ((corner & 1) == 1)
- {
- if (sin > cos)
- {
- cos /= sin;
- sin = 1f;
- if (invert)
- {
- xy[num].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
- xy[num2].x = xy[num].x;
- }
- }
- else if (cos > sin)
- {
- sin /= cos;
- cos = 1f;
- if (!invert)
- {
- xy[num2].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
- xy[num3].y = xy[num2].y;
- }
- }
- else
- {
- cos = 1f;
- sin = 1f;
- }
- if (!invert)
- {
- xy[num3].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
- }
- else
- {
- xy[num].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
- }
- }
- else
- {
- if (cos > sin)
- {
- sin /= cos;
- cos = 1f;
- if (!invert)
- {
- xy[num].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
- xy[num2].y = xy[num].y;
- }
- }
- else if (sin > cos)
- {
- cos /= sin;
- sin = 1f;
- if (invert)
- {
- xy[num2].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
- xy[num3].x = xy[num2].x;
- }
- }
- else
- {
- cos = 1f;
- sin = 1f;
- }
- if (invert)
- {
- xy[num3].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
- }
- else
- {
- xy[num].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
- }
- }
- }
- private static void Fill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, float v0x, float v1x, float v0y, float v1y, float u0x, float u1x, float u0y, float u1y, Color col)
- {
- verts.Add(new Vector3(v0x, v0y));
- verts.Add(new Vector3(v0x, v1y));
- verts.Add(new Vector3(v1x, v1y));
- verts.Add(new Vector3(v1x, v0y));
- uvs.Add(new Vector2(u0x, u0y));
- uvs.Add(new Vector2(u0x, u1y));
- uvs.Add(new Vector2(u1x, u1y));
- uvs.Add(new Vector2(u1x, u0y));
- cols.Add(col);
- cols.Add(col);
- cols.Add(col);
- cols.Add(col);
- }
- [HideInInspector]
- [SerializeField]
- protected UIBasicSprite.Type mType;
- [HideInInspector]
- [SerializeField]
- protected UIBasicSprite.FillDirection mFillDirection = UIBasicSprite.FillDirection.Radial360;
- [Range(0f, 1f)]
- [HideInInspector]
- [SerializeField]
- protected float mFillAmount = 1f;
- [HideInInspector]
- [SerializeField]
- protected bool mInvert;
- [HideInInspector]
- [SerializeField]
- protected UIBasicSprite.Flip mFlip;
- [NonSerialized]
- private Rect mInnerUV = default(Rect);
- [NonSerialized]
- private Rect mOuterUV = default(Rect);
- public UIBasicSprite.AdvancedType centerType = UIBasicSprite.AdvancedType.Sliced;
- public UIBasicSprite.AdvancedType leftType = UIBasicSprite.AdvancedType.Sliced;
- public UIBasicSprite.AdvancedType rightType = UIBasicSprite.AdvancedType.Sliced;
- public UIBasicSprite.AdvancedType bottomType = UIBasicSprite.AdvancedType.Sliced;
- public UIBasicSprite.AdvancedType topType = UIBasicSprite.AdvancedType.Sliced;
- protected static Vector2[] mTempPos = new Vector2[4];
- protected static Vector2[] mTempUVs = new Vector2[4];
- public enum Type
- {
- Simple,
- Sliced,
- Tiled,
- Filled,
- Advanced
- }
- public enum FillDirection
- {
- Horizontal,
- Vertical,
- Radial90,
- Radial180,
- Radial360
- }
- public enum AdvancedType
- {
- Invisible,
- Sliced,
- Tiled
- }
- public enum Flip
- {
- Nothing,
- Horizontally,
- Vertically,
- Both
- }
- }
|