EventSystem应用于3D GameObject,实现拖拽效果

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的参数,其中了些属性,很重要的

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值