Exemplo n.º 1
0
    //-----------------------------------------------------------------------------------------------------
    // Main game cycle
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            Pause();
        }


        if (puzzle && Time.timeScale > 0 && !gameFinished)
        {
            // Process puzzle and react on it state
            switch (puzzle.ProcessPuzzle(
                        GetPointerPosition(gameCamera),
                        !EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButton(0) && (!cameraScript || !cameraScript.IsCameraMoved()),
                        GetRotationDirection()
                        ))
            {
            case PuzzleState.None:
                ;
                break;

            case PuzzleState.DragPiece:
                break;

            case PuzzleState.ReturnPiece:
                break;

            case PuzzleState.DropPiece:
                break;

            // Hide all pieces and finish game - if whole puzzle Assembled
            case PuzzleState.PuzzleAssembled:
                if (background && !invertRules)
                {
                    puzzle.SetPiecesActive(false);
                }
                SpawnEffect();
                if (winUI)
                {
                    winUI.SetActive(true);
                }
                if (bg_right)
                {
                    bg_right.SetActive(false);
                }
                gameFinished = true;
                break;
            }


            ProcessTimer();
        }
        else  // Show background (assembled puzzle) if gameFinished
        if (gameFinished && (!loseUI || (loseUI && !loseUI.activeSelf)))
        {
            if (!invertRules)
            {
                ShowBackground();
            }
        }


        // Control Camera
        if (cameraScript && puzzle)
        {
            // if (puzzle.GetCurrentPiece() == null)  cameraScript.ManualUpdate();
            cameraScript.enabled = (puzzle.GetCurrentPiece() == null);
        }
    }