- 最后登录
- 2021-7-6
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 76145
- 纳金币
- 53488
- 精华
- 316
|
利用系统现有组件,简单处理了下:
1. 自定义了一个CustomRaycaster类,派生自GraphicRaycaster- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System.Collections.Generic;
- using UnityEngine.EventSystems;
- public class CustomRaycaster : GraphicRaycaster
- {
- private List<RaycastResult> _toBeRemoved = new List<RaycastResult>();
- public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList)
- {
- base.Raycast(eventData, resultAppendList);
- _toBeRemoved.Clear();
- foreach (var result in resultAppendList)
- {
- var polygon2D = result.gameObject.GetComponent<PolygonCollider2D>();
- if (!polygon2D)
- continue;
-
- if (!polygon2D.OverlapPoint(eventData.position))
- _toBeRemoved.Add(result);
- }
- if (_toBeRemoved.Count > 0)
- resultAppendList.RemoveAll(r => _toBeRemoved.Contains(r));
- }
- }
复制代码 2. 删除Canvas上原有的GraphicRaycaster,用这个替换
3. 在不规则UI对象上添加一个PolygonCollider2D组件,编辑节点,覆盖热点区域
|
|