UIPanel.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. [ExecuteInEditMode]
  6. [AddComponentMenu("NGUI/UI/NGUI Panel")]
  7. public class UIPanel : UIRect
  8. {
  9. public static int nextUnusedDepth
  10. {
  11. get
  12. {
  13. int num = int.MinValue;
  14. int i = 0;
  15. int count = UIPanel.list.Count;
  16. while (i < count)
  17. {
  18. num = Mathf.Max(num, UIPanel.list[i].depth);
  19. i++;
  20. }
  21. return (num != int.MinValue) ? (num + 1) : 0;
  22. }
  23. }
  24. public override bool canBeAnchored
  25. {
  26. get
  27. {
  28. return this.mClipping != UIDrawCall.Clipping.None;
  29. }
  30. }
  31. public override float alpha
  32. {
  33. get
  34. {
  35. return this.mAlpha;
  36. }
  37. set
  38. {
  39. float num = Mathf.Clamp01(value);
  40. if (this.mAlpha != num)
  41. {
  42. this.mAlphaFrameID = -1;
  43. this.mResized = true;
  44. this.mAlpha = num;
  45. this.SetDirty();
  46. }
  47. }
  48. }
  49. public int depth
  50. {
  51. get
  52. {
  53. return this.mDepth;
  54. }
  55. set
  56. {
  57. if (this.mDepth != value)
  58. {
  59. this.mDepth = value;
  60. List<UIPanel> list = UIPanel.list;
  61. if (UIPanel.<>f__mg$cache0 == null)
  62. {
  63. UIPanel.<>f__mg$cache0 = new Comparison<UIPanel>(UIPanel.CompareFunc);
  64. }
  65. list.Sort(UIPanel.<>f__mg$cache0);
  66. }
  67. }
  68. }
  69. public int sortingOrder
  70. {
  71. get
  72. {
  73. return this.mSortingOrder;
  74. }
  75. set
  76. {
  77. if (this.mSortingOrder != value)
  78. {
  79. this.mSortingOrder = value;
  80. this.UpdateDrawCalls();
  81. }
  82. }
  83. }
  84. public static int CompareFunc(UIPanel a, UIPanel b)
  85. {
  86. if (!(a != b) || !(a != null) || !(b != null))
  87. {
  88. return 0;
  89. }
  90. if (a.mDepth < b.mDepth)
  91. {
  92. return -1;
  93. }
  94. if (a.mDepth > b.mDepth)
  95. {
  96. return 1;
  97. }
  98. return (a.GetInstanceID() >= b.GetInstanceID()) ? 1 : -1;
  99. }
  100. public float width
  101. {
  102. get
  103. {
  104. return this.GetViewSize().x;
  105. }
  106. }
  107. public float height
  108. {
  109. get
  110. {
  111. return this.GetViewSize().y;
  112. }
  113. }
  114. public bool halfPixelOffset
  115. {
  116. get
  117. {
  118. return this.mHalfPixelOffset;
  119. }
  120. }
  121. public bool usedForUI
  122. {
  123. get
  124. {
  125. return base.anchorCamera != null && this.mCam.orthographic;
  126. }
  127. }
  128. public Vector3 drawCallOffset
  129. {
  130. get
  131. {
  132. if (this.mHalfPixelOffset && base.anchorCamera != null && this.mCam.orthographic)
  133. {
  134. float num = 1f / this.GetWindowSize().y / this.mCam.orthographicSize;
  135. return new Vector3(-num, num);
  136. }
  137. return Vector3.zero;
  138. }
  139. }
  140. public UIDrawCall.Clipping clipping
  141. {
  142. get
  143. {
  144. return this.mClipping;
  145. }
  146. set
  147. {
  148. if (this.mClipping != value)
  149. {
  150. this.mResized = true;
  151. this.mClipping = value;
  152. this.mMatrixFrame = -1;
  153. }
  154. }
  155. }
  156. public UIPanel parentPanel
  157. {
  158. get
  159. {
  160. return this.mParentPanel;
  161. }
  162. }
  163. public int clipCount
  164. {
  165. get
  166. {
  167. int num = 0;
  168. UIPanel uipanel = this;
  169. while (uipanel != null)
  170. {
  171. if (uipanel.mClipping == UIDrawCall.Clipping.SoftClip || uipanel.mClipping == UIDrawCall.Clipping.TextureMask)
  172. {
  173. num++;
  174. }
  175. uipanel = uipanel.mParentPanel;
  176. }
  177. return num;
  178. }
  179. }
  180. public bool hasClipping
  181. {
  182. get
  183. {
  184. return this.mClipping == UIDrawCall.Clipping.SoftClip || this.mClipping == UIDrawCall.Clipping.TextureMask;
  185. }
  186. }
  187. public bool hasCumulativeClipping
  188. {
  189. get
  190. {
  191. return this.clipCount != 0;
  192. }
  193. }
  194. [Obsolete("Use 'hasClipping' or 'hasCumulativeClipping' instead")]
  195. public bool clipsChildren
  196. {
  197. get
  198. {
  199. return this.hasCumulativeClipping;
  200. }
  201. }
  202. public Vector2 clipOffset
  203. {
  204. get
  205. {
  206. return this.mClipOffset;
  207. }
  208. set
  209. {
  210. if (Mathf.Abs(this.mClipOffset.x - value.x) > 0.001f || Mathf.Abs(this.mClipOffset.y - value.y) > 0.001f)
  211. {
  212. this.mClipOffset = value;
  213. this.InvalidateClipping();
  214. if (this.onClipMove != null)
  215. {
  216. this.onClipMove(this);
  217. }
  218. }
  219. }
  220. }
  221. private void InvalidateClipping()
  222. {
  223. this.mResized = true;
  224. this.mMatrixFrame = -1;
  225. this.mCullTime = ((this.mCullTime != 0f) ? (RealTime.time + 0.15f) : 0.001f);
  226. int i = 0;
  227. int count = UIPanel.list.Count;
  228. while (i < count)
  229. {
  230. UIPanel uipanel = UIPanel.list[i];
  231. if (uipanel != this && uipanel.parentPanel == this)
  232. {
  233. uipanel.InvalidateClipping();
  234. }
  235. i++;
  236. }
  237. }
  238. public Texture2D clipTexture
  239. {
  240. get
  241. {
  242. return this.mClipTexture;
  243. }
  244. set
  245. {
  246. if (this.mClipTexture != value)
  247. {
  248. this.mClipTexture = value;
  249. }
  250. }
  251. }
  252. [Obsolete("Use 'finalClipRegion' or 'baseClipRegion' instead")]
  253. public Vector4 clipRange
  254. {
  255. get
  256. {
  257. return this.baseClipRegion;
  258. }
  259. set
  260. {
  261. this.baseClipRegion = value;
  262. }
  263. }
  264. public Vector4 baseClipRegion
  265. {
  266. get
  267. {
  268. return this.mClipRange;
  269. }
  270. set
  271. {
  272. if (Mathf.Abs(this.mClipRange.x - value.x) > 0.001f || Mathf.Abs(this.mClipRange.y - value.y) > 0.001f || Mathf.Abs(this.mClipRange.z - value.z) > 0.001f || Mathf.Abs(this.mClipRange.w - value.w) > 0.001f)
  273. {
  274. this.mResized = true;
  275. this.mCullTime = ((this.mCullTime != 0f) ? (RealTime.time + 0.15f) : 0.001f);
  276. this.mClipRange = value;
  277. this.mMatrixFrame = -1;
  278. UIScrollView component = base.GetComponent<UIScrollView>();
  279. if (component != null)
  280. {
  281. component.UpdatePosition();
  282. }
  283. if (this.onClipMove != null)
  284. {
  285. this.onClipMove(this);
  286. }
  287. }
  288. }
  289. }
  290. public Vector4 finalClipRegion
  291. {
  292. get
  293. {
  294. Vector2 viewSize = this.GetViewSize();
  295. if (this.mClipping != UIDrawCall.Clipping.None)
  296. {
  297. return new Vector4(this.mClipRange.x + this.mClipOffset.x, this.mClipRange.y + this.mClipOffset.y, viewSize.x, viewSize.y);
  298. }
  299. return new Vector4(0f, 0f, viewSize.x, viewSize.y);
  300. }
  301. }
  302. public Vector2 clipSoftness
  303. {
  304. get
  305. {
  306. return this.mClipSoftness;
  307. }
  308. set
  309. {
  310. if (this.mClipSoftness != value)
  311. {
  312. this.mClipSoftness = value;
  313. }
  314. }
  315. }
  316. public override Vector3[] localCorners
  317. {
  318. get
  319. {
  320. if (this.mClipping == UIDrawCall.Clipping.None)
  321. {
  322. Vector3[] worldCorners = this.worldCorners;
  323. Transform cachedTransform = base.cachedTransform;
  324. for (int i = 0; i < 4; i++)
  325. {
  326. worldCorners[i] = cachedTransform.InverseTransformPoint(worldCorners[i]);
  327. }
  328. return worldCorners;
  329. }
  330. float num = this.mClipOffset.x + this.mClipRange.x - 0.5f * this.mClipRange.z;
  331. float num2 = this.mClipOffset.y + this.mClipRange.y - 0.5f * this.mClipRange.w;
  332. float x = num + this.mClipRange.z;
  333. float y = num2 + this.mClipRange.w;
  334. UIPanel.mCorners[0] = new Vector3(num, num2);
  335. UIPanel.mCorners[1] = new Vector3(num, y);
  336. UIPanel.mCorners[2] = new Vector3(x, y);
  337. UIPanel.mCorners[3] = new Vector3(x, num2);
  338. return UIPanel.mCorners;
  339. }
  340. }
  341. public override Vector3[] worldCorners
  342. {
  343. get
  344. {
  345. if (this.mClipping != UIDrawCall.Clipping.None)
  346. {
  347. float num = this.mClipOffset.x + this.mClipRange.x - 0.5f * this.mClipRange.z;
  348. float num2 = this.mClipOffset.y + this.mClipRange.y - 0.5f * this.mClipRange.w;
  349. float x = num + this.mClipRange.z;
  350. float y = num2 + this.mClipRange.w;
  351. Transform cachedTransform = base.cachedTransform;
  352. UIPanel.mCorners[0] = cachedTransform.TransformPoint(num, num2, 0f);
  353. UIPanel.mCorners[1] = cachedTransform.TransformPoint(num, y, 0f);
  354. UIPanel.mCorners[2] = cachedTransform.TransformPoint(x, y, 0f);
  355. UIPanel.mCorners[3] = cachedTransform.TransformPoint(x, num2, 0f);
  356. }
  357. else
  358. {
  359. if (base.anchorCamera != null)
  360. {
  361. return this.mCam.GetWorldCorners(base.cameraRayDistance);
  362. }
  363. Vector2 viewSize = this.GetViewSize();
  364. float num3 = -0.5f * viewSize.x;
  365. float num4 = -0.5f * viewSize.y;
  366. float x2 = num3 + viewSize.x;
  367. float y2 = num4 + viewSize.y;
  368. UIPanel.mCorners[0] = new Vector3(num3, num4);
  369. UIPanel.mCorners[1] = new Vector3(num3, y2);
  370. UIPanel.mCorners[2] = new Vector3(x2, y2);
  371. UIPanel.mCorners[3] = new Vector3(x2, num4);
  372. if (this.anchorOffset && (this.mCam == null || this.mCam.transform.parent != base.cachedTransform))
  373. {
  374. Vector3 position = base.cachedTransform.position;
  375. for (int i = 0; i < 4; i++)
  376. {
  377. UIPanel.mCorners[i] += position;
  378. }
  379. }
  380. }
  381. return UIPanel.mCorners;
  382. }
  383. }
  384. public override Vector3[] GetSides(Transform relativeTo)
  385. {
  386. if (this.mClipping != UIDrawCall.Clipping.None)
  387. {
  388. float num = this.mClipOffset.x + this.mClipRange.x - 0.5f * this.mClipRange.z;
  389. float num2 = this.mClipOffset.y + this.mClipRange.y - 0.5f * this.mClipRange.w;
  390. float num3 = num + this.mClipRange.z;
  391. float num4 = num2 + this.mClipRange.w;
  392. float x = (num + num3) * 0.5f;
  393. float y = (num2 + num4) * 0.5f;
  394. Transform cachedTransform = base.cachedTransform;
  395. UIRect.mSides[0] = cachedTransform.TransformPoint(num, y, 0f);
  396. UIRect.mSides[1] = cachedTransform.TransformPoint(x, num4, 0f);
  397. UIRect.mSides[2] = cachedTransform.TransformPoint(num3, y, 0f);
  398. UIRect.mSides[3] = cachedTransform.TransformPoint(x, num2, 0f);
  399. if (relativeTo != null)
  400. {
  401. for (int i = 0; i < 4; i++)
  402. {
  403. UIRect.mSides[i] = relativeTo.InverseTransformPoint(UIRect.mSides[i]);
  404. }
  405. }
  406. return UIRect.mSides;
  407. }
  408. if (base.anchorCamera != null && this.anchorOffset)
  409. {
  410. Vector3[] sides = this.mCam.GetSides(base.cameraRayDistance);
  411. Vector3 position = base.cachedTransform.position;
  412. for (int j = 0; j < 4; j++)
  413. {
  414. sides[j] += position;
  415. }
  416. if (relativeTo != null)
  417. {
  418. for (int k = 0; k < 4; k++)
  419. {
  420. sides[k] = relativeTo.InverseTransformPoint(sides[k]);
  421. }
  422. }
  423. return sides;
  424. }
  425. return base.GetSides(relativeTo);
  426. }
  427. public override void Invalidate(bool includeChildren)
  428. {
  429. this.mAlphaFrameID = -1;
  430. base.Invalidate(includeChildren);
  431. }
  432. public override float CalculateFinalAlpha(int frameID)
  433. {
  434. if (this.mAlphaFrameID != frameID)
  435. {
  436. this.mAlphaFrameID = frameID;
  437. UIRect parent = base.parent;
  438. this.finalAlpha = ((!(base.parent != null)) ? this.mAlpha : (parent.CalculateFinalAlpha(frameID) * this.mAlpha));
  439. }
  440. return this.finalAlpha;
  441. }
  442. public override void SetRect(float x, float y, float width, float height)
  443. {
  444. int num = Mathf.FloorToInt(width + 0.5f);
  445. int num2 = Mathf.FloorToInt(height + 0.5f);
  446. num = num >> 1 << 1;
  447. num2 = num2 >> 1 << 1;
  448. Transform transform = base.cachedTransform;
  449. Vector3 localPosition = transform.localPosition;
  450. localPosition.x = Mathf.Floor(x + 0.5f);
  451. localPosition.y = Mathf.Floor(y + 0.5f);
  452. if (num < 2)
  453. {
  454. num = 2;
  455. }
  456. if (num2 < 2)
  457. {
  458. num2 = 2;
  459. }
  460. this.baseClipRegion = new Vector4(localPosition.x, localPosition.y, (float)num, (float)num2);
  461. if (base.isAnchored)
  462. {
  463. transform = transform.parent;
  464. if (this.leftAnchor.target)
  465. {
  466. this.leftAnchor.SetHorizontal(transform, x);
  467. }
  468. if (this.rightAnchor.target)
  469. {
  470. this.rightAnchor.SetHorizontal(transform, x + width);
  471. }
  472. if (this.bottomAnchor.target)
  473. {
  474. this.bottomAnchor.SetVertical(transform, y);
  475. }
  476. if (this.topAnchor.target)
  477. {
  478. this.topAnchor.SetVertical(transform, y + height);
  479. }
  480. }
  481. }
  482. public bool IsVisible(Vector3 a, Vector3 b, Vector3 c, Vector3 d)
  483. {
  484. this.UpdateTransformMatrix();
  485. a = this.worldToLocal.MultiplyPoint3x4(a);
  486. b = this.worldToLocal.MultiplyPoint3x4(b);
  487. c = this.worldToLocal.MultiplyPoint3x4(c);
  488. d = this.worldToLocal.MultiplyPoint3x4(d);
  489. UIPanel.mTemp[0] = a.x;
  490. UIPanel.mTemp[1] = b.x;
  491. UIPanel.mTemp[2] = c.x;
  492. UIPanel.mTemp[3] = d.x;
  493. float num = Mathf.Min(UIPanel.mTemp);
  494. float num2 = Mathf.Max(UIPanel.mTemp);
  495. UIPanel.mTemp[0] = a.y;
  496. UIPanel.mTemp[1] = b.y;
  497. UIPanel.mTemp[2] = c.y;
  498. UIPanel.mTemp[3] = d.y;
  499. float num3 = Mathf.Min(UIPanel.mTemp);
  500. float num4 = Mathf.Max(UIPanel.mTemp);
  501. return num2 >= this.mMin.x && num4 >= this.mMin.y && num <= this.mMax.x && num3 <= this.mMax.y;
  502. }
  503. public bool IsVisible(Vector3 worldPos)
  504. {
  505. if (this.mAlpha < 0.001f)
  506. {
  507. return false;
  508. }
  509. if (this.mClipping == UIDrawCall.Clipping.None || this.mClipping == UIDrawCall.Clipping.ConstrainButDontClip)
  510. {
  511. return true;
  512. }
  513. this.UpdateTransformMatrix();
  514. Vector3 vector = this.worldToLocal.MultiplyPoint3x4(worldPos);
  515. return vector.x >= this.mMin.x && vector.y >= this.mMin.y && vector.x <= this.mMax.x && vector.y <= this.mMax.y;
  516. }
  517. public bool IsVisible(UIWidget w)
  518. {
  519. UIPanel uipanel = this;
  520. Vector3[] array = null;
  521. while (uipanel != null)
  522. {
  523. if ((uipanel.mClipping == UIDrawCall.Clipping.None || uipanel.mClipping == UIDrawCall.Clipping.ConstrainButDontClip) && !w.hideIfOffScreen)
  524. {
  525. uipanel = uipanel.mParentPanel;
  526. }
  527. else
  528. {
  529. if (array == null)
  530. {
  531. array = w.worldCorners;
  532. }
  533. if (!uipanel.IsVisible(array[0], array[1], array[2], array[3]))
  534. {
  535. return false;
  536. }
  537. uipanel = uipanel.mParentPanel;
  538. }
  539. }
  540. return true;
  541. }
  542. public bool Affects(UIWidget w)
  543. {
  544. if (w == null)
  545. {
  546. return false;
  547. }
  548. UIPanel panel = w.panel;
  549. if (panel == null)
  550. {
  551. return false;
  552. }
  553. UIPanel uipanel = this;
  554. while (uipanel != null)
  555. {
  556. if (uipanel == panel)
  557. {
  558. return true;
  559. }
  560. if (!uipanel.hasCumulativeClipping)
  561. {
  562. return false;
  563. }
  564. uipanel = uipanel.mParentPanel;
  565. }
  566. return false;
  567. }
  568. [ContextMenu("Force Refresh")]
  569. public void RebuildAllDrawCalls()
  570. {
  571. this.mRebuild = true;
  572. }
  573. public void SetDirty()
  574. {
  575. int i = 0;
  576. int count = this.drawCalls.Count;
  577. while (i < count)
  578. {
  579. if (this.drawCalls[i] != null)
  580. {
  581. this.drawCalls[i].isDirty = true;
  582. }
  583. i++;
  584. }
  585. this.Invalidate(true);
  586. }
  587. private void Awake()
  588. {
  589. this.mGo = base.gameObject;
  590. this.mTrans = base.transform;
  591. this.mHalfPixelOffset = (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.XBOX360 || Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.WindowsEditor);
  592. if (this.mHalfPixelOffset)
  593. {
  594. this.mHalfPixelOffset = (SystemInfo.graphicsShaderLevel < 40 && SystemInfo.graphicsDeviceVersion.Contains("Direct3D"));
  595. }
  596. }
  597. private void FindParent()
  598. {
  599. Transform parent = base.cachedTransform.parent;
  600. this.mParentPanel = ((!(parent != null)) ? null : NGUITools.FindInParents<UIPanel>(parent.gameObject));
  601. }
  602. public override void ParentHasChanged()
  603. {
  604. base.ParentHasChanged();
  605. this.FindParent();
  606. }
  607. protected override void OnStart()
  608. {
  609. this.mLayer = this.mGo.layer;
  610. }
  611. protected override void OnEnable()
  612. {
  613. this.mRebuild = true;
  614. this.mAlphaFrameID = -1;
  615. this.mMatrixFrame = -1;
  616. this.OnStart();
  617. base.OnEnable();
  618. this.mMatrixFrame = -1;
  619. }
  620. protected override void OnInit()
  621. {
  622. if (UIPanel.list.Contains(this))
  623. {
  624. return;
  625. }
  626. base.OnInit();
  627. this.FindParent();
  628. if (base.GetComponent<Rigidbody>() == null && this.mParentPanel == null)
  629. {
  630. UICamera uicamera = (!(base.anchorCamera != null)) ? null : this.mCam.GetComponent<UICamera>();
  631. if (uicamera != null && (uicamera.eventType == UICamera.EventType.UI_3D || uicamera.eventType == UICamera.EventType.World_3D))
  632. {
  633. Rigidbody rigidbody = base.gameObject.AddComponent<Rigidbody>();
  634. rigidbody.isKinematic = true;
  635. rigidbody.useGravity = false;
  636. }
  637. }
  638. this.mRebuild = true;
  639. this.mAlphaFrameID = -1;
  640. this.mMatrixFrame = -1;
  641. UIPanel.list.Add(this);
  642. List<UIPanel> list = UIPanel.list;
  643. if (UIPanel.<>f__mg$cache1 == null)
  644. {
  645. UIPanel.<>f__mg$cache1 = new Comparison<UIPanel>(UIPanel.CompareFunc);
  646. }
  647. list.Sort(UIPanel.<>f__mg$cache1);
  648. }
  649. protected override void OnDisable()
  650. {
  651. int i = 0;
  652. int count = this.drawCalls.Count;
  653. while (i < count)
  654. {
  655. UIDrawCall uidrawCall = this.drawCalls[i];
  656. if (uidrawCall != null)
  657. {
  658. UIDrawCall.Destroy(uidrawCall);
  659. }
  660. i++;
  661. }
  662. this.drawCalls.Clear();
  663. UIPanel.list.Remove(this);
  664. this.mAlphaFrameID = -1;
  665. this.mMatrixFrame = -1;
  666. if (UIPanel.list.Count == 0)
  667. {
  668. UIDrawCall.ReleaseAll();
  669. UIPanel.mUpdateFrame = -1;
  670. }
  671. base.OnDisable();
  672. }
  673. private void UpdateTransformMatrix()
  674. {
  675. int frameCount = Time.frameCount;
  676. if (this.mMatrixFrame != frameCount)
  677. {
  678. this.mMatrixFrame = frameCount;
  679. this.worldToLocal = base.cachedTransform.worldToLocalMatrix;
  680. Vector2 vector = this.GetViewSize() * 0.5f;
  681. float num = this.mClipOffset.x + this.mClipRange.x;
  682. float num2 = this.mClipOffset.y + this.mClipRange.y;
  683. this.mMin.x = num - vector.x;
  684. this.mMin.y = num2 - vector.y;
  685. this.mMax.x = num + vector.x;
  686. this.mMax.y = num2 + vector.y;
  687. }
  688. }
  689. protected override void OnAnchor()
  690. {
  691. if (this.mClipping == UIDrawCall.Clipping.None)
  692. {
  693. return;
  694. }
  695. Transform cachedTransform = base.cachedTransform;
  696. Transform parent = cachedTransform.parent;
  697. Vector2 viewSize = this.GetViewSize();
  698. Vector2 vector = cachedTransform.localPosition;
  699. float num;
  700. float num2;
  701. float num3;
  702. float num4;
  703. if (this.leftAnchor.target == this.bottomAnchor.target && this.leftAnchor.target == this.rightAnchor.target && this.leftAnchor.target == this.topAnchor.target)
  704. {
  705. Vector3[] sides = this.leftAnchor.GetSides(parent);
  706. if (sides != null)
  707. {
  708. num = NGUIMath.Lerp(sides[0].x, sides[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute;
  709. num2 = NGUIMath.Lerp(sides[0].x, sides[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute;
  710. num3 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute;
  711. num4 = NGUIMath.Lerp(sides[3].y, sides[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute;
  712. }
  713. else
  714. {
  715. Vector2 vector2 = base.GetLocalPos(this.leftAnchor, parent);
  716. num = vector2.x + (float)this.leftAnchor.absolute;
  717. num3 = vector2.y + (float)this.bottomAnchor.absolute;
  718. num2 = vector2.x + (float)this.rightAnchor.absolute;
  719. num4 = vector2.y + (float)this.topAnchor.absolute;
  720. }
  721. }
  722. else
  723. {
  724. if (this.leftAnchor.target)
  725. {
  726. Vector3[] sides2 = this.leftAnchor.GetSides(parent);
  727. if (sides2 != null)
  728. {
  729. num = NGUIMath.Lerp(sides2[0].x, sides2[2].x, this.leftAnchor.relative) + (float)this.leftAnchor.absolute;
  730. }
  731. else
  732. {
  733. num = base.GetLocalPos(this.leftAnchor, parent).x + (float)this.leftAnchor.absolute;
  734. }
  735. }
  736. else
  737. {
  738. num = this.mClipRange.x - 0.5f * viewSize.x;
  739. }
  740. if (this.rightAnchor.target)
  741. {
  742. Vector3[] sides3 = this.rightAnchor.GetSides(parent);
  743. if (sides3 != null)
  744. {
  745. num2 = NGUIMath.Lerp(sides3[0].x, sides3[2].x, this.rightAnchor.relative) + (float)this.rightAnchor.absolute;
  746. }
  747. else
  748. {
  749. num2 = base.GetLocalPos(this.rightAnchor, parent).x + (float)this.rightAnchor.absolute;
  750. }
  751. }
  752. else
  753. {
  754. num2 = this.mClipRange.x + 0.5f * viewSize.x;
  755. }
  756. if (this.bottomAnchor.target)
  757. {
  758. Vector3[] sides4 = this.bottomAnchor.GetSides(parent);
  759. if (sides4 != null)
  760. {
  761. num3 = NGUIMath.Lerp(sides4[3].y, sides4[1].y, this.bottomAnchor.relative) + (float)this.bottomAnchor.absolute;
  762. }
  763. else
  764. {
  765. num3 = base.GetLocalPos(this.bottomAnchor, parent).y + (float)this.bottomAnchor.absolute;
  766. }
  767. }
  768. else
  769. {
  770. num3 = this.mClipRange.y - 0.5f * viewSize.y;
  771. }
  772. if (this.topAnchor.target)
  773. {
  774. Vector3[] sides5 = this.topAnchor.GetSides(parent);
  775. if (sides5 != null)
  776. {
  777. num4 = NGUIMath.Lerp(sides5[3].y, sides5[1].y, this.topAnchor.relative) + (float)this.topAnchor.absolute;
  778. }
  779. else
  780. {
  781. num4 = base.GetLocalPos(this.topAnchor, parent).y + (float)this.topAnchor.absolute;
  782. }
  783. }
  784. else
  785. {
  786. num4 = this.mClipRange.y + 0.5f * viewSize.y;
  787. }
  788. }
  789. num -= vector.x + this.mClipOffset.x;
  790. num2 -= vector.x + this.mClipOffset.x;
  791. num3 -= vector.y + this.mClipOffset.y;
  792. num4 -= vector.y + this.mClipOffset.y;
  793. float x = Mathf.Lerp(num, num2, 0.5f);
  794. float y = Mathf.Lerp(num3, num4, 0.5f);
  795. float num5 = num2 - num;
  796. float num6 = num4 - num3;
  797. float num7 = Mathf.Max(2f, this.mClipSoftness.x);
  798. float num8 = Mathf.Max(2f, this.mClipSoftness.y);
  799. if (num5 < num7)
  800. {
  801. num5 = num7;
  802. }
  803. if (num6 < num8)
  804. {
  805. num6 = num8;
  806. }
  807. this.baseClipRegion = new Vector4(x, y, num5, num6);
  808. }
  809. private void LateUpdate()
  810. {
  811. if (UIPanel.mUpdateFrame != Time.frameCount)
  812. {
  813. UIPanel.mUpdateFrame = Time.frameCount;
  814. int i = 0;
  815. int count = UIPanel.list.Count;
  816. while (i < count)
  817. {
  818. UIPanel.list[i].UpdateSelf();
  819. i++;
  820. }
  821. int num = 3000;
  822. int j = 0;
  823. int count2 = UIPanel.list.Count;
  824. while (j < count2)
  825. {
  826. UIPanel uipanel = UIPanel.list[j];
  827. if (uipanel.renderQueue == UIPanel.RenderQueue.Automatic)
  828. {
  829. uipanel.startingRenderQueue = num;
  830. uipanel.UpdateDrawCalls();
  831. num += uipanel.drawCalls.Count;
  832. }
  833. else if (uipanel.renderQueue == UIPanel.RenderQueue.StartAt)
  834. {
  835. uipanel.UpdateDrawCalls();
  836. if (uipanel.drawCalls.Count != 0)
  837. {
  838. num = Mathf.Max(num, uipanel.startingRenderQueue + uipanel.drawCalls.Count);
  839. }
  840. }
  841. else
  842. {
  843. uipanel.UpdateDrawCalls();
  844. if (uipanel.drawCalls.Count != 0)
  845. {
  846. num = Mathf.Max(num, uipanel.startingRenderQueue + 1);
  847. }
  848. }
  849. j++;
  850. }
  851. }
  852. }
  853. private void UpdateSelf()
  854. {
  855. this.mUpdateTime = RealTime.time;
  856. this.UpdateTransformMatrix();
  857. this.UpdateLayers();
  858. this.UpdateWidgets();
  859. if (this.mRebuild)
  860. {
  861. this.mRebuild = false;
  862. this.FillAllDrawCalls();
  863. }
  864. else
  865. {
  866. int i = 0;
  867. while (i < this.drawCalls.Count)
  868. {
  869. UIDrawCall uidrawCall = this.drawCalls[i];
  870. if (!(uidrawCall == null))
  871. {
  872. if (uidrawCall.isDirty && !this.FillDrawCall(uidrawCall))
  873. {
  874. UIDrawCall.Destroy(uidrawCall);
  875. this.drawCalls.RemoveAt(i);
  876. }
  877. else
  878. {
  879. i++;
  880. }
  881. }
  882. }
  883. }
  884. if (this.mUpdateScroll)
  885. {
  886. this.mUpdateScroll = false;
  887. UIScrollView component = base.GetComponent<UIScrollView>();
  888. if (component != null)
  889. {
  890. component.UpdateScrollbars();
  891. }
  892. }
  893. }
  894. public void SortWidgets()
  895. {
  896. this.mSortWidgets = false;
  897. List<UIWidget> list = this.widgets;
  898. if (UIPanel.<>f__mg$cache2 == null)
  899. {
  900. UIPanel.<>f__mg$cache2 = new Comparison<UIWidget>(UIWidget.PanelCompareFunc);
  901. }
  902. list.Sort(UIPanel.<>f__mg$cache2);
  903. }
  904. private void FillAllDrawCalls()
  905. {
  906. for (int i = 0; i < this.drawCalls.Count; i++)
  907. {
  908. UIDrawCall.Destroy(this.drawCalls[i]);
  909. }
  910. this.drawCalls.Clear();
  911. Material material = null;
  912. Texture texture = null;
  913. Shader shader = null;
  914. UIDrawCall uidrawCall = null;
  915. int num = 0;
  916. if (this.mSortWidgets)
  917. {
  918. this.SortWidgets();
  919. }
  920. for (int j = 0; j < this.widgets.Count; j++)
  921. {
  922. UIWidget uiwidget = this.widgets[j];
  923. if (uiwidget.isVisible && uiwidget.hasVertices)
  924. {
  925. Material material2 = uiwidget.material;
  926. Texture mainTexture = uiwidget.mainTexture;
  927. Shader shader2 = uiwidget.shader;
  928. if (material != material2 || texture != mainTexture || shader != shader2)
  929. {
  930. if (uidrawCall != null && uidrawCall.verts.size != 0)
  931. {
  932. this.drawCalls.Add(uidrawCall);
  933. uidrawCall.UpdateGeometry(num);
  934. uidrawCall.onRender = this.mOnRender;
  935. this.mOnRender = null;
  936. num = 0;
  937. uidrawCall = null;
  938. }
  939. material = material2;
  940. texture = mainTexture;
  941. shader = shader2;
  942. }
  943. if (material != null || shader != null || texture != null)
  944. {
  945. if (uidrawCall == null)
  946. {
  947. uidrawCall = UIDrawCall.Create(this, material, texture, shader);
  948. uidrawCall.depthStart = uiwidget.depth;
  949. uidrawCall.depthEnd = uidrawCall.depthStart;
  950. uidrawCall.panel = this;
  951. }
  952. else
  953. {
  954. int depth = uiwidget.depth;
  955. if (depth < uidrawCall.depthStart)
  956. {
  957. uidrawCall.depthStart = depth;
  958. }
  959. if (depth > uidrawCall.depthEnd)
  960. {
  961. uidrawCall.depthEnd = depth;
  962. }
  963. }
  964. uiwidget.drawCall = uidrawCall;
  965. num++;
  966. if (this.generateNormals)
  967. {
  968. uiwidget.WriteToBuffers(uidrawCall.verts, uidrawCall.uvs, uidrawCall.cols, uidrawCall.norms, uidrawCall.tans);
  969. }
  970. else
  971. {
  972. uiwidget.WriteToBuffers(uidrawCall.verts, uidrawCall.uvs, uidrawCall.cols, null, null);
  973. }
  974. if (uiwidget.mOnRender != null)
  975. {
  976. if (this.mOnRender == null)
  977. {
  978. this.mOnRender = uiwidget.mOnRender;
  979. }
  980. else
  981. {
  982. this.mOnRender = (UIDrawCall.OnRenderCallback)Delegate.Combine(this.mOnRender, uiwidget.mOnRender);
  983. }
  984. }
  985. }
  986. }
  987. else
  988. {
  989. uiwidget.drawCall = null;
  990. }
  991. }
  992. if (uidrawCall != null && uidrawCall.verts.size != 0)
  993. {
  994. this.drawCalls.Add(uidrawCall);
  995. uidrawCall.UpdateGeometry(num);
  996. uidrawCall.onRender = this.mOnRender;
  997. this.mOnRender = null;
  998. }
  999. }
  1000. private bool FillDrawCall(UIDrawCall dc)
  1001. {
  1002. if (dc != null)
  1003. {
  1004. dc.isDirty = false;
  1005. int num = 0;
  1006. int i = 0;
  1007. while (i < this.widgets.Count)
  1008. {
  1009. UIWidget uiwidget = this.widgets[i];
  1010. if (uiwidget == null)
  1011. {
  1012. this.widgets.RemoveAt(i);
  1013. }
  1014. else
  1015. {
  1016. if (uiwidget.drawCall == dc)
  1017. {
  1018. if (uiwidget.isVisible && uiwidget.hasVertices)
  1019. {
  1020. num++;
  1021. if (this.generateNormals)
  1022. {
  1023. uiwidget.WriteToBuffers(dc.verts, dc.uvs, dc.cols, dc.norms, dc.tans);
  1024. }
  1025. else
  1026. {
  1027. uiwidget.WriteToBuffers(dc.verts, dc.uvs, dc.cols, null, null);
  1028. }
  1029. if (uiwidget.mOnRender != null)
  1030. {
  1031. if (this.mOnRender == null)
  1032. {
  1033. this.mOnRender = uiwidget.mOnRender;
  1034. }
  1035. else
  1036. {
  1037. this.mOnRender = (UIDrawCall.OnRenderCallback)Delegate.Combine(this.mOnRender, uiwidget.mOnRender);
  1038. }
  1039. }
  1040. }
  1041. else
  1042. {
  1043. uiwidget.drawCall = null;
  1044. }
  1045. }
  1046. i++;
  1047. }
  1048. }
  1049. if (dc.verts.size != 0)
  1050. {
  1051. dc.UpdateGeometry(num);
  1052. dc.onRender = this.mOnRender;
  1053. this.mOnRender = null;
  1054. return true;
  1055. }
  1056. }
  1057. return false;
  1058. }
  1059. private void UpdateDrawCalls()
  1060. {
  1061. Transform cachedTransform = base.cachedTransform;
  1062. if (cachedTransform == null)
  1063. {
  1064. return;
  1065. }
  1066. bool usedForUI = this.usedForUI;
  1067. if (this.clipping != UIDrawCall.Clipping.None)
  1068. {
  1069. this.drawCallClipRange = this.finalClipRegion;
  1070. this.drawCallClipRange.z = this.drawCallClipRange.z * 0.5f;
  1071. this.drawCallClipRange.w = this.drawCallClipRange.w * 0.5f;
  1072. }
  1073. else
  1074. {
  1075. this.drawCallClipRange = Vector4.zero;
  1076. }
  1077. if (Application.isPlaying && GameMain.Instance != null && GameMain.Instance.VRMode)
  1078. {
  1079. if (this.drawCallClipRange.z == 0f)
  1080. {
  1081. this.drawCallClipRange.z = 640f;
  1082. }
  1083. if (this.drawCallClipRange.w == 0f)
  1084. {
  1085. this.drawCallClipRange.w = 360f;
  1086. }
  1087. }
  1088. else
  1089. {
  1090. if (this.drawCallClipRange.z == 0f)
  1091. {
  1092. this.drawCallClipRange.z = (float)UICamera.ScreenWidth * 0.5f;
  1093. }
  1094. if (this.drawCallClipRange.w == 0f)
  1095. {
  1096. this.drawCallClipRange.w = (float)UICamera.ScreenHeight * 0.5f;
  1097. }
  1098. }
  1099. if (this.halfPixelOffset)
  1100. {
  1101. this.drawCallClipRange.x = this.drawCallClipRange.x - 0.5f;
  1102. this.drawCallClipRange.y = this.drawCallClipRange.y + 0.5f;
  1103. }
  1104. Vector3 vector;
  1105. if (usedForUI)
  1106. {
  1107. Transform parent = base.cachedTransform.parent;
  1108. vector = base.cachedTransform.localPosition;
  1109. if (this.clipping != UIDrawCall.Clipping.None)
  1110. {
  1111. vector.x = (float)Mathf.RoundToInt(vector.x);
  1112. vector.y = (float)Mathf.RoundToInt(vector.y);
  1113. }
  1114. if (parent != null)
  1115. {
  1116. vector = parent.TransformPoint(vector);
  1117. }
  1118. vector += this.drawCallOffset;
  1119. }
  1120. else
  1121. {
  1122. vector = cachedTransform.position;
  1123. }
  1124. Quaternion rotation = cachedTransform.rotation;
  1125. Vector3 lossyScale = cachedTransform.lossyScale;
  1126. for (int i = 0; i < this.drawCalls.Count; i++)
  1127. {
  1128. UIDrawCall uidrawCall = this.drawCalls[i];
  1129. if (!(uidrawCall == null))
  1130. {
  1131. Transform cachedTransform2 = uidrawCall.cachedTransform;
  1132. cachedTransform2.position = vector;
  1133. cachedTransform2.rotation = rotation;
  1134. cachedTransform2.localScale = lossyScale;
  1135. uidrawCall.renderQueue = ((this.renderQueue != UIPanel.RenderQueue.Explicit) ? (this.startingRenderQueue + i) : this.startingRenderQueue);
  1136. uidrawCall.alwaysOnScreen = (this.alwaysOnScreen && (this.mClipping == UIDrawCall.Clipping.None || this.mClipping == UIDrawCall.Clipping.ConstrainButDontClip));
  1137. uidrawCall.sortingOrder = this.mSortingOrder;
  1138. uidrawCall.clipTexture = this.mClipTexture;
  1139. }
  1140. }
  1141. }
  1142. private void UpdateLayers()
  1143. {
  1144. if (this.mLayer != base.cachedGameObject.layer)
  1145. {
  1146. this.mLayer = this.mGo.layer;
  1147. NGUITools.SetChildLayer(base.cachedTransform, this.mLayer);
  1148. base.ResetAnchors();
  1149. for (int i = 0; i < this.drawCalls.Count; i++)
  1150. {
  1151. if (this.drawCalls[i] != null)
  1152. {
  1153. this.drawCalls[i].gameObject.layer = this.mLayer;
  1154. }
  1155. }
  1156. }
  1157. }
  1158. private void UpdateWidgets()
  1159. {
  1160. bool flag = !this.cullWhileDragging && this.mCullTime > this.mUpdateTime;
  1161. bool flag2 = false;
  1162. if (this.mForced != flag)
  1163. {
  1164. this.mForced = flag;
  1165. this.mResized = true;
  1166. }
  1167. bool hasCumulativeClipping = this.hasCumulativeClipping;
  1168. int i = 0;
  1169. int count = this.widgets.Count;
  1170. while (i < count)
  1171. {
  1172. UIWidget uiwidget = this.widgets[i];
  1173. if (uiwidget.panel == this && uiwidget.enabled)
  1174. {
  1175. int frameCount = Time.frameCount;
  1176. if (uiwidget.UpdateTransform(frameCount) || this.mResized)
  1177. {
  1178. bool visibleByAlpha = flag || uiwidget.CalculateCumulativeAlpha(frameCount) > 0.001f;
  1179. uiwidget.UpdateVisibility(visibleByAlpha, flag || (!hasCumulativeClipping && !uiwidget.hideIfOffScreen) || this.IsVisible(uiwidget));
  1180. }
  1181. if (uiwidget.UpdateGeometry(frameCount))
  1182. {
  1183. flag2 = true;
  1184. if (!this.mRebuild)
  1185. {
  1186. if (uiwidget.drawCall != null)
  1187. {
  1188. uiwidget.drawCall.isDirty = true;
  1189. }
  1190. else
  1191. {
  1192. this.FindDrawCall(uiwidget);
  1193. }
  1194. }
  1195. }
  1196. }
  1197. i++;
  1198. }
  1199. if (flag2 && this.onGeometryUpdated != null)
  1200. {
  1201. this.onGeometryUpdated();
  1202. }
  1203. this.mResized = false;
  1204. }
  1205. public UIDrawCall FindDrawCall(UIWidget w)
  1206. {
  1207. Material material = w.material;
  1208. Texture mainTexture = w.mainTexture;
  1209. int depth = w.depth;
  1210. for (int i = 0; i < this.drawCalls.Count; i++)
  1211. {
  1212. UIDrawCall uidrawCall = this.drawCalls[i];
  1213. if (!(uidrawCall == null))
  1214. {
  1215. int num = (i != 0) ? (this.drawCalls[i - 1].depthEnd + 1) : int.MinValue;
  1216. int num2 = (i + 1 != this.drawCalls.Count) ? (this.drawCalls[i + 1].depthStart - 1) : int.MaxValue;
  1217. if (num <= depth && num2 >= depth)
  1218. {
  1219. if (uidrawCall.baseMaterial == material && uidrawCall.mainTexture == mainTexture)
  1220. {
  1221. if (w.isVisible)
  1222. {
  1223. w.drawCall = uidrawCall;
  1224. if (w.hasVertices)
  1225. {
  1226. uidrawCall.isDirty = true;
  1227. }
  1228. return uidrawCall;
  1229. }
  1230. }
  1231. else
  1232. {
  1233. this.mRebuild = true;
  1234. }
  1235. return null;
  1236. }
  1237. }
  1238. }
  1239. this.mRebuild = true;
  1240. return null;
  1241. }
  1242. public void AddWidget(UIWidget w)
  1243. {
  1244. this.mUpdateScroll = true;
  1245. if (this.widgets.Count == 0)
  1246. {
  1247. this.widgets.Add(w);
  1248. }
  1249. else if (this.mSortWidgets)
  1250. {
  1251. this.widgets.Add(w);
  1252. this.SortWidgets();
  1253. }
  1254. else if (UIWidget.PanelCompareFunc(w, this.widgets[0]) == -1)
  1255. {
  1256. this.widgets.Insert(0, w);
  1257. }
  1258. else
  1259. {
  1260. int i = this.widgets.Count;
  1261. while (i > 0)
  1262. {
  1263. if (UIWidget.PanelCompareFunc(w, this.widgets[--i]) != -1)
  1264. {
  1265. this.widgets.Insert(i + 1, w);
  1266. break;
  1267. }
  1268. }
  1269. }
  1270. this.FindDrawCall(w);
  1271. }
  1272. public void RemoveWidget(UIWidget w)
  1273. {
  1274. if (this.widgets.Remove(w) && w.drawCall != null)
  1275. {
  1276. int depth = w.depth;
  1277. if (depth == w.drawCall.depthStart || depth == w.drawCall.depthEnd)
  1278. {
  1279. this.mRebuild = true;
  1280. }
  1281. w.drawCall.isDirty = true;
  1282. w.drawCall = null;
  1283. }
  1284. }
  1285. public void Refresh()
  1286. {
  1287. this.mRebuild = true;
  1288. UIPanel.mUpdateFrame = -1;
  1289. if (UIPanel.list.Count > 0)
  1290. {
  1291. UIPanel.list[0].LateUpdate();
  1292. }
  1293. }
  1294. public virtual Vector3 CalculateConstrainOffset(Vector2 min, Vector2 max)
  1295. {
  1296. Vector4 finalClipRegion = this.finalClipRegion;
  1297. float num = finalClipRegion.z * 0.5f;
  1298. float num2 = finalClipRegion.w * 0.5f;
  1299. Vector2 minRect = new Vector2(min.x, min.y);
  1300. Vector2 maxRect = new Vector2(max.x, max.y);
  1301. Vector2 minArea = new Vector2(finalClipRegion.x - num, finalClipRegion.y - num2);
  1302. Vector2 maxArea = new Vector2(finalClipRegion.x + num, finalClipRegion.y + num2);
  1303. if (this.softBorderPadding && this.clipping == UIDrawCall.Clipping.SoftClip)
  1304. {
  1305. minArea.x += this.mClipSoftness.x;
  1306. minArea.y += this.mClipSoftness.y;
  1307. maxArea.x -= this.mClipSoftness.x;
  1308. maxArea.y -= this.mClipSoftness.y;
  1309. }
  1310. return NGUIMath.ConstrainRect(minRect, maxRect, minArea, maxArea);
  1311. }
  1312. public bool ConstrainTargetToBounds(Transform target, ref Bounds targetBounds, bool immediate)
  1313. {
  1314. Vector3 vector = targetBounds.min;
  1315. Vector3 vector2 = targetBounds.max;
  1316. float num = 1f;
  1317. if (this.mClipping == UIDrawCall.Clipping.None)
  1318. {
  1319. UIRoot root = base.root;
  1320. if (root != null)
  1321. {
  1322. num = root.pixelSizeAdjustment;
  1323. }
  1324. }
  1325. if (num != 1f)
  1326. {
  1327. vector /= num;
  1328. vector2 /= num;
  1329. }
  1330. Vector3 b = this.CalculateConstrainOffset(vector, vector2) * num;
  1331. if (b.sqrMagnitude > 0f)
  1332. {
  1333. if (immediate)
  1334. {
  1335. target.localPosition += b;
  1336. targetBounds.center += b;
  1337. SpringPosition component = target.GetComponent<SpringPosition>();
  1338. if (component != null)
  1339. {
  1340. component.enabled = false;
  1341. }
  1342. }
  1343. else
  1344. {
  1345. SpringPosition springPosition = SpringPosition.Begin(target.gameObject, target.localPosition + b, 13f);
  1346. springPosition.ignoreTimeScale = true;
  1347. springPosition.worldSpace = false;
  1348. }
  1349. return true;
  1350. }
  1351. return false;
  1352. }
  1353. public bool ConstrainTargetToBounds(Transform target, bool immediate)
  1354. {
  1355. Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(base.cachedTransform, target);
  1356. return this.ConstrainTargetToBounds(target, ref bounds, immediate);
  1357. }
  1358. public static UIPanel Find(Transform trans)
  1359. {
  1360. return UIPanel.Find(trans, false, -1);
  1361. }
  1362. public static UIPanel Find(Transform trans, bool createIfMissing)
  1363. {
  1364. return UIPanel.Find(trans, createIfMissing, -1);
  1365. }
  1366. public static UIPanel Find(Transform trans, bool createIfMissing, int layer)
  1367. {
  1368. UIPanel uipanel = NGUITools.FindInParents<UIPanel>(trans);
  1369. if (uipanel != null)
  1370. {
  1371. return uipanel;
  1372. }
  1373. return (!createIfMissing) ? null : NGUITools.CreateUI(trans, false, layer);
  1374. }
  1375. private Vector2 GetWindowSize()
  1376. {
  1377. UIRoot root = base.root;
  1378. Vector2 vector = NGUITools.screenSize;
  1379. if (root != null)
  1380. {
  1381. vector *= root.GetPixelSizeAdjustment(Mathf.RoundToInt(vector.y));
  1382. }
  1383. return vector;
  1384. }
  1385. public Vector2 GetViewSize()
  1386. {
  1387. if (this.mClipping != UIDrawCall.Clipping.None)
  1388. {
  1389. return new Vector2(this.mClipRange.z, this.mClipRange.w);
  1390. }
  1391. return NGUITools.screenSize;
  1392. }
  1393. public static List<UIPanel> list = new List<UIPanel>();
  1394. public UIPanel.OnGeometryUpdated onGeometryUpdated;
  1395. public bool showInPanelTool = true;
  1396. public bool generateNormals;
  1397. public bool widgetsAreStatic;
  1398. public bool cullWhileDragging = true;
  1399. public bool alwaysOnScreen;
  1400. public bool anchorOffset;
  1401. public bool softBorderPadding = true;
  1402. public UIPanel.RenderQueue renderQueue;
  1403. public int startingRenderQueue = 3000;
  1404. [NonSerialized]
  1405. public List<UIWidget> widgets = new List<UIWidget>();
  1406. [NonSerialized]
  1407. public List<UIDrawCall> drawCalls = new List<UIDrawCall>();
  1408. [NonSerialized]
  1409. public Matrix4x4 worldToLocal = Matrix4x4.identity;
  1410. [NonSerialized]
  1411. public Vector4 drawCallClipRange = new Vector4(0f, 0f, 1f, 1f);
  1412. public UIPanel.OnClippingMoved onClipMove;
  1413. [HideInInspector]
  1414. [SerializeField]
  1415. private Texture2D mClipTexture;
  1416. [HideInInspector]
  1417. [SerializeField]
  1418. private float mAlpha = 1f;
  1419. [HideInInspector]
  1420. [SerializeField]
  1421. private UIDrawCall.Clipping mClipping;
  1422. [HideInInspector]
  1423. [SerializeField]
  1424. private Vector4 mClipRange = new Vector4(0f, 0f, 300f, 200f);
  1425. [HideInInspector]
  1426. [SerializeField]
  1427. private Vector2 mClipSoftness = new Vector2(4f, 4f);
  1428. [HideInInspector]
  1429. [SerializeField]
  1430. private int mDepth;
  1431. [HideInInspector]
  1432. [SerializeField]
  1433. private int mSortingOrder;
  1434. private bool mRebuild;
  1435. private bool mResized;
  1436. [SerializeField]
  1437. private Vector2 mClipOffset = Vector2.zero;
  1438. private float mCullTime;
  1439. private float mUpdateTime;
  1440. private int mMatrixFrame = -1;
  1441. private int mAlphaFrameID;
  1442. private int mLayer = -1;
  1443. private static float[] mTemp = new float[4];
  1444. private Vector2 mMin = Vector2.zero;
  1445. private Vector2 mMax = Vector2.zero;
  1446. private bool mHalfPixelOffset;
  1447. private bool mSortWidgets;
  1448. private bool mUpdateScroll;
  1449. private UIPanel mParentPanel;
  1450. private static Vector3[] mCorners = new Vector3[4];
  1451. private static int mUpdateFrame = -1;
  1452. private UIDrawCall.OnRenderCallback mOnRender;
  1453. private bool mForced;
  1454. [CompilerGenerated]
  1455. private static Comparison<UIPanel> <>f__mg$cache0;
  1456. [CompilerGenerated]
  1457. private static Comparison<UIPanel> <>f__mg$cache1;
  1458. [CompilerGenerated]
  1459. private static Comparison<UIWidget> <>f__mg$cache2;
  1460. public enum RenderQueue
  1461. {
  1462. Automatic,
  1463. StartAt,
  1464. Explicit
  1465. }
  1466. public delegate void OnGeometryUpdated();
  1467. public delegate void OnClippingMoved(UIPanel panel);
  1468. }