UIDrawCall.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. [ExecuteInEditMode]
  5. [AddComponentMenu("NGUI/Internal/Draw Call")]
  6. public class UIDrawCall : MonoBehaviour
  7. {
  8. [Obsolete("Use UIDrawCall.activeList")]
  9. public static BetterList<UIDrawCall> list
  10. {
  11. get
  12. {
  13. return UIDrawCall.mActiveList;
  14. }
  15. }
  16. public static BetterList<UIDrawCall> activeList
  17. {
  18. get
  19. {
  20. return UIDrawCall.mActiveList;
  21. }
  22. }
  23. public static BetterList<UIDrawCall> inactiveList
  24. {
  25. get
  26. {
  27. return UIDrawCall.mInactiveList;
  28. }
  29. }
  30. public int renderQueue
  31. {
  32. get
  33. {
  34. return this.mRenderQueue;
  35. }
  36. set
  37. {
  38. if (this.mRenderQueue != value)
  39. {
  40. this.mRenderQueue = value;
  41. if (this.mDynamicMat != null)
  42. {
  43. this.mDynamicMat.renderQueue = value;
  44. }
  45. }
  46. }
  47. }
  48. public int sortingOrder
  49. {
  50. get
  51. {
  52. return (!(this.mRenderer != null)) ? 0 : this.mRenderer.sortingOrder;
  53. }
  54. set
  55. {
  56. if (this.mRenderer != null && this.mRenderer.sortingOrder != value)
  57. {
  58. this.mRenderer.sortingOrder = value;
  59. }
  60. }
  61. }
  62. public int finalRenderQueue
  63. {
  64. get
  65. {
  66. return (!(this.mDynamicMat != null)) ? this.mRenderQueue : this.mDynamicMat.renderQueue;
  67. }
  68. }
  69. public Transform cachedTransform
  70. {
  71. get
  72. {
  73. if (this.mTrans == null)
  74. {
  75. this.mTrans = base.transform;
  76. }
  77. return this.mTrans;
  78. }
  79. }
  80. public Material baseMaterial
  81. {
  82. get
  83. {
  84. return this.mMaterial;
  85. }
  86. set
  87. {
  88. if (this.mMaterial != value)
  89. {
  90. this.mMaterial = value;
  91. this.mRebuildMat = true;
  92. }
  93. }
  94. }
  95. public Material dynamicMaterial
  96. {
  97. get
  98. {
  99. return this.mDynamicMat;
  100. }
  101. }
  102. public Texture mainTexture
  103. {
  104. get
  105. {
  106. return this.mTexture;
  107. }
  108. set
  109. {
  110. this.mTexture = value;
  111. if (this.mDynamicMat != null)
  112. {
  113. this.mDynamicMat.mainTexture = value;
  114. }
  115. }
  116. }
  117. public Shader shader
  118. {
  119. get
  120. {
  121. return this.mShader;
  122. }
  123. set
  124. {
  125. if (this.mShader != value)
  126. {
  127. this.mShader = value;
  128. this.mRebuildMat = true;
  129. }
  130. }
  131. }
  132. public int triangles
  133. {
  134. get
  135. {
  136. return (!(this.mMesh != null)) ? 0 : this.mTriangles;
  137. }
  138. }
  139. public bool isClipped
  140. {
  141. get
  142. {
  143. return this.mClipCount != 0;
  144. }
  145. }
  146. private void CreateMaterial()
  147. {
  148. this.mTextureClip = false;
  149. this.mLegacyShader = false;
  150. this.mClipCount = this.panel.clipCount;
  151. string text = (!(this.mShader != null)) ? ((!(this.mMaterial != null)) ? "Unlit/Transparent Colored" : this.mMaterial.shader.name) : this.mShader.name;
  152. text = text.Replace("GUI/Text Shader", "Unlit/Text");
  153. if (text.Length > 2 && text[text.Length - 2] == ' ')
  154. {
  155. int num = (int)text[text.Length - 1];
  156. if (num > 48 && num <= 57)
  157. {
  158. text = text.Substring(0, text.Length - 2);
  159. }
  160. }
  161. if (text.StartsWith("Hidden/"))
  162. {
  163. text = text.Substring(7);
  164. }
  165. text = text.Replace(" (SoftClip)", string.Empty);
  166. text = text.Replace(" (TextureClip)", string.Empty);
  167. if (this.panel.clipping == UIDrawCall.Clipping.TextureMask)
  168. {
  169. this.mTextureClip = true;
  170. this.shader = Shader.Find("Hidden/" + text + " (TextureClip)");
  171. }
  172. else if (this.mClipCount != 0)
  173. {
  174. this.shader = Shader.Find(string.Concat(new object[]
  175. {
  176. "Hidden/",
  177. text,
  178. " ",
  179. this.mClipCount
  180. }));
  181. if (this.shader == null)
  182. {
  183. this.shader = Shader.Find(text + " " + this.mClipCount);
  184. }
  185. if (this.shader == null && this.mClipCount == 1)
  186. {
  187. this.mLegacyShader = true;
  188. this.shader = Shader.Find(text + " (SoftClip)");
  189. }
  190. }
  191. else
  192. {
  193. this.shader = Shader.Find(text);
  194. }
  195. if (this.shader == null)
  196. {
  197. this.shader = Shader.Find("Unlit/Transparent Colored");
  198. }
  199. if (this.mMaterial != null)
  200. {
  201. this.mDynamicMat = new Material(this.mMaterial);
  202. this.mDynamicMat.name = "[NGUI] " + this.mMaterial.name;
  203. this.mDynamicMat.hideFlags = (HideFlags.DontSaveInEditor | HideFlags.NotEditable | HideFlags.DontSaveInBuild | HideFlags.DontUnloadUnusedAsset);
  204. this.mDynamicMat.CopyPropertiesFromMaterial(this.mMaterial);
  205. string[] shaderKeywords = this.mMaterial.shaderKeywords;
  206. for (int i = 0; i < shaderKeywords.Length; i++)
  207. {
  208. this.mDynamicMat.EnableKeyword(shaderKeywords[i]);
  209. }
  210. if (this.shader != null)
  211. {
  212. this.mDynamicMat.shader = this.shader;
  213. }
  214. else if (this.mClipCount != 0)
  215. {
  216. Debug.LogError(string.Concat(new object[]
  217. {
  218. text,
  219. " shader doesn't have a clipped shader version for ",
  220. this.mClipCount,
  221. " clip regions"
  222. }));
  223. }
  224. }
  225. else
  226. {
  227. this.mDynamicMat = new Material(this.shader);
  228. this.mDynamicMat.name = "[NGUI] " + this.shader.name;
  229. this.mDynamicMat.hideFlags = (HideFlags.DontSaveInEditor | HideFlags.NotEditable | HideFlags.DontSaveInBuild | HideFlags.DontUnloadUnusedAsset);
  230. }
  231. }
  232. private Material RebuildMaterial()
  233. {
  234. NGUITools.DestroyImmediate(this.mDynamicMat);
  235. this.CreateMaterial();
  236. this.mDynamicMat.renderQueue = this.mRenderQueue;
  237. if (this.mTexture != null)
  238. {
  239. this.mDynamicMat.mainTexture = this.mTexture;
  240. }
  241. if (this.mRenderer != null)
  242. {
  243. this.mRenderer.sharedMaterials = new Material[]
  244. {
  245. this.mDynamicMat
  246. };
  247. }
  248. return this.mDynamicMat;
  249. }
  250. private void UpdateMaterials()
  251. {
  252. if (this.mRebuildMat || this.mDynamicMat == null || this.mClipCount != this.panel.clipCount || this.mTextureClip != (this.panel.clipping == UIDrawCall.Clipping.TextureMask))
  253. {
  254. this.RebuildMaterial();
  255. this.mRebuildMat = false;
  256. }
  257. else if (this.mRenderer.sharedMaterial != this.mDynamicMat)
  258. {
  259. this.mRenderer.sharedMaterials = new Material[]
  260. {
  261. this.mDynamicMat
  262. };
  263. }
  264. }
  265. public void UpdateGeometry(int widgetCount)
  266. {
  267. this.widgetCount = widgetCount;
  268. int size = this.verts.size;
  269. if (size > 0 && size == this.uvs.size && size == this.cols.size && size % 4 == 0)
  270. {
  271. if (this.mFilter == null)
  272. {
  273. this.mFilter = base.gameObject.GetComponent<MeshFilter>();
  274. }
  275. if (this.mFilter == null)
  276. {
  277. this.mFilter = base.gameObject.AddComponent<MeshFilter>();
  278. }
  279. if (this.verts.size < 65000)
  280. {
  281. int num = (size >> 1) * 3;
  282. bool flag = this.mIndices == null || this.mIndices.Length != num;
  283. if (this.mMesh == null)
  284. {
  285. this.mMesh = new Mesh();
  286. this.mMesh.hideFlags = HideFlags.DontSave;
  287. this.mMesh.name = ((!(this.mMaterial != null)) ? "[NGUI] Mesh" : ("[NGUI] " + this.mMaterial.name));
  288. this.mMesh.MarkDynamic();
  289. flag = true;
  290. }
  291. bool flag2 = this.uvs.buffer.Length != this.verts.buffer.Length || this.cols.buffer.Length != this.verts.buffer.Length || (this.norms.buffer != null && this.norms.buffer.Length != this.verts.buffer.Length) || (this.tans.buffer != null && this.tans.buffer.Length != this.verts.buffer.Length);
  292. if (!flag2 && this.panel.renderQueue != UIPanel.RenderQueue.Automatic)
  293. {
  294. flag2 = (this.mMesh == null || this.mMesh.vertexCount != this.verts.buffer.Length);
  295. }
  296. if (!flag2 && this.verts.size << 1 < this.verts.buffer.Length)
  297. {
  298. flag2 = true;
  299. }
  300. this.mTriangles = this.verts.size >> 1;
  301. if (flag2 || this.verts.buffer.Length > 65000)
  302. {
  303. if (flag2 || this.mMesh.vertexCount != this.verts.size)
  304. {
  305. this.mMesh.Clear();
  306. flag = true;
  307. }
  308. this.mMesh.vertices = this.verts.ToArray();
  309. this.mMesh.uv = this.uvs.ToArray();
  310. this.mMesh.colors32 = this.cols.ToArray();
  311. if (this.norms != null)
  312. {
  313. this.mMesh.normals = this.norms.ToArray();
  314. }
  315. if (this.tans != null)
  316. {
  317. this.mMesh.tangents = this.tans.ToArray();
  318. }
  319. }
  320. else
  321. {
  322. if (this.mMesh.vertexCount != this.verts.buffer.Length)
  323. {
  324. this.mMesh.Clear();
  325. flag = true;
  326. }
  327. this.mMesh.vertices = this.verts.buffer;
  328. this.mMesh.uv = this.uvs.buffer;
  329. this.mMesh.colors32 = this.cols.buffer;
  330. if (this.norms != null)
  331. {
  332. this.mMesh.normals = this.norms.buffer;
  333. }
  334. if (this.tans != null)
  335. {
  336. this.mMesh.tangents = this.tans.buffer;
  337. }
  338. }
  339. if (flag)
  340. {
  341. this.mIndices = this.GenerateCachedIndexBuffer(size, num);
  342. this.mMesh.triangles = this.mIndices;
  343. }
  344. if (flag2 || !this.alwaysOnScreen)
  345. {
  346. this.mMesh.RecalculateBounds();
  347. }
  348. this.mFilter.mesh = this.mMesh;
  349. }
  350. else
  351. {
  352. this.mTriangles = 0;
  353. if (this.mFilter.mesh != null)
  354. {
  355. this.mFilter.mesh.Clear();
  356. }
  357. Debug.LogError("Too many vertices on one panel: " + this.verts.size);
  358. }
  359. if (this.mRenderer == null)
  360. {
  361. this.mRenderer = base.gameObject.GetComponent<MeshRenderer>();
  362. }
  363. if (this.mRenderer == null)
  364. {
  365. this.mRenderer = base.gameObject.AddComponent<MeshRenderer>();
  366. }
  367. this.UpdateMaterials();
  368. }
  369. else
  370. {
  371. if (this.mFilter.mesh != null)
  372. {
  373. this.mFilter.mesh.Clear();
  374. }
  375. Debug.LogError("UIWidgets must fill the buffer with 4 vertices per quad. Found " + size);
  376. }
  377. this.verts.Clear();
  378. this.uvs.Clear();
  379. this.cols.Clear();
  380. this.norms.Clear();
  381. this.tans.Clear();
  382. }
  383. private int[] GenerateCachedIndexBuffer(int vertexCount, int indexCount)
  384. {
  385. int i = 0;
  386. int count = UIDrawCall.mCache.Count;
  387. while (i < count)
  388. {
  389. int[] array = UIDrawCall.mCache[i];
  390. if (array != null && array.Length == indexCount)
  391. {
  392. return array;
  393. }
  394. i++;
  395. }
  396. int[] array2 = new int[indexCount];
  397. int num = 0;
  398. for (int j = 0; j < vertexCount; j += 4)
  399. {
  400. array2[num++] = j;
  401. array2[num++] = j + 1;
  402. array2[num++] = j + 2;
  403. array2[num++] = j + 2;
  404. array2[num++] = j + 3;
  405. array2[num++] = j;
  406. }
  407. if (UIDrawCall.mCache.Count > 10)
  408. {
  409. UIDrawCall.mCache.RemoveAt(0);
  410. }
  411. UIDrawCall.mCache.Add(array2);
  412. return array2;
  413. }
  414. private void OnWillRenderObject()
  415. {
  416. this.UpdateMaterials();
  417. if (this.onRender != null)
  418. {
  419. this.onRender(this.mDynamicMat ?? this.mMaterial);
  420. }
  421. if (this.mDynamicMat == null || this.mClipCount == 0)
  422. {
  423. return;
  424. }
  425. if (this.mTextureClip)
  426. {
  427. Vector4 drawCallClipRange = this.panel.drawCallClipRange;
  428. Vector2 clipSoftness = this.panel.clipSoftness;
  429. Vector2 vector = new Vector2(1000f, 1000f);
  430. if (clipSoftness.x > 0f)
  431. {
  432. vector.x = drawCallClipRange.z / clipSoftness.x;
  433. }
  434. if (clipSoftness.y > 0f)
  435. {
  436. vector.y = drawCallClipRange.w / clipSoftness.y;
  437. }
  438. this.mDynamicMat.SetVector(UIDrawCall.ClipRange[0], new Vector4(-drawCallClipRange.x / drawCallClipRange.z, -drawCallClipRange.y / drawCallClipRange.w, 1f / drawCallClipRange.z, 1f / drawCallClipRange.w));
  439. this.mDynamicMat.SetTexture("_ClipTex", this.clipTexture);
  440. }
  441. else if (!this.mLegacyShader)
  442. {
  443. UIPanel parentPanel = this.panel;
  444. int num = 0;
  445. while (parentPanel != null)
  446. {
  447. if (parentPanel.hasClipping)
  448. {
  449. float angle = 0f;
  450. Vector4 drawCallClipRange2 = parentPanel.drawCallClipRange;
  451. if (parentPanel != this.panel)
  452. {
  453. Vector3 vector2 = parentPanel.cachedTransform.InverseTransformPoint(this.panel.cachedTransform.position);
  454. drawCallClipRange2.x -= vector2.x;
  455. drawCallClipRange2.y -= vector2.y;
  456. Vector3 eulerAngles = this.panel.cachedTransform.rotation.eulerAngles;
  457. Vector3 eulerAngles2 = parentPanel.cachedTransform.rotation.eulerAngles;
  458. Vector3 vector3 = eulerAngles2 - eulerAngles;
  459. vector3.x = NGUIMath.WrapAngle(vector3.x);
  460. vector3.y = NGUIMath.WrapAngle(vector3.y);
  461. vector3.z = NGUIMath.WrapAngle(vector3.z);
  462. if (Mathf.Abs(vector3.x) > 0.001f || Mathf.Abs(vector3.y) > 0.001f)
  463. {
  464. Debug.LogWarning("Panel can only be clipped properly if X and Y rotation is left at 0", this.panel);
  465. }
  466. angle = vector3.z;
  467. }
  468. this.SetClipping(num++, drawCallClipRange2, parentPanel.clipSoftness, angle);
  469. }
  470. parentPanel = parentPanel.parentPanel;
  471. }
  472. }
  473. else
  474. {
  475. Vector2 clipSoftness2 = this.panel.clipSoftness;
  476. Vector4 drawCallClipRange3 = this.panel.drawCallClipRange;
  477. Vector2 mainTextureOffset = new Vector2(-drawCallClipRange3.x / drawCallClipRange3.z, -drawCallClipRange3.y / drawCallClipRange3.w);
  478. Vector2 mainTextureScale = new Vector2(1f / drawCallClipRange3.z, 1f / drawCallClipRange3.w);
  479. Vector2 v = new Vector2(1000f, 1000f);
  480. if (clipSoftness2.x > 0f)
  481. {
  482. v.x = drawCallClipRange3.z / clipSoftness2.x;
  483. }
  484. if (clipSoftness2.y > 0f)
  485. {
  486. v.y = drawCallClipRange3.w / clipSoftness2.y;
  487. }
  488. this.mDynamicMat.mainTextureOffset = mainTextureOffset;
  489. this.mDynamicMat.mainTextureScale = mainTextureScale;
  490. this.mDynamicMat.SetVector("_ClipSharpness", v);
  491. }
  492. }
  493. private void SetClipping(int index, Vector4 cr, Vector2 soft, float angle)
  494. {
  495. angle *= -0.017453292f;
  496. Vector2 vector = new Vector2(1000f, 1000f);
  497. if (soft.x > 0f)
  498. {
  499. vector.x = cr.z / soft.x;
  500. }
  501. if (soft.y > 0f)
  502. {
  503. vector.y = cr.w / soft.y;
  504. }
  505. if (index < UIDrawCall.ClipRange.Length)
  506. {
  507. this.mDynamicMat.SetVector(UIDrawCall.ClipRange[index], new Vector4(-cr.x / cr.z, -cr.y / cr.w, 1f / cr.z, 1f / cr.w));
  508. this.mDynamicMat.SetVector(UIDrawCall.ClipArgs[index], new Vector4(vector.x, vector.y, Mathf.Sin(angle), Mathf.Cos(angle)));
  509. }
  510. }
  511. private void Awake()
  512. {
  513. if (UIDrawCall.ClipRange == null)
  514. {
  515. UIDrawCall.ClipRange = new int[]
  516. {
  517. Shader.PropertyToID("_ClipRange0"),
  518. Shader.PropertyToID("_ClipRange1"),
  519. Shader.PropertyToID("_ClipRange2"),
  520. Shader.PropertyToID("_ClipRange4")
  521. };
  522. }
  523. if (UIDrawCall.ClipArgs == null)
  524. {
  525. UIDrawCall.ClipArgs = new int[]
  526. {
  527. Shader.PropertyToID("_ClipArgs0"),
  528. Shader.PropertyToID("_ClipArgs1"),
  529. Shader.PropertyToID("_ClipArgs2"),
  530. Shader.PropertyToID("_ClipArgs3")
  531. };
  532. }
  533. }
  534. private void OnEnable()
  535. {
  536. this.mRebuildMat = true;
  537. }
  538. private void OnDisable()
  539. {
  540. this.depthStart = int.MaxValue;
  541. this.depthEnd = int.MinValue;
  542. this.panel = null;
  543. this.manager = null;
  544. this.mMaterial = null;
  545. this.mTexture = null;
  546. this.clipTexture = null;
  547. if (this.mRenderer != null)
  548. {
  549. this.mRenderer.sharedMaterials = new Material[0];
  550. }
  551. NGUITools.DestroyImmediate(this.mDynamicMat);
  552. this.mDynamicMat = null;
  553. }
  554. private void OnDestroy()
  555. {
  556. NGUITools.DestroyImmediate(this.mMesh);
  557. this.mMesh = null;
  558. }
  559. public static UIDrawCall Create(UIPanel panel, Material mat, Texture tex, Shader shader)
  560. {
  561. return UIDrawCall.Create(null, panel, mat, tex, shader);
  562. }
  563. private static UIDrawCall Create(string name, UIPanel pan, Material mat, Texture tex, Shader shader)
  564. {
  565. UIDrawCall uidrawCall = UIDrawCall.Create(name);
  566. uidrawCall.gameObject.layer = pan.cachedGameObject.layer;
  567. uidrawCall.baseMaterial = mat;
  568. uidrawCall.mainTexture = tex;
  569. uidrawCall.shader = shader;
  570. uidrawCall.renderQueue = pan.startingRenderQueue;
  571. uidrawCall.sortingOrder = pan.sortingOrder;
  572. uidrawCall.manager = pan;
  573. return uidrawCall;
  574. }
  575. private static UIDrawCall Create(string name)
  576. {
  577. if (UIDrawCall.mInactiveList.size > 0)
  578. {
  579. UIDrawCall uidrawCall = UIDrawCall.mInactiveList.Pop();
  580. if (uidrawCall == null || uidrawCall.gameObject == null)
  581. {
  582. GameObject gameObject = new GameObject(name);
  583. UnityEngine.Object.DontDestroyOnLoad(gameObject);
  584. UIDrawCall uidrawCall2 = gameObject.AddComponent<UIDrawCall>();
  585. uidrawCall = uidrawCall2;
  586. }
  587. UIDrawCall.mActiveList.Add(uidrawCall);
  588. if (name != null)
  589. {
  590. uidrawCall.name = name;
  591. }
  592. NGUITools.SetActive(uidrawCall.gameObject, true);
  593. return uidrawCall;
  594. }
  595. GameObject gameObject2 = new GameObject(name);
  596. UnityEngine.Object.DontDestroyOnLoad(gameObject2);
  597. UIDrawCall uidrawCall3 = gameObject2.AddComponent<UIDrawCall>();
  598. UIDrawCall.mActiveList.Add(uidrawCall3);
  599. return uidrawCall3;
  600. }
  601. public static void ClearAll()
  602. {
  603. bool isPlaying = Application.isPlaying;
  604. int i = UIDrawCall.mActiveList.size;
  605. while (i > 0)
  606. {
  607. UIDrawCall uidrawCall = UIDrawCall.mActiveList[--i];
  608. if (uidrawCall)
  609. {
  610. if (isPlaying)
  611. {
  612. NGUITools.SetActive(uidrawCall.gameObject, false);
  613. }
  614. else
  615. {
  616. NGUITools.DestroyImmediate(uidrawCall.gameObject);
  617. }
  618. }
  619. }
  620. UIDrawCall.mActiveList.Clear();
  621. }
  622. public static void ReleaseAll()
  623. {
  624. UIDrawCall.ClearAll();
  625. UIDrawCall.ReleaseInactive();
  626. }
  627. public static void ReleaseInactive()
  628. {
  629. int i = UIDrawCall.mInactiveList.size;
  630. while (i > 0)
  631. {
  632. UIDrawCall uidrawCall = UIDrawCall.mInactiveList[--i];
  633. if (uidrawCall)
  634. {
  635. NGUITools.DestroyImmediate(uidrawCall.gameObject);
  636. }
  637. }
  638. UIDrawCall.mInactiveList.Clear();
  639. }
  640. public static int Count(UIPanel panel)
  641. {
  642. int num = 0;
  643. for (int i = 0; i < UIDrawCall.mActiveList.size; i++)
  644. {
  645. if (UIDrawCall.mActiveList[i] != null && UIDrawCall.mActiveList[i].manager == panel)
  646. {
  647. num++;
  648. }
  649. }
  650. return num;
  651. }
  652. public static void Destroy(UIDrawCall dc)
  653. {
  654. if (dc)
  655. {
  656. dc.onRender = null;
  657. if (Application.isPlaying)
  658. {
  659. if (UIDrawCall.mActiveList.Remove(dc))
  660. {
  661. NGUITools.SetActive(dc.gameObject, false);
  662. UIDrawCall.mInactiveList.Add(dc);
  663. }
  664. }
  665. else
  666. {
  667. UIDrawCall.mActiveList.Remove(dc);
  668. NGUITools.DestroyImmediate(dc.gameObject);
  669. }
  670. }
  671. }
  672. private static BetterList<UIDrawCall> mActiveList = new BetterList<UIDrawCall>();
  673. private static BetterList<UIDrawCall> mInactiveList = new BetterList<UIDrawCall>();
  674. [HideInInspector]
  675. [NonSerialized]
  676. public int widgetCount;
  677. [HideInInspector]
  678. [NonSerialized]
  679. public int depthStart = int.MaxValue;
  680. [HideInInspector]
  681. [NonSerialized]
  682. public int depthEnd = int.MinValue;
  683. [HideInInspector]
  684. [NonSerialized]
  685. public UIPanel manager;
  686. [HideInInspector]
  687. [NonSerialized]
  688. public UIPanel panel;
  689. [HideInInspector]
  690. [NonSerialized]
  691. public Texture2D clipTexture;
  692. [HideInInspector]
  693. [NonSerialized]
  694. public bool alwaysOnScreen;
  695. [HideInInspector]
  696. [NonSerialized]
  697. public BetterList<Vector3> verts = new BetterList<Vector3>();
  698. [HideInInspector]
  699. [NonSerialized]
  700. public BetterList<Vector3> norms = new BetterList<Vector3>();
  701. [HideInInspector]
  702. [NonSerialized]
  703. public BetterList<Vector4> tans = new BetterList<Vector4>();
  704. [HideInInspector]
  705. [NonSerialized]
  706. public BetterList<Vector2> uvs = new BetterList<Vector2>();
  707. [HideInInspector]
  708. [NonSerialized]
  709. public BetterList<Color32> cols = new BetterList<Color32>();
  710. private Material mMaterial;
  711. private Texture mTexture;
  712. private Shader mShader;
  713. private int mClipCount;
  714. private Transform mTrans;
  715. private Mesh mMesh;
  716. private MeshFilter mFilter;
  717. private MeshRenderer mRenderer;
  718. private Material mDynamicMat;
  719. private int[] mIndices;
  720. private bool mRebuildMat = true;
  721. private bool mLegacyShader;
  722. private int mRenderQueue = 3000;
  723. private int mTriangles;
  724. [NonSerialized]
  725. public bool isDirty;
  726. [NonSerialized]
  727. private bool mTextureClip;
  728. public UIDrawCall.OnRenderCallback onRender;
  729. private const int maxIndexBufferCache = 10;
  730. private static List<int[]> mCache = new List<int[]>(10);
  731. private static int[] ClipRange = null;
  732. private static int[] ClipArgs = null;
  733. public enum Clipping
  734. {
  735. None,
  736. TextureMask,
  737. SoftClip = 3,
  738. ConstrainButDontClip
  739. }
  740. public delegate void OnRenderCallback(Material mat);
  741. }