Example #1
0
    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);
    }
Example #2
0
    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);
    }