unity3D UGUI学习(五) EventSystem,EventTrigger响应事件介绍

前言

UGUI中EventSystem主要负责处理输入、射线以及发送事件,一个场景中
只能有一个EventSystem并且需要 BaseInputModule类型组建的协助才
能工作。

EventSystem负责管理,BaseInputModule负责输 入,BaseRaycaster负责确定目标对象。

UGUI中不仅可以对UI进行监测,还可以对场景中的对象进 行监测,以下会
有详细介绍

需要引入的空间名

using UnityEngine.EventSystems;
using UnityEngine.Events;
一、StandaloneInputModule和TouchInoutModule两个组件会监测一些输入操作,以事件的方式通知目标对象,支持的事件有以下:
  1. IPointerEnterHandler - OnPointerEnter - Called when a pointer enters the object
  2. IPointerExitHandler - OnPointerExit - Called when a pointer exits the object
  3. IPointerDownHandler - OnPointerDown - Called when a pointer is pressed on the object
  4. IPointerUpHandler - OnPointerUp - Called when a pointer is released (called on the original the pressed object)
  5. IPointerClickHandler - OnPointerClick - Called when a pointer is pressed and released on the same object
  6. IInitializePotentialDragHandler - OnInitializePotentialDrag - Called when a drag target is found, can be used to initialise values

使用方式:
1. 引入命名空间 using UnityEngine.EventSystems;
2. 使用某个方法就继承某个接口
3. 根据方法的参数使用

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
/// <summary>
/// Button a.
/// UGUI处理其他类型事件的方式一:接口
/// </summary>
public class ButtonA : MonoBehaviour,IPointerEnterHand
  • 6
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值