简介
- Input
- IPointerEnterHandler等接口
- 键盘,鼠标,操作杆
Input
- GetAxis:返回float,对应的name为InputSetting对应的
- GetButton:返回bool,对应的name为InputSetting对应的
- GetKey:返回bool
- KeyCode:对应键值
- string:对应InputSetting对应的每一个下面的NegativeButton等Button
if (Input.GetButton("Horizontal"))
{
Debug.LogError("GetButton");
}
float h = Input.GetAxis("Horizontal");
if (0!=h)
{
Debug.LogError("GetAxis");
}
if (Input.GetKey(KeyCode.A))
{
Debug.LogError("GetKey_keycode");
}
if (Input.GetKey("a"))
{
Debug.LogError("GetKey_name");
}
- mousePresent:检测鼠标设备,官方文档中解释在各个平台会有很大出入
- mouseScrollDelta:返回(0,0,1)或者(0,0,-1)
- mousePosition:返回鼠标在屏幕坐标系坐标
if (Input.mousePresent)
{
Debug.LogError("______mousepresent");
}
Debug.LogError(Input.mouseScrollDelta+"______scroll");
Debug.LogError(Input.mousePosition+"_____position");
- touchSupported:触控支持
- touchPressureSupported:触控按压支持
- multiTouchEnabled:多个触控支持
- stylusTouchSupported:触控板支持
- simulateMouseWithTouches:通过触摸启用/禁用鼠标模拟。默认情况下,此选项已启用。如果启用,最多三个并发触摸将转换为相应鼠标按钮上的状态(例如:双指点击将等于鼠标右键单击)。
- touchCount:
- GetTouch:
- touches:
Touch[] to = Input.touches;
if (to.Length>0)
{
Debug.LogError(to.Length);
if (to[0].phase==TouchPhase.Began)
{
Debug.LogError("begin");
}
else if (to[0].phase == TouchPhase.Moved)
{
Debug.LogError("move");
}
else if (to[0].phase == TouchPhase.Stationary)
{
Debug.LogError("station");
}
else if (to[0].phase == TouchPhase.Ended)
{
Debug.LogError("end");
}
}
Touch
- position:触控的当前屏幕坐标
- rawPosition:触控的开始移动坐标
- deltaPosition:触控的每次移动方向坐标
- TouchPhase:触控状态Begin,Move,Stationary,End
- TouchType:触控类型,直接触控,远程的,还是触控笔那种
- fingerId:开始:手指放上,依次0123;移开1号,其他不变;再放上一个,从0开始分配空着的1
EventSystem
- InputModule:StandaloneInputModule和TouchInputModule
- Raycaster:Graphic Raycaster(UI),Physics 2D Raycaster(2d),Physics Raycaster(3d)
可以统一用EventSystem来处理射线检测问题,ui摄像机处理ui层,场景摄像机添加Physics Raycaster组件处理射线检测
接口 | 含义 |
---|---|
IPointerEnterHandler | 进入 |
IPointerExitHandler | 离开 |
IPointerDownHandler | 按下 |
IPointerUpHandler | 抬起 |
IPointerClickHandler | 按下和抬起 |
IInitializePotentialDragHandler | 可拖拽物体被发现,可用来初始化一些变量 |
IBeginDragHandler | 开始拖拽 |
IDragHandler | 拖拽中 |
IEndDragHandler | 拖拽结束时 (when) |
IDropHandler | 拖拽结束位置(where) |
IScrollHandler | 鼠标滚轮 |
IUpdateSelectedHandler | 选中物体时,持续发送 |
ISelectHandler | 物体变为被选择 |
IDeselectHandler | 物体变为取消选择 |
IMoveHandler | 物体移动(左右上下等) |
ISubmitHandler | submit(提交)按钮按下 |
ICancelHandler | cancel(取消)按钮按下 |
PointerEventData
- pointerPress:The GameObject that received the OnPointerDown
- dragging:是否拖拽发生
- scrollDelta:滚轮值变化
- clickCount:点击次数
- clickTime:上次发送点击事件的时间
- position:当前坐标
public void OnPointerClick(PointerEventData eventData)
{
if (eventData.clickCount == 2)
{
Debug.log("双击");
}
}
OnMouseXXX
- 在update之前调用,EventSystem是在update中每帧调用,优先进行
网友评论