UIBasicSprite.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. using System;
  2. using UnityEngine;
  3. public abstract class UIBasicSprite : UIWidget
  4. {
  5. public virtual UIBasicSprite.Type type
  6. {
  7. get
  8. {
  9. return this.mType;
  10. }
  11. set
  12. {
  13. if (this.mType != value)
  14. {
  15. this.mType = value;
  16. this.MarkAsChanged();
  17. }
  18. }
  19. }
  20. public UIBasicSprite.Flip flip
  21. {
  22. get
  23. {
  24. return this.mFlip;
  25. }
  26. set
  27. {
  28. if (this.mFlip != value)
  29. {
  30. this.mFlip = value;
  31. this.MarkAsChanged();
  32. }
  33. }
  34. }
  35. public UIBasicSprite.FillDirection fillDirection
  36. {
  37. get
  38. {
  39. return this.mFillDirection;
  40. }
  41. set
  42. {
  43. if (this.mFillDirection != value)
  44. {
  45. this.mFillDirection = value;
  46. this.mChanged = true;
  47. }
  48. }
  49. }
  50. public float fillAmount
  51. {
  52. get
  53. {
  54. return this.mFillAmount;
  55. }
  56. set
  57. {
  58. float num = Mathf.Clamp01(value);
  59. if (this.mFillAmount != num)
  60. {
  61. this.mFillAmount = num;
  62. this.mChanged = true;
  63. }
  64. }
  65. }
  66. public override int minWidth
  67. {
  68. get
  69. {
  70. if (this.type == UIBasicSprite.Type.Sliced || this.type == UIBasicSprite.Type.Advanced)
  71. {
  72. Vector4 vector = this.border * this.pixelSize;
  73. int num = Mathf.RoundToInt(vector.x + vector.z);
  74. return Mathf.Max(base.minWidth, ((num & 1) != 1) ? num : (num + 1));
  75. }
  76. return base.minWidth;
  77. }
  78. }
  79. public override int minHeight
  80. {
  81. get
  82. {
  83. if (this.type == UIBasicSprite.Type.Sliced || this.type == UIBasicSprite.Type.Advanced)
  84. {
  85. Vector4 vector = this.border * this.pixelSize;
  86. int num = Mathf.RoundToInt(vector.y + vector.w);
  87. return Mathf.Max(base.minHeight, ((num & 1) != 1) ? num : (num + 1));
  88. }
  89. return base.minHeight;
  90. }
  91. }
  92. public bool invert
  93. {
  94. get
  95. {
  96. return this.mInvert;
  97. }
  98. set
  99. {
  100. if (this.mInvert != value)
  101. {
  102. this.mInvert = value;
  103. this.mChanged = true;
  104. }
  105. }
  106. }
  107. public bool hasBorder
  108. {
  109. get
  110. {
  111. Vector4 border = this.border;
  112. return border.x != 0f || border.y != 0f || border.z != 0f || border.w != 0f;
  113. }
  114. }
  115. public virtual bool premultipliedAlpha
  116. {
  117. get
  118. {
  119. return false;
  120. }
  121. }
  122. public virtual float pixelSize
  123. {
  124. get
  125. {
  126. return 1f;
  127. }
  128. }
  129. private Vector4 drawingUVs
  130. {
  131. get
  132. {
  133. switch (this.mFlip)
  134. {
  135. case UIBasicSprite.Flip.Horizontally:
  136. return new Vector4(this.mOuterUV.xMax, this.mOuterUV.yMin, this.mOuterUV.xMin, this.mOuterUV.yMax);
  137. case UIBasicSprite.Flip.Vertically:
  138. return new Vector4(this.mOuterUV.xMin, this.mOuterUV.yMax, this.mOuterUV.xMax, this.mOuterUV.yMin);
  139. case UIBasicSprite.Flip.Both:
  140. return new Vector4(this.mOuterUV.xMax, this.mOuterUV.yMax, this.mOuterUV.xMin, this.mOuterUV.yMin);
  141. default:
  142. return new Vector4(this.mOuterUV.xMin, this.mOuterUV.yMin, this.mOuterUV.xMax, this.mOuterUV.yMax);
  143. }
  144. }
  145. }
  146. private Color32 drawingColor
  147. {
  148. get
  149. {
  150. Color c = base.color;
  151. c.a = this.finalAlpha;
  152. if (this.premultipliedAlpha)
  153. {
  154. c = NGUITools.ApplyPMA(c);
  155. }
  156. if (QualitySettings.activeColorSpace == ColorSpace.Linear)
  157. {
  158. c.r = Mathf.Pow(c.r, 2.2f);
  159. c.g = Mathf.Pow(c.g, 2.2f);
  160. c.b = Mathf.Pow(c.b, 2.2f);
  161. }
  162. return c;
  163. }
  164. }
  165. protected void Fill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, Rect outer, Rect inner)
  166. {
  167. this.mOuterUV = outer;
  168. this.mInnerUV = inner;
  169. switch (this.type)
  170. {
  171. case UIBasicSprite.Type.Simple:
  172. this.SimpleFill(verts, uvs, cols);
  173. break;
  174. case UIBasicSprite.Type.Sliced:
  175. this.SlicedFill(verts, uvs, cols);
  176. break;
  177. case UIBasicSprite.Type.Tiled:
  178. this.TiledFill(verts, uvs, cols);
  179. break;
  180. case UIBasicSprite.Type.Filled:
  181. this.FilledFill(verts, uvs, cols);
  182. break;
  183. case UIBasicSprite.Type.Advanced:
  184. this.AdvancedFill(verts, uvs, cols);
  185. break;
  186. }
  187. }
  188. private void SimpleFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  189. {
  190. Vector4 drawingDimensions = this.drawingDimensions;
  191. Vector4 drawingUVs = this.drawingUVs;
  192. Color32 drawingColor = this.drawingColor;
  193. verts.Add(new Vector3(drawingDimensions.x, drawingDimensions.y));
  194. verts.Add(new Vector3(drawingDimensions.x, drawingDimensions.w));
  195. verts.Add(new Vector3(drawingDimensions.z, drawingDimensions.w));
  196. verts.Add(new Vector3(drawingDimensions.z, drawingDimensions.y));
  197. uvs.Add(new Vector2(drawingUVs.x, drawingUVs.y));
  198. uvs.Add(new Vector2(drawingUVs.x, drawingUVs.w));
  199. uvs.Add(new Vector2(drawingUVs.z, drawingUVs.w));
  200. uvs.Add(new Vector2(drawingUVs.z, drawingUVs.y));
  201. cols.Add(drawingColor);
  202. cols.Add(drawingColor);
  203. cols.Add(drawingColor);
  204. cols.Add(drawingColor);
  205. }
  206. private void SlicedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  207. {
  208. Vector4 vector = this.border * this.pixelSize;
  209. if (vector.x == 0f && vector.y == 0f && vector.z == 0f && vector.w == 0f)
  210. {
  211. this.SimpleFill(verts, uvs, cols);
  212. return;
  213. }
  214. Color32 drawingColor = this.drawingColor;
  215. Vector4 drawingDimensions = this.drawingDimensions;
  216. UIBasicSprite.mTempPos[0].x = drawingDimensions.x;
  217. UIBasicSprite.mTempPos[0].y = drawingDimensions.y;
  218. UIBasicSprite.mTempPos[3].x = drawingDimensions.z;
  219. UIBasicSprite.mTempPos[3].y = drawingDimensions.w;
  220. if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both)
  221. {
  222. UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.z;
  223. UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.x;
  224. UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMin;
  225. UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMin;
  226. UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMax;
  227. UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMax;
  228. }
  229. else
  230. {
  231. UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.x;
  232. UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.z;
  233. UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMin;
  234. UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMin;
  235. UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMax;
  236. UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMax;
  237. }
  238. if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both)
  239. {
  240. UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.w;
  241. UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.y;
  242. UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMin;
  243. UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMin;
  244. UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMax;
  245. UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMax;
  246. }
  247. else
  248. {
  249. UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.y;
  250. UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.w;
  251. UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMin;
  252. UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMin;
  253. UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMax;
  254. UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMax;
  255. }
  256. for (int i = 0; i < 3; i++)
  257. {
  258. int num = i + 1;
  259. for (int j = 0; j < 3; j++)
  260. {
  261. if (this.centerType != UIBasicSprite.AdvancedType.Invisible || i != 1 || j != 1)
  262. {
  263. int num2 = j + 1;
  264. verts.Add(new Vector3(UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[j].y));
  265. verts.Add(new Vector3(UIBasicSprite.mTempPos[i].x, UIBasicSprite.mTempPos[num2].y));
  266. verts.Add(new Vector3(UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[num2].y));
  267. verts.Add(new Vector3(UIBasicSprite.mTempPos[num].x, UIBasicSprite.mTempPos[j].y));
  268. uvs.Add(new Vector2(UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[j].y));
  269. uvs.Add(new Vector2(UIBasicSprite.mTempUVs[i].x, UIBasicSprite.mTempUVs[num2].y));
  270. uvs.Add(new Vector2(UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[num2].y));
  271. uvs.Add(new Vector2(UIBasicSprite.mTempUVs[num].x, UIBasicSprite.mTempUVs[j].y));
  272. cols.Add(drawingColor);
  273. cols.Add(drawingColor);
  274. cols.Add(drawingColor);
  275. cols.Add(drawingColor);
  276. }
  277. }
  278. }
  279. }
  280. private void TiledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  281. {
  282. Texture mainTexture = this.mainTexture;
  283. if (mainTexture == null)
  284. {
  285. return;
  286. }
  287. Vector2 a = new Vector2(this.mInnerUV.width * (float)mainTexture.width, this.mInnerUV.height * (float)mainTexture.height);
  288. a *= this.pixelSize;
  289. if (mainTexture == null || a.x < 2f || a.y < 2f)
  290. {
  291. return;
  292. }
  293. Color32 drawingColor = this.drawingColor;
  294. Vector4 drawingDimensions = this.drawingDimensions;
  295. Vector4 vector;
  296. if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both)
  297. {
  298. vector.x = this.mInnerUV.xMax;
  299. vector.z = this.mInnerUV.xMin;
  300. }
  301. else
  302. {
  303. vector.x = this.mInnerUV.xMin;
  304. vector.z = this.mInnerUV.xMax;
  305. }
  306. if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both)
  307. {
  308. vector.y = this.mInnerUV.yMax;
  309. vector.w = this.mInnerUV.yMin;
  310. }
  311. else
  312. {
  313. vector.y = this.mInnerUV.yMin;
  314. vector.w = this.mInnerUV.yMax;
  315. }
  316. float num = drawingDimensions.x;
  317. float num2 = drawingDimensions.y;
  318. float x = vector.x;
  319. float y = vector.y;
  320. while (num2 < drawingDimensions.w)
  321. {
  322. num = drawingDimensions.x;
  323. float num3 = num2 + a.y;
  324. float y2 = vector.w;
  325. if (num3 > drawingDimensions.w)
  326. {
  327. y2 = Mathf.Lerp(vector.y, vector.w, (drawingDimensions.w - num2) / a.y);
  328. num3 = drawingDimensions.w;
  329. }
  330. while (num < drawingDimensions.z)
  331. {
  332. float num4 = num + a.x;
  333. float x2 = vector.z;
  334. if (num4 > drawingDimensions.z)
  335. {
  336. x2 = Mathf.Lerp(vector.x, vector.z, (drawingDimensions.z - num) / a.x);
  337. num4 = drawingDimensions.z;
  338. }
  339. verts.Add(new Vector3(num, num2));
  340. verts.Add(new Vector3(num, num3));
  341. verts.Add(new Vector3(num4, num3));
  342. verts.Add(new Vector3(num4, num2));
  343. uvs.Add(new Vector2(x, y));
  344. uvs.Add(new Vector2(x, y2));
  345. uvs.Add(new Vector2(x2, y2));
  346. uvs.Add(new Vector2(x2, y));
  347. cols.Add(drawingColor);
  348. cols.Add(drawingColor);
  349. cols.Add(drawingColor);
  350. cols.Add(drawingColor);
  351. num += a.x;
  352. }
  353. num2 += a.y;
  354. }
  355. }
  356. private void FilledFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  357. {
  358. if (this.mFillAmount < 0.001f)
  359. {
  360. return;
  361. }
  362. Vector4 drawingDimensions = this.drawingDimensions;
  363. Vector4 drawingUVs = this.drawingUVs;
  364. Color32 drawingColor = this.drawingColor;
  365. if (this.mFillDirection == UIBasicSprite.FillDirection.Horizontal || this.mFillDirection == UIBasicSprite.FillDirection.Vertical)
  366. {
  367. if (this.mFillDirection == UIBasicSprite.FillDirection.Horizontal)
  368. {
  369. float num = (drawingUVs.z - drawingUVs.x) * this.mFillAmount;
  370. if (this.mInvert)
  371. {
  372. drawingDimensions.x = drawingDimensions.z - (drawingDimensions.z - drawingDimensions.x) * this.mFillAmount;
  373. drawingUVs.x = drawingUVs.z - num;
  374. }
  375. else
  376. {
  377. drawingDimensions.z = drawingDimensions.x + (drawingDimensions.z - drawingDimensions.x) * this.mFillAmount;
  378. drawingUVs.z = drawingUVs.x + num;
  379. }
  380. }
  381. else if (this.mFillDirection == UIBasicSprite.FillDirection.Vertical)
  382. {
  383. float num2 = (drawingUVs.w - drawingUVs.y) * this.mFillAmount;
  384. if (this.mInvert)
  385. {
  386. drawingDimensions.y = drawingDimensions.w - (drawingDimensions.w - drawingDimensions.y) * this.mFillAmount;
  387. drawingUVs.y = drawingUVs.w - num2;
  388. }
  389. else
  390. {
  391. drawingDimensions.w = drawingDimensions.y + (drawingDimensions.w - drawingDimensions.y) * this.mFillAmount;
  392. drawingUVs.w = drawingUVs.y + num2;
  393. }
  394. }
  395. }
  396. UIBasicSprite.mTempPos[0] = new Vector2(drawingDimensions.x, drawingDimensions.y);
  397. UIBasicSprite.mTempPos[1] = new Vector2(drawingDimensions.x, drawingDimensions.w);
  398. UIBasicSprite.mTempPos[2] = new Vector2(drawingDimensions.z, drawingDimensions.w);
  399. UIBasicSprite.mTempPos[3] = new Vector2(drawingDimensions.z, drawingDimensions.y);
  400. UIBasicSprite.mTempUVs[0] = new Vector2(drawingUVs.x, drawingUVs.y);
  401. UIBasicSprite.mTempUVs[1] = new Vector2(drawingUVs.x, drawingUVs.w);
  402. UIBasicSprite.mTempUVs[2] = new Vector2(drawingUVs.z, drawingUVs.w);
  403. UIBasicSprite.mTempUVs[3] = new Vector2(drawingUVs.z, drawingUVs.y);
  404. if (this.mFillAmount < 1f)
  405. {
  406. if (this.mFillDirection == UIBasicSprite.FillDirection.Radial90)
  407. {
  408. if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, this.mFillAmount, this.mInvert, 0))
  409. {
  410. for (int i = 0; i < 4; i++)
  411. {
  412. verts.Add(UIBasicSprite.mTempPos[i]);
  413. uvs.Add(UIBasicSprite.mTempUVs[i]);
  414. cols.Add(drawingColor);
  415. }
  416. }
  417. return;
  418. }
  419. if (this.mFillDirection == UIBasicSprite.FillDirection.Radial180)
  420. {
  421. for (int j = 0; j < 2; j++)
  422. {
  423. float t = 0f;
  424. float t2 = 1f;
  425. float t3;
  426. float t4;
  427. if (j == 0)
  428. {
  429. t3 = 0f;
  430. t4 = 0.5f;
  431. }
  432. else
  433. {
  434. t3 = 0.5f;
  435. t4 = 1f;
  436. }
  437. UIBasicSprite.mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t3);
  438. UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x;
  439. UIBasicSprite.mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t4);
  440. UIBasicSprite.mTempPos[3].x = UIBasicSprite.mTempPos[2].x;
  441. UIBasicSprite.mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t);
  442. UIBasicSprite.mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t2);
  443. UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[1].y;
  444. UIBasicSprite.mTempPos[3].y = UIBasicSprite.mTempPos[0].y;
  445. UIBasicSprite.mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t3);
  446. UIBasicSprite.mTempUVs[1].x = UIBasicSprite.mTempUVs[0].x;
  447. UIBasicSprite.mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t4);
  448. UIBasicSprite.mTempUVs[3].x = UIBasicSprite.mTempUVs[2].x;
  449. UIBasicSprite.mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t);
  450. UIBasicSprite.mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t2);
  451. UIBasicSprite.mTempUVs[2].y = UIBasicSprite.mTempUVs[1].y;
  452. UIBasicSprite.mTempUVs[3].y = UIBasicSprite.mTempUVs[0].y;
  453. float value = this.mInvert ? (this.mFillAmount * 2f - (float)(1 - j)) : (this.fillAmount * 2f - (float)j);
  454. if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, Mathf.Clamp01(value), !this.mInvert, NGUIMath.RepeatIndex(j + 3, 4)))
  455. {
  456. for (int k = 0; k < 4; k++)
  457. {
  458. verts.Add(UIBasicSprite.mTempPos[k]);
  459. uvs.Add(UIBasicSprite.mTempUVs[k]);
  460. cols.Add(drawingColor);
  461. }
  462. }
  463. }
  464. return;
  465. }
  466. if (this.mFillDirection == UIBasicSprite.FillDirection.Radial360)
  467. {
  468. for (int l = 0; l < 4; l++)
  469. {
  470. float t5;
  471. float t6;
  472. if (l < 2)
  473. {
  474. t5 = 0f;
  475. t6 = 0.5f;
  476. }
  477. else
  478. {
  479. t5 = 0.5f;
  480. t6 = 1f;
  481. }
  482. float t7;
  483. float t8;
  484. if (l == 0 || l == 3)
  485. {
  486. t7 = 0f;
  487. t8 = 0.5f;
  488. }
  489. else
  490. {
  491. t7 = 0.5f;
  492. t8 = 1f;
  493. }
  494. UIBasicSprite.mTempPos[0].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t5);
  495. UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x;
  496. UIBasicSprite.mTempPos[2].x = Mathf.Lerp(drawingDimensions.x, drawingDimensions.z, t6);
  497. UIBasicSprite.mTempPos[3].x = UIBasicSprite.mTempPos[2].x;
  498. UIBasicSprite.mTempPos[0].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t7);
  499. UIBasicSprite.mTempPos[1].y = Mathf.Lerp(drawingDimensions.y, drawingDimensions.w, t8);
  500. UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[1].y;
  501. UIBasicSprite.mTempPos[3].y = UIBasicSprite.mTempPos[0].y;
  502. UIBasicSprite.mTempUVs[0].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t5);
  503. UIBasicSprite.mTempUVs[1].x = UIBasicSprite.mTempUVs[0].x;
  504. UIBasicSprite.mTempUVs[2].x = Mathf.Lerp(drawingUVs.x, drawingUVs.z, t6);
  505. UIBasicSprite.mTempUVs[3].x = UIBasicSprite.mTempUVs[2].x;
  506. UIBasicSprite.mTempUVs[0].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t7);
  507. UIBasicSprite.mTempUVs[1].y = Mathf.Lerp(drawingUVs.y, drawingUVs.w, t8);
  508. UIBasicSprite.mTempUVs[2].y = UIBasicSprite.mTempUVs[1].y;
  509. UIBasicSprite.mTempUVs[3].y = UIBasicSprite.mTempUVs[0].y;
  510. float value2 = (!this.mInvert) ? (this.mFillAmount * 4f - (float)(3 - NGUIMath.RepeatIndex(l + 2, 4))) : (this.mFillAmount * 4f - (float)NGUIMath.RepeatIndex(l + 2, 4));
  511. if (UIBasicSprite.RadialCut(UIBasicSprite.mTempPos, UIBasicSprite.mTempUVs, Mathf.Clamp01(value2), this.mInvert, NGUIMath.RepeatIndex(l + 2, 4)))
  512. {
  513. for (int m = 0; m < 4; m++)
  514. {
  515. verts.Add(UIBasicSprite.mTempPos[m]);
  516. uvs.Add(UIBasicSprite.mTempUVs[m]);
  517. cols.Add(drawingColor);
  518. }
  519. }
  520. }
  521. return;
  522. }
  523. }
  524. for (int n = 0; n < 4; n++)
  525. {
  526. verts.Add(UIBasicSprite.mTempPos[n]);
  527. uvs.Add(UIBasicSprite.mTempUVs[n]);
  528. cols.Add(drawingColor);
  529. }
  530. }
  531. private void AdvancedFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  532. {
  533. Texture mainTexture = this.mainTexture;
  534. if (mainTexture == null)
  535. {
  536. return;
  537. }
  538. Vector4 vector = this.border * this.pixelSize;
  539. if (vector.x == 0f && vector.y == 0f && vector.z == 0f && vector.w == 0f)
  540. {
  541. this.SimpleFill(verts, uvs, cols);
  542. return;
  543. }
  544. Color32 drawingColor = this.drawingColor;
  545. Vector4 drawingDimensions = this.drawingDimensions;
  546. Vector2 a = new Vector2(this.mInnerUV.width * (float)mainTexture.width, this.mInnerUV.height * (float)mainTexture.height);
  547. a *= this.pixelSize;
  548. if (a.x < 1f)
  549. {
  550. a.x = 1f;
  551. }
  552. if (a.y < 1f)
  553. {
  554. a.y = 1f;
  555. }
  556. UIBasicSprite.mTempPos[0].x = drawingDimensions.x;
  557. UIBasicSprite.mTempPos[0].y = drawingDimensions.y;
  558. UIBasicSprite.mTempPos[3].x = drawingDimensions.z;
  559. UIBasicSprite.mTempPos[3].y = drawingDimensions.w;
  560. if (this.mFlip == UIBasicSprite.Flip.Horizontally || this.mFlip == UIBasicSprite.Flip.Both)
  561. {
  562. UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.z;
  563. UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.x;
  564. UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMin;
  565. UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMin;
  566. UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMax;
  567. UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMax;
  568. }
  569. else
  570. {
  571. UIBasicSprite.mTempPos[1].x = UIBasicSprite.mTempPos[0].x + vector.x;
  572. UIBasicSprite.mTempPos[2].x = UIBasicSprite.mTempPos[3].x - vector.z;
  573. UIBasicSprite.mTempUVs[0].x = this.mOuterUV.xMin;
  574. UIBasicSprite.mTempUVs[1].x = this.mInnerUV.xMin;
  575. UIBasicSprite.mTempUVs[2].x = this.mInnerUV.xMax;
  576. UIBasicSprite.mTempUVs[3].x = this.mOuterUV.xMax;
  577. }
  578. if (this.mFlip == UIBasicSprite.Flip.Vertically || this.mFlip == UIBasicSprite.Flip.Both)
  579. {
  580. UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.w;
  581. UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.y;
  582. UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMin;
  583. UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMin;
  584. UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMax;
  585. UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMax;
  586. }
  587. else
  588. {
  589. UIBasicSprite.mTempPos[1].y = UIBasicSprite.mTempPos[0].y + vector.y;
  590. UIBasicSprite.mTempPos[2].y = UIBasicSprite.mTempPos[3].y - vector.w;
  591. UIBasicSprite.mTempUVs[0].y = this.mOuterUV.yMin;
  592. UIBasicSprite.mTempUVs[1].y = this.mInnerUV.yMin;
  593. UIBasicSprite.mTempUVs[2].y = this.mInnerUV.yMax;
  594. UIBasicSprite.mTempUVs[3].y = this.mOuterUV.yMax;
  595. }
  596. for (int i = 0; i < 3; i++)
  597. {
  598. int num = i + 1;
  599. for (int j = 0; j < 3; j++)
  600. {
  601. if (this.centerType != UIBasicSprite.AdvancedType.Invisible || i != 1 || j != 1)
  602. {
  603. int num2 = j + 1;
  604. if (i == 1 && j == 1)
  605. {
  606. if (this.centerType == UIBasicSprite.AdvancedType.Tiled)
  607. {
  608. float x = UIBasicSprite.mTempPos[i].x;
  609. float x2 = UIBasicSprite.mTempPos[num].x;
  610. float y = UIBasicSprite.mTempPos[j].y;
  611. float y2 = UIBasicSprite.mTempPos[num2].y;
  612. float x3 = UIBasicSprite.mTempUVs[i].x;
  613. float y3 = UIBasicSprite.mTempUVs[j].y;
  614. for (float num3 = y; num3 < y2; num3 += a.y)
  615. {
  616. float num4 = x;
  617. float num5 = UIBasicSprite.mTempUVs[num2].y;
  618. float num6 = num3 + a.y;
  619. if (num6 > y2)
  620. {
  621. num5 = Mathf.Lerp(y3, num5, (y2 - num3) / a.y);
  622. num6 = y2;
  623. }
  624. while (num4 < x2)
  625. {
  626. float num7 = num4 + a.x;
  627. float num8 = UIBasicSprite.mTempUVs[num].x;
  628. if (num7 > x2)
  629. {
  630. num8 = Mathf.Lerp(x3, num8, (x2 - num4) / a.x);
  631. num7 = x2;
  632. }
  633. UIBasicSprite.Fill(verts, uvs, cols, num4, num7, num3, num6, x3, num8, y3, num5, drawingColor);
  634. num4 += a.x;
  635. }
  636. }
  637. }
  638. else if (this.centerType == UIBasicSprite.AdvancedType.Sliced)
  639. {
  640. 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);
  641. }
  642. }
  643. else if (i == 1)
  644. {
  645. if ((j == 0 && this.bottomType == UIBasicSprite.AdvancedType.Tiled) || (j == 2 && this.topType == UIBasicSprite.AdvancedType.Tiled))
  646. {
  647. float x4 = UIBasicSprite.mTempPos[i].x;
  648. float x5 = UIBasicSprite.mTempPos[num].x;
  649. float y4 = UIBasicSprite.mTempPos[j].y;
  650. float y5 = UIBasicSprite.mTempPos[num2].y;
  651. float x6 = UIBasicSprite.mTempUVs[i].x;
  652. float y6 = UIBasicSprite.mTempUVs[j].y;
  653. float y7 = UIBasicSprite.mTempUVs[num2].y;
  654. for (float num9 = x4; num9 < x5; num9 += a.x)
  655. {
  656. float num10 = num9 + a.x;
  657. float num11 = UIBasicSprite.mTempUVs[num].x;
  658. if (num10 > x5)
  659. {
  660. num11 = Mathf.Lerp(x6, num11, (x5 - num9) / a.x);
  661. num10 = x5;
  662. }
  663. UIBasicSprite.Fill(verts, uvs, cols, num9, num10, y4, y5, x6, num11, y6, y7, drawingColor);
  664. }
  665. }
  666. else if ((j == 0 && this.bottomType == UIBasicSprite.AdvancedType.Sliced) || (j == 2 && this.topType == UIBasicSprite.AdvancedType.Sliced))
  667. {
  668. 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);
  669. }
  670. }
  671. else if (j == 1)
  672. {
  673. if ((i == 0 && this.leftType == UIBasicSprite.AdvancedType.Tiled) || (i == 2 && this.rightType == UIBasicSprite.AdvancedType.Tiled))
  674. {
  675. float x7 = UIBasicSprite.mTempPos[i].x;
  676. float x8 = UIBasicSprite.mTempPos[num].x;
  677. float y8 = UIBasicSprite.mTempPos[j].y;
  678. float y9 = UIBasicSprite.mTempPos[num2].y;
  679. float x9 = UIBasicSprite.mTempUVs[i].x;
  680. float x10 = UIBasicSprite.mTempUVs[num].x;
  681. float y10 = UIBasicSprite.mTempUVs[j].y;
  682. for (float num12 = y8; num12 < y9; num12 += a.y)
  683. {
  684. float num13 = UIBasicSprite.mTempUVs[num2].y;
  685. float num14 = num12 + a.y;
  686. if (num14 > y9)
  687. {
  688. num13 = Mathf.Lerp(y10, num13, (y9 - num12) / a.y);
  689. num14 = y9;
  690. }
  691. UIBasicSprite.Fill(verts, uvs, cols, x7, x8, num12, num14, x9, x10, y10, num13, drawingColor);
  692. }
  693. }
  694. else if ((i == 0 && this.leftType == UIBasicSprite.AdvancedType.Sliced) || (i == 2 && this.rightType == UIBasicSprite.AdvancedType.Sliced))
  695. {
  696. 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);
  697. }
  698. }
  699. else
  700. {
  701. 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);
  702. }
  703. }
  704. }
  705. }
  706. }
  707. private static bool RadialCut(Vector2[] xy, Vector2[] uv, float fill, bool invert, int corner)
  708. {
  709. if (fill < 0.001f)
  710. {
  711. return false;
  712. }
  713. if ((corner & 1) == 1)
  714. {
  715. invert = !invert;
  716. }
  717. if (!invert && fill > 0.999f)
  718. {
  719. return true;
  720. }
  721. float num = Mathf.Clamp01(fill);
  722. if (invert)
  723. {
  724. num = 1f - num;
  725. }
  726. num *= 1.5707964f;
  727. float cos = Mathf.Cos(num);
  728. float sin = Mathf.Sin(num);
  729. UIBasicSprite.RadialCut(xy, cos, sin, invert, corner);
  730. UIBasicSprite.RadialCut(uv, cos, sin, invert, corner);
  731. return true;
  732. }
  733. private static void RadialCut(Vector2[] xy, float cos, float sin, bool invert, int corner)
  734. {
  735. int num = NGUIMath.RepeatIndex(corner + 1, 4);
  736. int num2 = NGUIMath.RepeatIndex(corner + 2, 4);
  737. int num3 = NGUIMath.RepeatIndex(corner + 3, 4);
  738. if ((corner & 1) == 1)
  739. {
  740. if (sin > cos)
  741. {
  742. cos /= sin;
  743. sin = 1f;
  744. if (invert)
  745. {
  746. xy[num].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
  747. xy[num2].x = xy[num].x;
  748. }
  749. }
  750. else if (cos > sin)
  751. {
  752. sin /= cos;
  753. cos = 1f;
  754. if (!invert)
  755. {
  756. xy[num2].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
  757. xy[num3].y = xy[num2].y;
  758. }
  759. }
  760. else
  761. {
  762. cos = 1f;
  763. sin = 1f;
  764. }
  765. if (!invert)
  766. {
  767. xy[num3].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
  768. }
  769. else
  770. {
  771. xy[num].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
  772. }
  773. }
  774. else
  775. {
  776. if (cos > sin)
  777. {
  778. sin /= cos;
  779. cos = 1f;
  780. if (!invert)
  781. {
  782. xy[num].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
  783. xy[num2].y = xy[num].y;
  784. }
  785. }
  786. else if (sin > cos)
  787. {
  788. cos /= sin;
  789. sin = 1f;
  790. if (invert)
  791. {
  792. xy[num2].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
  793. xy[num3].x = xy[num2].x;
  794. }
  795. }
  796. else
  797. {
  798. cos = 1f;
  799. sin = 1f;
  800. }
  801. if (invert)
  802. {
  803. xy[num3].y = Mathf.Lerp(xy[corner].y, xy[num2].y, sin);
  804. }
  805. else
  806. {
  807. xy[num].x = Mathf.Lerp(xy[corner].x, xy[num2].x, cos);
  808. }
  809. }
  810. }
  811. 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)
  812. {
  813. verts.Add(new Vector3(v0x, v0y));
  814. verts.Add(new Vector3(v0x, v1y));
  815. verts.Add(new Vector3(v1x, v1y));
  816. verts.Add(new Vector3(v1x, v0y));
  817. uvs.Add(new Vector2(u0x, u0y));
  818. uvs.Add(new Vector2(u0x, u1y));
  819. uvs.Add(new Vector2(u1x, u1y));
  820. uvs.Add(new Vector2(u1x, u0y));
  821. cols.Add(col);
  822. cols.Add(col);
  823. cols.Add(col);
  824. cols.Add(col);
  825. }
  826. [HideInInspector]
  827. [SerializeField]
  828. protected UIBasicSprite.Type mType;
  829. [HideInInspector]
  830. [SerializeField]
  831. protected UIBasicSprite.FillDirection mFillDirection = UIBasicSprite.FillDirection.Radial360;
  832. [Range(0f, 1f)]
  833. [HideInInspector]
  834. [SerializeField]
  835. protected float mFillAmount = 1f;
  836. [HideInInspector]
  837. [SerializeField]
  838. protected bool mInvert;
  839. [HideInInspector]
  840. [SerializeField]
  841. protected UIBasicSprite.Flip mFlip;
  842. [NonSerialized]
  843. private Rect mInnerUV = default(Rect);
  844. [NonSerialized]
  845. private Rect mOuterUV = default(Rect);
  846. public UIBasicSprite.AdvancedType centerType = UIBasicSprite.AdvancedType.Sliced;
  847. public UIBasicSprite.AdvancedType leftType = UIBasicSprite.AdvancedType.Sliced;
  848. public UIBasicSprite.AdvancedType rightType = UIBasicSprite.AdvancedType.Sliced;
  849. public UIBasicSprite.AdvancedType bottomType = UIBasicSprite.AdvancedType.Sliced;
  850. public UIBasicSprite.AdvancedType topType = UIBasicSprite.AdvancedType.Sliced;
  851. protected static Vector2[] mTempPos = new Vector2[4];
  852. protected static Vector2[] mTempUVs = new Vector2[4];
  853. public enum Type
  854. {
  855. Simple,
  856. Sliced,
  857. Tiled,
  858. Filled,
  859. Advanced
  860. }
  861. public enum FillDirection
  862. {
  863. Horizontal,
  864. Vertical,
  865. Radial90,
  866. Radial180,
  867. Radial360
  868. }
  869. public enum AdvancedType
  870. {
  871. Invisible,
  872. Sliced,
  873. Tiled
  874. }
  875. public enum Flip
  876. {
  877. Nothing,
  878. Horizontally,
  879. Vertically,
  880. Both
  881. }
  882. }