public void SnapToReceiver(TouchReceiver receiver) { if (receiver == null) { return; } var position = receiver.GetPosition(); if (!CanSnap(receiver)) { return; } if (lastTouchedReceiver == null) { lastTouchedReceiver = receiver; } if (receiver.id != lastTouchedReceiver.id) { lastTouchedReceiver = receiver; } UpdatePosition(position); }
public bool CanSnap(TouchReceiver receiver) { var position = receiver.GetPosition(); var center = transform.position; if (center.x > position.x + receiver.xRange) { return(false); } if (center.x < position.x - receiver.xRange) { return(false); } if (center.y > position.y + receiver.yRange) { return(false); } if (center.y < position.y - receiver.yRange) { return(false); } return(true); }