Exemple #1
0
    protected void InitHighlights()
    {
        PieceDimension.Row[] columns = PieceInfo.Columns;

        if (columns == null)
        {
            return;
        }

        float width = 1f;
        List <PieceHighlight> attachedHighlights = new List <PieceHighlight>();

        for (int y = 0; y < columns.Length; y++)
        {
            bool[] rowItems = columns[y].RowBools;

            if (rowItems == null)
            {
                continue;
            }

            for (int x = 0; x < rowItems.Length; x++)
            {
                if (!rowItems[x])
                {
                    continue;
                }

                Vector2Int drawOffset   = PieceInfo.GetRelativeIndex(x, y);
                Vector3    cubePosition = transform.localPosition;
                cubePosition += new Vector3(drawOffset.x * width, 0f, drawOffset.y);

                PieceHighlight thisHighlight = PieceHighlightHolder.InstantiateChild <PieceHighlight>(PieceHighlightPrefab.gameObject);
                thisHighlight.transform.localPosition = cubePosition;

                attachedHighlights.Add(thisHighlight);
            }
        }

        CurrentHighlights = attachedHighlights.ToArray();

        UpdateHits();
    }
Exemple #2
0
    public bool DoesOtherPieceCollide(BasePiece otherPiece)
    {
        if (otherPiece == null || otherPiece.CurrentHighlights == null || otherPiece.CurrentHighlights.Length <= 0)
        {
            return(false);
        }

        // Ensure we have the latest data for both pieces
        otherPiece.UpdateHits(false);
        UpdateHits(false);

        List <BoardGridLocation> collidedLocations = new List <BoardGridLocation>();

        for (int i = 0; i < CurrentHighlights.Length; i++)
        {
            PieceHighlight thisHighlight = CurrentHighlights[i];

            if (thisHighlight == null)
            {
                continue;
            }

            for (int k = 0; k < otherPiece.CurrentHighlights.Length; k++)
            {
                PieceHighlight otherHighlight = otherPiece.CurrentHighlights[k];

                if (thisHighlight.FoundGridPosition != null && thisHighlight.FoundGridPosition == otherHighlight.FoundGridPosition)
                {
                    collidedLocations.Add(thisHighlight.FoundGridPosition);
                    return(true);
                }
            }
        }

        return(false);
    }