CommonUtil.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using FairyGUI;
  2. using UnityEngine;
  3. namespace GFGGame
  4. {
  5. public class CommonUtil : SingletonBase<CommonUtil>
  6. {
  7. /// <summary>
  8. /// 检查一个点是否在某物体范围内
  9. /// </summary>
  10. /// <param name="obj"></param>
  11. /// <param name="point"></param>
  12. /// <returns></returns>
  13. public bool CheckPointIsOnComponent(GObject obj, Vector2 point)
  14. {
  15. if (!obj.visible) return false;
  16. Vector2 p = obj.LocalToGlobal(new Vector2(0, 0));
  17. Debug.Log("p:" + p);
  18. Debug.Log("point:" + point);
  19. float w = obj.width;
  20. float h = obj.height;
  21. float x0 = p.x;
  22. float y0 = p.y;
  23. float x1 = x0 + w;
  24. float y1 = y0 + h;
  25. if (point.x >= x0 && point.x < x1 && point.y >= y0 && point.y < y1)
  26. {
  27. return true;
  28. }
  29. return false;
  30. }
  31. private Vector2 _moustPoint = new Vector2();
  32. public Vector2 GetMouseV2Point()
  33. {
  34. ; Vector2 moustPoint = new Vector2(Input.mousePosition.x, UnityEngine.Screen.height - Input.mousePosition.y);// this.
  35. _moustPoint.x = Input.mousePosition.x;
  36. _moustPoint.y = UnityEngine.Screen.height - Input.mousePosition.y;
  37. return _moustPoint;
  38. }
  39. }
  40. }