コード例 #1
0
    public int TriggerShapeDestruction(int index, Transform boardParent)
    {
        // Getting the current slot
        GameShape centerShape = boardParent.GetChild(index).GetComponent <GameSlot>().GetSlotShape();

        if (centerShape == null)
        {
            Debug.LogError("Couldn't find shape when triggering destruction at slot " + index);
            return(-1);
        }

        // Declaring temp storage variable
        List <int> targetIndexes = CheckForSurroundingShapes(index, boardParent);
        GameSlot   slot;
        GameShape  shape = null;
        bool       destoryCurrentSlot      = false;
        int        newShapesBeingDestroyed = 0;

        if (targetIndexes != null)
        {
            foreach (int i in targetIndexes)
            {
                slot  = boardParent.GetChild(i).GetComponent <GameSlot>();
                shape = slot.GetSlotShape();

                if (gameManager.CheckForMatch(centerShape, shape))
                {
                    if (!shape.IsMarkedForDestruct())
                    {
                        shape.TriggerDestruction();
                        shape.MarkForDestruction();
                        newShapesBeingDestroyed++;
                        shapesBeingDestroyed++;
                    }

                    destoryCurrentSlot = true;
                }
            }
        }

        if (destoryCurrentSlot)
        {
            if (!centerShape.IsMarkedForDestruct())
            {
                centerShape.TriggerDestruction();
                centerShape.MarkForDestruction();
                newShapesBeingDestroyed++;
                shapesBeingDestroyed++;
            }
        }

        //onShapeDestroy?.Invoke(newShapesBeingDestroyed);
        return(newShapesBeingDestroyed);
    }