zoukankan      html  css  js  c++  java
  • 穿透UI (转载雨松老师)

     1 using System.Collections;
     2 using System.Collections.Generic;
     3 using UnityEngine;
     4 using UnityEngine.EventSystems;
     5 
     6 
     7 public class UIRaycastPass : MonoBehaviour,IPointerClickHandler ,IPointerDownHandler,IPointerUpHandler 
     8 {
     9     //监听按下
    10     public void OnPointerDown(PointerEventData eventData)
    11     {
    12         PassEvent(eventData, ExecuteEvents.pointerDownHandler);
    13     }
    14 
    15     //监听抬起
    16     public void OnPointerUp(PointerEventData eventData)
    17     {
    18         PassEvent(eventData, ExecuteEvents.pointerUpHandler);
    19     }
    20 
    21     //监听点击
    22     public void OnPointerClick(PointerEventData eventData)
    23     {
    24         PassEvent(eventData, ExecuteEvents.submitHandler);
    25         PassEvent(eventData, ExecuteEvents.pointerClickHandler);
    26     }
    27 
    28 
    29     //把事件透下去
    30     public void PassEvent<T>(PointerEventData data, ExecuteEvents.EventFunction<T> function)
    31         where T : IEventSystemHandler
    32     {
    33         List<RaycastResult> results = new List<RaycastResult>();
    34         EventSystem.current.RaycastAll(data, results);
    35         GameObject current = data.pointerCurrentRaycast.gameObject;
    36         for (int i = 0; i < results.Count; i++)
    37         {
    38             if (current != results[i].gameObject)
    39             {
    40                 ExecuteEvents.Execute(results[i].gameObject, data, function);
    41                 //RaycastAll后ugui会自己排序,如果你只想响应透下去的第一个响应,这里ExecuteEvents.Execute后直接break就行。
    42                 //break;
    43             }
    44         }
    45     }
    46 
    47 }

    之后我用这个工具开发了一套引导流程,之后有机会写出来,有一些思路和实现

  • 相关阅读:
    iOS 页面间几种传值方式(属性,代理,block,单例,通知)
    iOS CocoaPods安装与使用
    iOS UIWebView截获html并修改便签内容
    block的底层实现原理?
    多线程的底层实现是什么?
    tabviewcell的删除注意
    iOS9 新特性总结!!!
    类方法加Static -------不需要初始化变量
    Warning:whose view is not in the window herarchy!
    iOS----录音:真机调试的注意
  • 原文地址:https://www.cnblogs.com/leilei-weapon/p/12110210.html
Copyright © 2011-2022 走看看