示例#1
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, rayLength, layerMask))
            {
                Debug.Log("Selected: " + hit.transform.name);

                if (expandBordersMode)
                {
                    HexCell hex = hit.transform.GetComponent <HexCell>();
                    if (hex.isHighlighted)
                    {
                        cityExpanding.AddCellToCityBorders(hex);
                    }
                }
                else
                {
                    // tiles are interactable
                    if (interactableTiles)
                    {
                        HexCell hex = hit.transform.GetComponent <HexCell>();
                        if (hex != null)
                        {
                            DeselectEverything();

                            currentSelectedCell = hex;
                            terrainPanel.SetActive(true);
                            currentSelectedCell.SelectCell();
                        }
                        else
                        {
                            terrainPanel.SetActive(false);
                            if (currentSelectedCell != null)
                            {
                                DeselectEverything();
                            }
                        }
                    }

                    // select city
                    CityManager city = hit.transform.GetComponent <CityManager>();
                    if (city != null)
                    {
                        DeselectEverything();

                        currentSelectedCity = city;
                        hexCamera.SetGameObjectToFollow(city.gameObject);
                        currentSelectedCity.SelectCity();
                    }
                    else
                    {
                        if (currentSelectedCity != null)
                        {
                            DeselectEverything();
                        }
                    }

                    // units are interactable
                    if (interactableUnits)
                    {
                        Unit unit = hit.transform.GetComponentInParent <Unit>();
                        if (unit != null)
                        {
                            DeselectEverything();

                            currentSelectedUnit = unit;
                            hexCamera.SetGameObjectToFollow(unit.gameObject);
                            currentSelectedUnit.SelectUnit();
                        }
                        else
                        {
                            if (currentSelectedUnit != null)
                            {
                                DeselectEverything();
                            }
                        }
                    }
                }
            }
            else
            {
                DeselectEverything();
            }
        }
    }