Пример #1
0
        void ActivateTowerMenu()
        {
            //if placing a tower, a menu should not be activated
            if (attachedTower != null)
            {
                return;
            }
            //if another menu is active, don't just make more
            if (currentMenu != null)
            {
                return;
            }

            //if there is something in that cell
            if (currentCell.occupant != null)
            {
                //and that something is a tower spot
                currentSpot = currentCell.occupant.GetComponent <TowerSpot>();
                if (currentSpot != null)
                {
                    //and the tower spot contains a tower
                    currentTower = currentSpot.Occupant;
                    if (currentTower != null)
                    {
                        //instantiate tower menu object on canvas at tower point
                        //hook tower up to menu buttons
                        //pause game

                        currentMenu = Instantiate(TowerMenuPrefab, mainCanvas.transform);
                        currentMenu.GetComponent <RectTransform>().anchoredPosition = currentCell.transform.position;
                        currentMenu.Init(currentTower);
                    }
                }
            }
        }
Пример #2
0
 public void OnTowerSpotTap(TowerSpot spot)
 {
     if (spot.buildedTower == null)
     {
         OnEmptyTowerSpotTap();
     }
     else
     {
         OnTowerTap(spot.buildedTower);
     }
 }
    public void OnTowerSpotSelected(TowerSpot towerSpot)
    {
        var tower = towerSpot.buildedTower;

        if (tower == null)
        {
            return;
        }

        ShowTowerInfo(tower);
    }
 private void OnSpotSelected(TowerSpot spot)
 {
     selectedSpot = spot;
     OnSpotTapped?.Invoke(selectedSpot);
 }
Пример #5
0
        /// <summary>
        /// Generic function for handling responses to input events
        /// </summary>
        void HandleInput()
        {
            //pause game on space
            if (Input.GetKeyDown(KeyCode.Space))
            {
                if (isPaused)
                {
                    ResumeGame();
                }
                else
                {
                    PauseGame();
                }
            }

            //bring up pause menu on escape
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (attachedTower != null)
                {
                    Destroy(attachedTower.gameObject);
                }
                else if (currentMenu != null && currentMenu.gameObject.activeSelf)
                {
                    currentMenu.gameObject.SetActive(false);
                }
                else if (PauseMenu.activeSelf)
                {
                    ResumeGame();
                    PauseMenu.SetActive(false);
                }
                else
                {
                    ActivatePauseMenu();
                }
            }

            //dont allow other inputs if pause menu is up
            if (PauseMenu != null && PauseMenu.activeSelf)
            {
                return;
            }

            //Check for the current cell and force the currently attached tower to that cell
            Ray        inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(inputRay, out hit))
            {
                //Debug.Log( mainMap.GetCellAtPosition(hit.point).occupant);
                currentCell = mainMap.GetCellAtPosition(hit.point);
                if (currentCell != null)
                {
                    //if a tower is attached to cursor, place it
                    if (attachedTower != null)
                    {
                        attachedTower.transform.position = currentCell.transform.position;
                    }
                    if (currentCell.occupant != null)
                    {
                        currentSpot = currentCell.occupant.GetComponent <TowerSpot>();
                    }
                }
            }

            if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject() && currentMenu != null)
            {
                Destroy(currentMenu.gameObject);
                currentMenu = null;
            }

            //Place the currently attached tower if the user clicks on the spot
            if (Input.GetMouseButtonUp(0) && !EventSystem.current.IsPointerOverGameObject())
            {
                if (!PlaceTower())
                {
                    ActivateTowerMenu();
                }
            }

            //right click cancels tower placement
            if (Input.GetMouseButton(1))
            {
                if (attachedTower != null)
                {
                    Destroy(attachedTower.gameObject);
                }
            }
        }