unity ui穿透点击

unity ui穿透点击

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

//Encoding:UTF-8
public class UIPointerEventPenetrate : MonoBehaviour, IPointerClickHandler
{
    List<RaycastResult> results = new List<RaycastResult>();
    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("=dianji=");
        Psss(eventData, ExecuteEvents.pointerClickHandler);
    }

    public void Psss<T>(PointerEventData data, ExecuteEvents.EventFunction<T> function) where T : IEventSystemHandler
    {
        results.Clear();
        EventSystem.current.RaycastAll(data, results);
        GameObject current = data.pointerCurrentRaycast.gameObject;
        for (int i = 0; i < results.Count; i++)
        {
            Debug.Log("=dianji=" + results[i].gameObject);
            if (current != results[i].gameObject)
            {
                if (ExecuteEvents.Execute(results[i].gameObject, data, function))
                {
                    break;
                }
            }
        }
    }
}

 

posted @ 2025-01-20 10:08  三页菌  阅读(50)  评论(0)    收藏  举报