PS:本系列笔记将会记录我此次在北京学习Unity开发的总体过程,方便后期写总结,笔记为日更。
笔记内容均为 自己理解,不保证每个都对
实现 简易模拟摇杆控制物体旋转,移动,小地图光标的同步移动与旋转
Part 1 UI部分接口:
使用UI接口时,要引用 EventSystems的库文件
using UnityEngine.EventSystems;
该博客举例部分接口为:
IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler, IPointerUpHandler,
IDragHandler,IBeginDragHandler
使用方法:
public class UIInterfaceTest : MonoBehaviour,
IPointerClickHandler, IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler, IPointerUpHandler,
IDragHandler,IBeginDragHandler
{
public void OnBeginDrag(PointerEventData eventData) //鼠标按下开始拖动
{
Debug.Log("OnBeginDrag !!!");
}
public void OnDrag(PointerEventData eventData) //正在拖动
{
transform.position = eventData.position; //拖动图片
Debug.Log("OnDrag !!!");
}
public void OnEndDrag(PointerEventData eventData) //结束拖动
{
Debug.Log("OnEndDrag !!!");
}
public void OnPointerClick(PointerEventData eventData) //鼠标按下松开
{
Debug.Log("OnPointerClick !!!");
}
public void OnPointerDown(PointerEventData eventData) //鼠标按下不松开
{
Debug.Log("OnPointerDown !!!");
}
public void OnPointerEnter(PointerEventData eventData) //鼠标进入
{
Debug.Log("OnPointerEnter !!!");
}
public void OnPointerExit(PointerEventData eventData) //鼠标离开
{
Debug.Log("OnPointerExit !!!");
}
public void OnPointerUp(PointerEventData eventData) //鼠标松开
{
Debug.Log("OnPointerUp !!!");
}
显示输出结果为:
可完成鼠标拖动物体DEMO: 脚本挂在物体上
public void OnDrag(PointerEventData eventData) //正在拖动
{
transform.position = eventData.position; //拖动图片