UIGeometry.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using UnityEngine;
  3. public class UIGeometry
  4. {
  5. public bool hasVertices
  6. {
  7. get
  8. {
  9. return this.verts.size > 0;
  10. }
  11. }
  12. public bool hasTransformed
  13. {
  14. get
  15. {
  16. return this.mRtpVerts != null && this.mRtpVerts.size > 0 && this.mRtpVerts.size == this.verts.size;
  17. }
  18. }
  19. public void Clear()
  20. {
  21. this.verts.Clear();
  22. this.uvs.Clear();
  23. this.cols.Clear();
  24. this.mRtpVerts.Clear();
  25. }
  26. public void ApplyTransform(Matrix4x4 widgetToPanel)
  27. {
  28. if (this.verts.size > 0)
  29. {
  30. this.mRtpVerts.Clear();
  31. int i = 0;
  32. int size = this.verts.size;
  33. while (i < size)
  34. {
  35. this.mRtpVerts.Add(widgetToPanel.MultiplyPoint3x4(this.verts[i]));
  36. i++;
  37. }
  38. this.mRtpNormal = widgetToPanel.MultiplyVector(Vector3.back).normalized;
  39. Vector3 normalized = widgetToPanel.MultiplyVector(Vector3.right).normalized;
  40. this.mRtpTan = new Vector4(normalized.x, normalized.y, normalized.z, -1f);
  41. }
  42. else
  43. {
  44. this.mRtpVerts.Clear();
  45. }
  46. }
  47. public void WriteToBuffers(BetterList<Vector3> v, BetterList<Vector2> u, BetterList<Color32> c, BetterList<Vector3> n, BetterList<Vector4> t)
  48. {
  49. if (this.mRtpVerts != null && this.mRtpVerts.size > 0)
  50. {
  51. if (n == null)
  52. {
  53. for (int i = 0; i < this.mRtpVerts.size; i++)
  54. {
  55. v.Add(this.mRtpVerts.buffer[i]);
  56. u.Add(this.uvs.buffer[i]);
  57. c.Add(this.cols.buffer[i]);
  58. }
  59. }
  60. else
  61. {
  62. for (int j = 0; j < this.mRtpVerts.size; j++)
  63. {
  64. v.Add(this.mRtpVerts.buffer[j]);
  65. u.Add(this.uvs.buffer[j]);
  66. c.Add(this.cols.buffer[j]);
  67. n.Add(this.mRtpNormal);
  68. t.Add(this.mRtpTan);
  69. }
  70. }
  71. }
  72. }
  73. public BetterList<Vector3> verts = new BetterList<Vector3>();
  74. public BetterList<Vector2> uvs = new BetterList<Vector2>();
  75. public BetterList<Color32> cols = new BetterList<Color32>();
  76. private BetterList<Vector3> mRtpVerts = new BetterList<Vector3>();
  77. private Vector3 mRtpNormal;
  78. private Vector4 mRtpTan;
  79. }