EventSystem大家平时主要是用来处理UGUI的输入,但其实也可以使用在一般的3D对象上,Unity API对这个介绍的很少。
在网上找到了一篇介绍不错的文章。
https://www.cnblogs.com/weiqiangwaideshijie/p/6859867.html
以下是我的一些分享:
除了需要依赖UI相同的EventSystem之后,还需要使用Physics RayCaster组件绑定Camera上
Test脚本如下,只不过Drag事件还未处理,物体还不能拖动
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class TestSystemInputMono : MonoBehaviour, IPointerDownHandler, IBeginDragHandler, IDragHandler, IEndDragHandler {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnPointerDown (PointerEventData eventData)
{
Debug.Log ("OnPointerDown");
}
public void OnBeginDrag(PointerEventData data)
{
Debug.Log ("OnBeginDrag");
}
public void OnDrag(PointerEventData data)
{
Debug.Log ("OnDrag");
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log ("OnEndDrag");
}
}
有关PointerEventData的参数,其中了些属性,很重要的