unity3d:ugui滚动层滑动与item点击事件的冲突处理

2023-08-24 14:24:05 浏览数 (1)

代码语言:javascript复制
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class ClickListener : MonoBehaviour, IPointerClickHandler
{
    public delegate void VoidDelegate(GameObject go);
    public VoidDelegate onClick;
    public object parameter;
    public object parameter1;

    static public ClickListener Get(GameObject go)
    {
        ClickListener listener = go.GetComponent<ClickListener>();
        if (listener == null) listener = go.AddComponent<ClickListener>();
        return listener;
    }

    public void OnPointerClick(PointerEventData eventData)
    {
        if (onClick != null)
        {
            onClick(gameObject);
        }
    }

}

注意: 当父物体上有button组件时,子部件不会响应

0 人点赞