Esempio n. 1
0
    // When left mouse up
    private void RealeaseSelection()
    {
        SelectionBox.gameObject.SetActive(false);
        _selection = false;

        // If selection made by box
        if (_boxSelection)
        {
            Vector2 min = SelectionBox.anchoredPosition - (SelectionBox.sizeDelta / 2);
            Vector2 max = SelectionBox.anchoredPosition + (SelectionBox.sizeDelta / 2);

            // If there are units
            SelectUnits?.Invoke(min, max, _selectedUnits);
            _boxSelection = false;
            ShowUnitsInfo();
        }
        // If selection made by left mouse click
        else
        {
            // Drawing Raycast to detect if there is selectable object
            Vector3      worldPos = _manager.GameCamera.ScreenToWorldPoint(_startPos);
            RaycastHit2D hit      = Physics2D.Raycast(worldPos, Vector3.back, Mathf.Infinity);
            Debug.DrawRay(worldPos, Vector3.forward, Color.blue, 10f);

            // Publishing selection request to buildings
            SelectBuilding?.Invoke(hit, _selectedBuildings);

            // If there is building
            if (_selectedBuildings.Count > 0)
            {
                int          buildingIndex = _selectedBuildings[0].BuildingIndex;
                BuildingData buildingData  = _manager.GameConfig.Buildings[buildingIndex];
                _informationMenu.ShowBuildingInfo(buildingData);
            }
            // Else if there is unit
            else
            {
                // Publishing selection request to units
                SelectUnit?.Invoke(hit, _selectedUnits);
                ShowUnitsInfo();
            }
        }
    }
Esempio n. 2
0
 private void OnUnitListItemClick(UnitListItem item)
 {
     SelectUnit?.Invoke(item.UnitType);
 }