MyGuideMask.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Fort23.UTool;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace Fort23.Mono
  5. {
  6. public class MyGuideMask : MonoBehaviour, ICanvasRaycastFilter
  7. {
  8. public Image _Mask; //??????
  9. private Material _materia;
  10. public GameObject target;
  11. private void Awake()
  12. {
  13. // _materia = _Mask.material;
  14. // RectTransform rectTransform = target.GetComponent<RectTransform>();
  15. // CreateCircleRectangleMask(rectTransform.anchoredPosition, rectTransform.sizeDelta, 2);
  16. }
  17. /// <summary>
  18. /// ??????????????
  19. /// </summary>
  20. /// <param name="pos">???ε????λ??</param>
  21. /// <param name="pos1">?????λ??</param>
  22. /// <param name="pos2">?????λ??</param>
  23. public void CreateCircleRectangleMask(Vector2 pos, Vector2 widthAndHeight, float raid)
  24. {
  25. _materia.SetFloat("_MaskType", 2f);
  26. _materia.SetVector("_Origin", new Vector4(pos.x, pos.y, widthAndHeight.x, widthAndHeight.y));
  27. _materia.SetFloat("_Raid", raid);
  28. }
  29. /// <summary>
  30. /// ???????ε??????
  31. /// </summary>
  32. /// <param name="pos">?????????????</param>
  33. /// <param name="widthAndHeight">???ο??</param>
  34. public void CreateRectangleMask(Vector2 pos, Vector2 widthAndHeight, float raid)
  35. {
  36. _materia.SetFloat("_MaskType", 1f);
  37. _materia.SetVector("_Origin", new Vector4(pos.x, pos.y, widthAndHeight.x, widthAndHeight.y));
  38. }
  39. /// <summary>
  40. /// ???????ε??????
  41. /// </summary>
  42. /// <param name="pos">??????????????</param>
  43. /// <param name="rad">??????</param>
  44. /// <param name="pos1">С????????????</param>
  45. /// <param name="rad1">С????</param>
  46. public void CreateCircleMask(Vector3 pos, float rad, Vector3 pos1, float rad1)
  47. {
  48. _materia.SetFloat("_MaskType", 0f);
  49. _materia.SetVector("_Origin", new Vector4(pos.x, pos.y, rad, 0));
  50. _materia.SetVector("_TopOri", new Vector4(pos1.x, pos1.y, rad1, 0));
  51. }
  52. /// <summary>
  53. /// ?????????Mask???
  54. /// </summary>
  55. /// <param name="tg">???</param>
  56. public void SetTargetImage(GameObject tg)
  57. {
  58. target = tg;
  59. }
  60. public bool IsRaycastLocationValid(Vector2 sp, Camera eventCamera)
  61. {
  62. //???????????????
  63. if (target == null)
  64. {
  65. return true;
  66. }
  67. //?????Χ??????????
  68. return !RectTransformUtility.RectangleContainsScreenPoint(target.GetComponent<RectTransform>(),
  69. sp, eventCamera);
  70. }
  71. public void CustomPoint()
  72. {
  73. LogTool.Log("??????????");
  74. }
  75. }
  76. }