- 最后登录
- 2019-12-25
- 注册时间
- 2012-8-24
- 阅读权限
- 90
- 积分
- 71088
- 纳金币
- 52336
- 精华
- 343
|
利用系统现有组件,简单处理了下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组件,编辑节点,覆盖热点区域
|
|