using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; /// /// 响应不规则区域点击事件 /// [RequireComponent(typeof(PolygonCollider2D))] public class PolygonImage : Image { PolygonCollider2D polygonCollider2D; protected override void Awake() { base.Awake(); polygonCollider2D = this.GetComponent(); } public override bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera) { if (eventCamera != null) screenPoint = eventCamera.ScreenToWorldPoint(screenPoint); return polygonCollider2D.OverlapPoint(screenPoint); } }