示例#1
0
    public virtual void OnEndDrag(PointerEventData eventData)
    {
        if (!Hamster || Hamster.HamsterData.status != HamsterStatus.Adult)
        {
            return;
        }

        Vector2         dropPos = Camera.main.ScreenToWorldPoint(eventData.position);
        HamsterLocation next    = GetClostestHamsterLocation(dropPos);

        if (next != null)
        {
            next.Hamster = Hamster;
            Hamster      = null;
        }
        else
        {
            Hamster = Hamster;
        }
    }
示例#2
0
    protected HamsterLocation GetClostestHamsterLocation(Vector2 pos)
    {
        float           bestDist = float.MaxValue;
        HamsterLocation bestLoc  = null;

        foreach (var hamLoc in RunManager.Instance.PlacableHamsterLocations)
        {
            float dist = Vector2.Distance(pos, hamLoc.transform.position);
            if (dist > SNAP_RADIUS || hamLoc.Hamster != null)
            {
                continue;
            }

            if (dist < bestDist)
            {
                bestDist = dist;
                bestLoc  = hamLoc;
            }
        }

        return(bestLoc);
    }