Around.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace WXB
  5. {
  6. public class Around
  7. {
  8. List<Rect> m_Rects = new List<Rect>(); // 环绕的区别
  9. public void Add(Rect rect)
  10. {
  11. m_Rects.Add(rect);
  12. }
  13. public void Clear()
  14. {
  15. m_Rects.Clear();
  16. }
  17. public bool isContain(Rect rect, out float ox)
  18. {
  19. if (m_Rects.Count == 0)
  20. {
  21. ox = 0f;
  22. return true;
  23. }
  24. return isContain(rect.x, rect.y, rect.width, rect.height, out ox);
  25. }
  26. public bool isContain(float x, float y, float w, float h, out float ox)
  27. {
  28. if (m_Rects.Count == 0)
  29. {
  30. ox = 0f;
  31. return true;
  32. }
  33. Rect r = new Rect(x, y, w, h);
  34. for (int i = 0; i < m_Rects.Count; ++i)
  35. {
  36. if (m_Rects[i].Overlaps(r))
  37. {
  38. ox = (m_Rects[i].xMax + 5f);
  39. return false;
  40. }
  41. }
  42. ox = 0f;
  43. return true;
  44. }
  45. }
  46. }