// 注册鼠标事件回调函数 private void _RegisterMouseEvent(int dicIndex, MouseEventType mouseEventType, MeCallback callback) { // 同一个回调函数只能注册一次 bool flag = false; foreach (MouseEventType _meType in dicPointer[dicIndex].Keys) { if (_meType == mouseEventType) { flag = true; break; } } if (!flag) { dicPointer[dicIndex].Add(mouseEventType, new List <MeCallback>()); } MeCallback meCallback = (MeCallback)callback; if (dicPointer[dicIndex][mouseEventType].Contains(meCallback)) { Debug.LogError("Mouse event handler has already been registered"); return; } dicPointer[dicIndex][mouseEventType].Add(meCallback); }
// 取消鼠标事件回调函数 private void _UnRegisterMouseEvent(int dicIndex, MouseEventType mouseEventType, MeCallback meCallback) { bool flag = false; foreach (MouseEventType _meType in dicPointer[dicIndex].Keys) { if (_meType == mouseEventType) { flag = true; break; } } if (flag) { dicPointer[dicIndex][mouseEventType].Remove(meCallback); } else { Debug.LogError("Mouse event handler has not been registered"); } }
public void OnMousePressedU(MouseEventType mouseEventType, KeyCode keyCode, MeCallback meCallback) { int dicIndex = GetKeyEventIndex(keyCode, KeyActionType.Pressed); _UnRegisterMouseEvent(dicIndex, mouseEventType, meCallback); }
// 注册鼠标事件处理函数 // 注册鼠标按下回调 public void OnMouseDownR(MouseEventType mouseEventType, KeyCode keyCode, MeCallback meCallback) { int dicIndex = GetKeyEventIndex(keyCode, KeyActionType.Down); _RegisterMouseEvent(dicIndex, mouseEventType, meCallback); }