纳金网
标题:
UGUI不规则热区的处理
[打印本页]
作者:
烟雨
时间:
2015-11-30 23:45
标题:
UGUI不规则热区的处理
利用系统现有组件,简单处理了下:
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组件,编辑节点,覆盖热点区域
欢迎光临 纳金网 (http://old.narkii.com/club/)
Powered by Discuz! X2.5