UGUI事件接口——IEventSystemHandler

作者:追风剑情 发布于:2017-4-9 22:08 分类:Unity3d

一、创建一个Cube

二、创建一个脚本EventTest.cs挂到Cube上

三、在摄像机上挂个Physics Raycaster组件


66666.png

3333333.png

2222222.png

using UnityEngine;
using UnityEngine.EventSystems;

public class EventTest : MonoBehaviour, 
    IPointerClickHandler, 
    IPointerEnterHandler, 
    IPointerExitHandler, 
    IPointerDownHandler, 
    IPointerUpHandler,
    IBeginDragHandler,
    IDragHandler,
    IInitializePotentialDragHandler,
    IEndDragHandler,
    IDropHandler,
    IUpdateSelectedHandler,
    ISelectHandler,
    IDeselectHandler,
    IScrollHandler,
    IMoveHandler,
    ISubmitHandler,
    ICancelHandler
{
    #region 鼠标指针类
    //鼠标进入时响应
    public void OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("OnPointerEnter");
    }

    //鼠标离开时响应
    public void OnPointerExit(PointerEventData eventData)
    {
        Debug.Log("OnPointerExit");
    }

    //鼠标按下时响应
    public void OnPointerDown(PointerEventData eventData)
    {
        Debug.Log("OnPointerDown");
    }

    //鼠标释放时响应
    public void OnPointerUp(PointerEventData eventData)
    {
        Debug.Log("OnPointerUp");
    }

    //鼠标点击时响应
    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("OnPointerClick");
    }
    #endregion


    #region 拖拽类
    //初始化拖拽
    public void OnInitializePotentialDrag(PointerEventData eventData)
    {
        Debug.Log("OnInitializePotentialDrag");
    }

    //开始拖拽
    public void OnBeginDrag(PointerEventData eventData)
    {
        Debug.Log("OnBeginDrag");
    }

    //拖拽中
    public void OnDrag(PointerEventData eventData)
    {
        Debug.Log("OnDrag");
    }

    //拖拽结束
    public void OnEndDrag(PointerEventData eventData)
    {
        Debug.Log("OnEndDrag");
    }

    //拖拽释放
    public void OnDrop(PointerEventData eventData)
    {
        Debug.Log("OnDrop");
    }
    #endregion


    #region 点选类
    //当物体被选中时每帧触发
    public void OnUpdateSelected(BaseEventData eventData)
    {
        Debug.Log("OnUpdateSelected");
    }

    //选中物体
    public void OnSelect(BaseEventData eventData)
    {
        Debug.Log("OnSelect");
    }

    //未选中物体
    public void OnDeselect(BaseEventData eventData)
    {
        Debug.Log("OnDeselect");
    }
    #endregion

    #region 输入类
    //鼠标中轮滚动
    public void OnScroll(PointerEventData eventData)
    {
        Debug.Log("OnScroll");
    }

    //移动物体
    public void OnMove(AxisEventData eventData)
    {
        Debug.Log("OnMove");
    }

    //提交
    public void OnSubmit(BaseEventData eventData)
    {
        Debug.Log("OnSubmit");
    }

    //取消
    public void OnCancel(BaseEventData eventData)
    {
        Debug.Log("OnCancel");
    }
    #endregion
}

运行测试

1111111.png


标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号