EventSystem

it2025-10-05  3

简介

InputIPointerEnterHandler等接口键盘,鼠标,操作杆

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,EndTouchType:触控类型,直接触控,远程的,还是触控笔那种fingerId:开始:手指放上,依次0123;移开1号,其他不变;再放上一个,从0开始分配空着的1

EventSystem

InputModule:StandaloneInputModule和TouchInputModuleRaycaster: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物体移动(左右上下等)ISubmitHandlersubmit(提交)按钮按下ICancelHandlercancel(取消)按钮按下

PointerEventData

pointerPress:The GameObject that received the OnPointerDowndragging:是否拖拽发生scrollDelta:滚轮值变化clickCount:点击次数clickTime:上次发送点击事件的时间position:当前坐标 public void OnPointerClick(PointerEventData eventData) { if (eventData.clickCount == 2) { Debug.log("双击"); } }

OnMouseXXX

在update之前调用,EventSystem是在update中每帧调用,优先进行 Script lifecycle flowchart.jpg

参考

https://blog.csdn.net/tom_221x/article/details/78457615

最新回复(0)