示例#1
0
    private ActionPack GetSwapAnimationActionPack(Vector2Int aCell, Vector2Int bCell)
    {
        Vector2 aCellPosition = fieldProperties.CalculateLocalFieldObjectPosition(aCell);
        Vector2 bCellPosition = fieldProperties.CalculateLocalFieldObjectPosition(bCell);

        GameObject aObject = fieldMatrix.GetObjectFromStorage(aCell).GetGameObject();
        GameObject bObject = fieldMatrix.GetObjectFromStorage(bCell).GetGameObject();

        ActionPack swapActionPack = new ActionPack();

        swapActionPack.AddAction((callback) => { coroutinePlayer.PlayCoroutine(CoroutineAnimations.MovementWithEasingFunction(aObject, aCellPosition, bCellPosition, swapDuration, EasingFunctions.EaseOutBack, callback)); });
        swapActionPack.AddAction((callback) => { coroutinePlayer.PlayCoroutine(CoroutineAnimations.MovementWithEasingFunction(bObject, bCellPosition, aCellPosition, swapDuration, EasingFunctions.EaseOutBack, callback)); });

        return(swapActionPack);
    }
示例#2
0
    private IAction CreateNewFieldObjectsAndFillEmptyCells()
    {
        ActionPack updateActions = new ActionPack();

        for (int i = 0; i < fieldProperties.GetFieldSize().x; i++)
        {
            int emptyCellsCount = 0;
            for (int j = 0; j < fieldProperties.GetFieldSize().y; j++)
            {
                if (fieldMatrix.GetObjectFromStorage(i, j) == null)
                {
                    emptyCellsCount++;
                }
                else if (emptyCellsCount > 0)
                {
                    Vector2Int newCellForCurrentObject = new Vector2Int(i, j - emptyCellsCount);
                    Vector2Int currentCell             = new Vector2Int(i, j);

                    Vector2 newPositionForCurrentObject = fieldProperties.CalculateLocalFieldObjectPosition(newCellForCurrentObject);
                    Vector2 currentPosition             = fieldProperties.CalculateLocalFieldObjectPosition(currentCell);

                    GameObject targetObject = fieldMatrix.GetObjectFromStorage(i, j).GetGameObject();

                    fieldMatrix.SwapObjectsInStorage(currentCell, newCellForCurrentObject);

                    updateActions.AddAction((callback) => { coroutinePlayer.PlayCoroutine(CoroutineAnimations.AcceleratedMovement(targetObject, currentPosition, newPositionForCurrentObject, fieldObjectFallingStartSpeed, fieldObjectFallingVelocity, callback)); });
                }
            }

            for (int j = fieldProperties.GetFieldSize().y - emptyCellsCount; j < fieldProperties.GetFieldSize().y; j++)
            {
                Vector2Int imaginaryCell = new Vector2Int(i, j + emptyCellsCount);
                Vector2Int actualCell    = new Vector2Int(i, j);

                Vector2 positionToCreateObject = fieldProperties.CalculateLocalFieldObjectPosition(imaginaryCell);
                Vector2 positionToMoveObject   = fieldProperties.CalculateLocalFieldObjectPosition(actualCell);

                fieldObjectCreator.CreateFieldObject(actualCell, positionToCreateObject);

                GameObject targetObject = fieldMatrix.GetObjectFromStorage(i, j).GetGameObject();

                updateActions.AddAction((callback) => { coroutinePlayer.PlayCoroutine(CoroutineAnimations.AcceleratedMovement(targetObject, positionToCreateObject, positionToMoveObject, fieldObjectFallingStartSpeed, fieldObjectFallingVelocity, callback)); });
            }
        }

        return(updateActions);
    }