1在项目中添加NGUI和EasyTouch插件
2 创建一个空物体,挂在easyTouch脚本,设置脚本参数,将摄像机设置为NGUI的相机,勾选AutoSelect选项,设置拖拽对象所在的层,也就是Pickable Layers
3 在拖拽对象上面挂载脚本,脚本中注册Easy Touch的拖拽事件
通过Easy touch拖拽物体移动,拖拽对象可以是2D的,也可以是3D的。
DragTest .cs
using UnityEngine;
using System.Collections;
public class DragTest : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log("Start");
}
public void OnEnable()
{
EasyTouch.On_DragStart += OndragStart1;
EasyTouch.On_Drag += OnDrag1;
EasyTouch.On_DragEnd += OnDragEnd1;
EasyTouch.On_SimpleTap += EasyTouch_On_SimpleTap;
}
public void OnDisable()
{
EasyTouch.On_DragStart -= OndragStart1;
EasyTouch.On_Drag -= OnDrag1;
EasyTouch.On_DragEnd -= OnDragEnd1;
EasyTouch.On_SimpleTap -= EasyTouch_On_SimpleTap;
}
private void EasyTouch_On_SimpleTap(Gesture gesture)
{
Debug.Log("EasyTouch_On_SimpleTap");
}
private void OnDrag1(Gesture gesture)
{
Debug.Log("OnDrag");
if (gesture.pickObject == this.gameObject) {//跟随鼠标移动
Vector3 position = gesture.GetTouchToWordlPoint(0);
transform.position = position ;
Debug.Log("OnDrag;" + gesture.pickObject.name);
}
}
private void OnDragEnd1(Gesture gesture)
{
Debug.Log("OnDragEnd1");
if (gesture.pickObject)
Debug.Log("OnDragEnd1;" + gesture.pickObject.name);
}
private void OndragStart1(Gesture gesture)
{
Debug.Log("OndragStart1");
if (gesture.pickObject)
Debug.Log("OndragStart1;" + gesture.pickObject.name);
}
// Update is called once per frame
void Update () {
}
}