Esempio n. 1
0
    protected override void AssignToDropZone()
    {
        DropZone_ContractSlot contractDropZone = _currentDropZone.GetComponent <DropZone_ContractSlot>();

        if (contractDropZone != null)
        {
            if (contractDropZone.CheckIfContractAccepted(this, out contractDropZones))
            {
                foreach (var dz in contractDropZones)
                {
                    if (dz.ZoneIndex == 0)
                    {
                        bottomLineRenderer.enabled = false;
                    }
                    dz.AddObjectToDropZone(this);
                }

                Vector2 newPos = contractDropZones[0].ColliderBounds.max;
                newPos.x           = contractDropZones[0].ColliderBounds.min.x;
                transform.position = newPos;
                boardDropZone      = null;

                if (contractAssigned != null)
                {
                    contractAssigned(this);
                }
            }
            else if (boardDropZone != null)
            {
                boardDropZone.AddObjectToDropZone(this);
            }
        }

        else if (boardDropZone != null)
        {
            boardDropZone.AddObjectToDropZone(this);
        }

        else if (_currentDropZone != null)
        {
            _currentDropZone.AddObjectToDropZone(this);
        }
    }
Esempio n. 2
0
    protected override void RemoveFromDropZone()
    {
        bottomLineRenderer.enabled = true;

        foreach (var dz in contractDropZones)
        {
            dz.Occupied = false;
            dz.RemoveObjectFromDropZone(this);
        }

        if (boardDropZone != null)
        {
            boardDropZone.RemoveObjectFromDropZone(this);
        }

        if (_currentDropZone != null)
        {
            _currentDropZone.RemoveObjectFromDropZone(this);
        }

        contractDropZones.Clear();
        _currentDropZone = null;
        boardDropZone    = null;
    }
Esempio n. 3
0
    protected override bool CheckForDropZone(out DropZone dropZone)
    {
        dropZone = null;
        bool found = false;

        Vector2 topCenterPoint = _spriteRenderer.bounds.center;

        topCenterPoint.y = _spriteRenderer.bounds.max.y + (-19 * (1 / 32f));// - ((ClientAmount - 1) * (38 * (1 / 32f)));

        //Debug.DrawLine(topCenterPoint, topCenterPoint + Vector2.up * 0.5f, Color.yellow, 5f);

        Collider2D[] allColliders  = Physics2D.OverlapPointAll(topCenterPoint, dropZoneLayerMask);
        int          colliderCount = allColliders.Length;

        for (int i = 0; i < colliderCount; i++)
        {
            DropZone candidate = allColliders[i].GetComponent <DropZone_ContractSlot>();

            if (candidate != null)
            {
                if (candidate.CheckIfAccepted(this))
                {
                    dropZone = candidate;
                    found    = true;
                    break;
                }
            }
        }

        for (int i = 0; i < colliderCount; i++)
        {
            DropZone_Board candidate = allColliders[i].GetComponent <DropZone_Board>();
            if (candidate != null)
            {
                if (candidate.CheckIfAccepted(this))
                {
                    if (!found)
                    {
                        dropZone      = candidate;
                        boardDropZone = candidate;
                        found         = true;
                    }
                    else
                    {
                        boardDropZone = candidate;
                    }
                    break;
                }
            }
        }
        if (!found)
        {
            for (int i = 0; i < colliderCount; i++)
            {
                DropZone candidate = allColliders[i].GetComponent <DropZone>();
                if (candidate != null)
                {
                    if (candidate.CheckIfAccepted(this))
                    {
                        if (!found)
                        {
                            dropZone = candidate;
                            found    = true;
                            break;
                        }
                    }
                }
            }
        }

        return(found);
    }