PDFInternalUtils.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. http://www.cgsoso.com/forum-211-1.html
  3. CG搜搜 Unity3d 每日Unity3d插件免费更新 更有VIP资源!
  4. CGSOSO 主打游戏开发,影视设计等CG资源素材。
  5. 插件如若商用,请务必官网购买!
  6. daily assets update for try.
  7. U should buy the asset from home store if u use it in your project!
  8. */
  9. using UnityEngine;
  10. namespace Paroxe.PdfRenderer.Internal
  11. {
  12. public static class PDFInternalUtils
  13. {
  14. public static float CalculateRectTransformIntersectArea(RectTransform a, RectTransform b)
  15. {
  16. Vector3[] worldCorners = new Vector3[4];
  17. a.GetWorldCorners(worldCorners);
  18. Vector2 min = worldCorners[0];
  19. Vector2 max = worldCorners[0];
  20. for (int i = 1; i < 4; ++i)
  21. {
  22. if (worldCorners[i].x < min.x)
  23. min.x = worldCorners[i].x;
  24. if (worldCorners[i].y < min.y)
  25. min.y = worldCorners[i].y;
  26. if (worldCorners[i].x > max.x)
  27. max.x = worldCorners[i].x;
  28. if (worldCorners[i].y > max.y)
  29. max.y = worldCorners[i].y;
  30. }
  31. Rect ra = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
  32. b.GetWorldCorners(worldCorners);
  33. min = worldCorners[0];
  34. max = worldCorners[0];
  35. for (int i = 1; i < 4; ++i)
  36. {
  37. if (worldCorners[i].x < min.x)
  38. min.x = worldCorners[i].x;
  39. if (worldCorners[i].y < min.y)
  40. min.y = worldCorners[i].y;
  41. if (worldCorners[i].x > max.x)
  42. max.x = worldCorners[i].x;
  43. if (worldCorners[i].y > max.y)
  44. max.y = worldCorners[i].y;
  45. }
  46. Rect rb = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
  47. float x_overlap = Mathf.Min(ra.xMin + ra.width, rb.xMin + rb.width) - Mathf.Max(ra.xMin, rb.xMin) + 1;
  48. float y_overlap = Mathf.Min(ra.yMin + ra.height, rb.yMin + rb.height) - Mathf.Max(ra.yMin, rb.yMin) + 1;
  49. if (x_overlap <= 0.0f || y_overlap <= 0.0f)
  50. return 0.0f;
  51. return x_overlap*y_overlap;
  52. }
  53. public static float CalculateRectTransformVerticalDistance(RectTransform a, RectTransform b)
  54. {
  55. if (CalculateRectTransformIntersectArea(a, b) > 0.0f)
  56. return 0.0f;
  57. Vector3[] worldCorners = new Vector3[4];
  58. a.GetWorldCorners(worldCorners);
  59. Vector2 min = worldCorners[0];
  60. Vector2 max = worldCorners[0];
  61. for (int i = 1; i < 4; ++i)
  62. {
  63. if (worldCorners[i].x < min.x)
  64. min.x = worldCorners[i].x;
  65. if (worldCorners[i].y < min.y)
  66. min.y = worldCorners[i].y;
  67. if (worldCorners[i].x > max.x)
  68. max.x = worldCorners[i].x;
  69. if (worldCorners[i].y > max.y)
  70. max.y = worldCorners[i].y;
  71. }
  72. Rect ra = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
  73. b.GetWorldCorners(worldCorners);
  74. min = worldCorners[0];
  75. max = worldCorners[0];
  76. for (int i = 1; i < 4; ++i)
  77. {
  78. if (worldCorners[i].x < min.x)
  79. min.x = worldCorners[i].x;
  80. if (worldCorners[i].y < min.y)
  81. min.y = worldCorners[i].y;
  82. if (worldCorners[i].x > max.x)
  83. max.x = worldCorners[i].x;
  84. if (worldCorners[i].y > max.y)
  85. max.y = worldCorners[i].y;
  86. }
  87. Rect rb = new Rect(min.x, min.y, max.x - min.x, max.y - min.y);
  88. return Mathf.Min(rb.yMin - ra.yMax, rb.yMax - ra.yMin);
  89. }
  90. public static float CubicEaseIn(float currentTime, float startingValue, float finalValue, float duration)
  91. {
  92. return finalValue*(currentTime /= duration)*currentTime*currentTime + startingValue;
  93. }
  94. }
  95. }