简介
- 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
Regular Update Events
GUI events
Physics events
Initialization Events
- 鼠标进入:IPointerEnterHandler,OnPointerEnter
- 鼠标退出:IPointerExitHandler,OnPointerExit
双击
-
UI:
IPointerClickHandler public void OnPointerClick(PointerEventData eventData) { if (eventData.clickCount == 2) { Debug.log("双击"); } }
-
物体:
void Update(){ if(Event.current.isMouse && Event.current.type == EventType.MouseDown && Event.current.clickCount == 2){ if(b){ print("double click " + transform.name); } } } void OnMouseEnter(){ b = true; } void OnMouseExit(){ b =false; }