private DragDirectionEnum GetMoveDirection(Vector2 delta) { float xMove = Mathf.Abs(delta.x); float yMove = Mathf.Abs(delta.y); DragDirectionEnum dir = DragDirectionEnum.DragDirNone; if (xMove < xLimit && yMove < yLimit) { return(dir); } if (xMove > yMove) { if (currentTouch.delta.x > 0) { dir = DragDirectionEnum.DragRight; } else { dir = DragDirectionEnum.DragLeft; } } else { if (currentTouch.delta.y > 0) { dir = DragDirectionEnum.DragUp; } else { dir = DragDirectionEnum.DragDown; } } return(dir); }
private void ProgressTouch(bool press, bool up) { if (press) { currentTouch.lastPos = currentTouch.pos; currentTouch.dragState = TouchDragState.Begin; currentTouch.delta = currentTouch.totalDelta = Vector2.zero; currentTouch.IsDraging = false; } else if (currentTouch.dragState != TouchDragState.End) { Vector2 delta = currentTouch.pos - currentTouch.lastPos; currentTouch.totalDelta += delta; if (currentTouch.dragState == TouchDragState.Begin && delta.magnitude != 0) { currentTouch.delta = currentTouch.totalDelta; currentTouch.dragState = TouchDragState.StartDrag; } else if (currentTouch.dragState == TouchDragState.StartDrag) { float drag = useMouse ? mouseDragThreshold : touchDragThreshold; if (drag < currentTouch.totalDelta.magnitude) { currentTouch.dragState = TouchDragState.Drag; currentTouch.delta = delta; if (DragBegin != null && !currentTouch.IsDraging) { DragBegin(currentTouch.pos); } currentTouch.IsDraging = false; } } if (currentTouch.dragState == TouchDragState.Drag) { currentTouch.dragState = TouchDragState.StartDrag; if (Drag != null) { Drag(currentTouch.pos, currentTouch.delta); } if (DragDirection != null) { DragDirectionEnum dir = GetMoveDirection(currentTouch.delta); DragDirection(dir, Mathf.Abs(currentTouch.delta.y)); } if (DragFixDirection != null) { List <DragDirectionEnum> list = GetMoveFixDirection(currentTouch.delta); if (list != null && list.Count != 0) { foreach (var item in list) { DragFixDirection(item, delta); } } } currentTouch.IsDraging = true; } } if (up) { currentTouch.dragState = TouchDragState.End; if (DragOver != null) { DragOver(currentTouch.pos); } currentTouch.IsDraging = false; } }