public virtual void OnDrag(PointerEventData eventData) { if (isDraggable) { screenTapping.TappingEffect(eventData); //Play screenTapping animation Vector2 localPointerPosition; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasTransform, eventData.position, eventData.pressEventCamera, out localPointerPosition)) { float xPos = localPointerPosition.x - _pointerOffset.x; float yPos = localPointerPosition.y - _pointerOffset.y; transform.localPosition = new Vector2(xPos, yPos); } SnapLocation locationToGoTo = GetClosestSnapLocation(); if (locationToGoTo != null) { if (lastLocation != locationToGoTo) { lastLocation = locationToGoTo; locationToGoTo.Hover(gameObject, false); // Clear all highlights locationToGoTo.Hover(gameObject, true); // Set on highlight for current tile AudioController.Instance.SnapTile(); } } else { lastLocation = null; TurnOffHovering(); } } }
public virtual void OnEndDrag(PointerEventData eventData) { if (isDraggable) { startTime = Time.time; isDragging = false; screenTapping.TappingEffect(eventData); //Play screenTapping animation SnapLocation locationToGoTo = GetClosestSnapLocation(); if (locationToGoTo != null) { transform.position = locationToGoTo.transform.position; locationToGoTo.Snap(gameObject); locationToGoTo.Hover(gameObject, false); } else { transform.localScale = nonDraggingScale; //Make the block samller //transform.localScale = new Vector3(1f, 1f, 1f); TurnOffHovering(); currentPosition = transform.localPosition; //transform.localPosition = defaultPosition; } if (EndDragEvent != null) { EndDragEvent(this); } } }