Exemplo n.º 1
0
    public GameObject Tick()
    {
        if (_accumulatorForNextInput < _timerForNextInput)
        {
            return(null);
        }
        _accumulatorForNextInput = 0.0f;
        // SPACE
        float                 select            = Input.GetAxisRaw("Jump");
        float                 vertical          = Input.GetAxisRaw("Vertical");
        float                 horizontal        = Input.GetAxisRaw("Horizontal");
        GameObject            nextPiece         = _towerData.SelectPiece(ref _selectedPiece, (int)horizontal, (int)vertical);
        PieceOriginalMaterial originalNextPiece = PieceOriginalMaterial.Get(nextPiece);

        if (nextPiece == _currentPiece)
        {
            MeshRenderer rend = nextPiece.GetComponent <MeshRenderer>();
            return(select > 0.5f && (rend.material = originalNextPiece.originalMaterial) ? _currentPiece : null);
        }
        if (_currentPiece)
        {
            MeshRenderer          rend          = _currentPiece.GetComponent <MeshRenderer>();
            PieceOriginalMaterial originalPiece = PieceOriginalMaterial.Get(_currentPiece);
            rend.material = originalPiece.originalMaterial;
        }
        MeshRenderer rendNext = nextPiece.GetComponent <MeshRenderer>();

        _prevMaterial     = rendNext.material;
        rendNext.material = selectionMaterial;
        _currentPiece     = nextPiece;
        return(select > 0.5f && (rendNext.material = selectionMaterial) ? _currentPiece : null);
    }
Exemplo n.º 2
0
    public void OnDestroy()
    {
        if (_inFloor)
        {
            _tower.DestroyPieceOnFloor(this);
        }

        if (_badPlaced)
        {
            _tower.badPlaced.Remove(gameObject);
        }
        GetComponent <Renderer>().material = PieceOriginalMaterial.Get(gameObject).originalMaterial;
        gameObject.tag = "Finish";
    }
Exemplo n.º 3
0
    private IEnumerator BuildTower(float secondInterval)
    {
        _towerData.ResetTower();
        for (int y = 0; y < towerHeight; y++)
        {
            for (int x = 0; x < 3; x++)
            {
                GameObject piece = _piecePool.Instantiate();
                piece.transform.parent = _tower.transform;

                pieceHeight = piece.transform.localScale.y + 0.05f;
                pieceWidth  = piece.transform.localScale.x + 0.05f;
                var original = PieceOriginalMaterial.Get(piece);
                original.originalMaterial = pieceMaterials[x % 2];
                piece.GetComponent <MeshRenderer>().material = original.originalMaterial;
                if (y % 2 == 0)
                {
                    piece.transform.localPosition = new Vector3(towerCenter.x + (x * pieceWidth - pieceWidth),
                                                                towerCenter.y + y * pieceHeight + pieceHeight,
                                                                towerCenter.z);
                }
                else
                {
                    piece.transform.localRotation = Quaternion.AngleAxis(90.0f, piece.transform.up);
                    piece.transform.localPosition = new Vector3(towerCenter.x,
                                                                towerCenter.y + y * pieceHeight + pieceHeight,
                                                                towerCenter.z + (x * pieceWidth - pieceWidth));
                }
                _towerData.AddPiece(piece);

                yield return(new WaitForSeconds(secondInterval));
            }
            Material temp = pieceMaterials[0];
            pieceMaterials[0] = pieceMaterials[1];
            pieceMaterials[1] = temp;
        }

        // This is a delay because Tower might bug
        yield return(new WaitForSeconds(2f));

        _towerData.towerAlreadyBuilt = true;

        yield return(0);
    }
Exemplo n.º 4
0
    public GameObject Tick(GameObject chosenFromStateMachine = null)
    {
        if (_topPieces == null)
        {
            _topPieces = _tower.GetTopPieces();
        }
        if (chosenFromStateMachine)
        {
            if (selection)
            {
                Renderer selectionRendererSelection = selection.GetComponent <Renderer>();
                PieceOriginalMaterial pom           = PieceOriginalMaterial.Get(selection.gameObject);
                selectionRendererSelection.material = pom.originalMaterial;
            }
            Renderer chosenRenderer = chosenFromStateMachine.GetComponent <Renderer>();
            chosenRenderer.material = mat;
            HandleSelectionFromStateMachine(chosenFromStateMachine);
            return(chosenFromStateMachine);
        }
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit) && hit.transform.CompareTag(selectableTag))
        {
            return(HandleHit(hit));
        }

        if (selection)
        {
            Renderer selectionRendererSelection = selection.GetComponent <Renderer>();
            PieceOriginalMaterial pom           = PieceOriginalMaterial.Get(selection.gameObject);
            selectionRendererSelection.material = pom.originalMaterial;
        }

        selection = null;
        return(null);
    }