示例#1
0
    // Place building at selected position
    // Used by SelectLocation() Function
    void PlaceBuilding()
    {
        resourcesDataController.UpdateResourceAmount(GODFORCE, -godForceCost);
        resourcesDataController.UpdateResourceAmount(FOOD, -foodCost);
        resourcesDataController.UpdateResourceAmount(STONE, -stoneCost);
        resourcesDataController.UpdateResourceAmount(WOOD, -woodCost);
        resourcesDataController.UpdateResourceAmount(MINERALS, -mineralsCost);

        Vector3Int position = newBuilding.GetComponent<GenericBuilding>().GridRef.WorldToCell(newBuilding.transform.position);

        position.x += mapCreator.MapWidth / 2;
        position.y += mapCreator.MapHeight / 2;

        newBuilding.GetComponent<GenericBuilding>().LastPosition = position;

        newBuilding.GetComponent<GenericBuilding>().UpdateNode(position, false);
        Time.timeScale = lastTimeScale;

        LevelManagerRef.StateMachineRef.ChangeState(LevelManagerRef.States[LevelManager.StatesEnum.BaseState]);
        LevelManagerRef.CreateBuildingRef = null;
    }
示例#2
0
    public void PlaceObject()
    {
        if (GfAmount.Value > GfCostIndicatorValue.Value)
        {
            selectObjectRef.SelectedObject.transform.position = Position;

            switch (_selectedType)
            {
            case SELECTED_BUILDING:

                Vector3Int position = GridRef.WorldToCell(ObjectToMove.transform.position);

                position.x += MapCreatorRef.MapWidth / 2;
                position.y += MapCreatorRef.MapHeight / 2;

                selectObjectRef.Building.UpdateNode(position, false);
                break;
            }

            LevelManagerRef.StateMachineRef.ChangeState(LevelManagerRef.States[LevelManager.StatesEnum.ObjectSelected]);
            ResourcesDataControllerRef.UpdateResourceAmount(GODFORCE, -GfCostIndicatorValue.Value);
        }
    }
示例#3
0
    public void CreatingLand()
    {
        note.SetActive(true);

        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // get the collision point of the ray with the z = 0 plane
        Vector3    worldPoint = ray.GetPoint(-ray.origin.z / ray.direction.z);
        Vector3Int position   = mapGrid.WorldToCell(worldPoint);

        hoverTile.transform.position = position + hoverTileOffset;

        _godForce = resourcesDataController.GetResourceAmount(GODFORCE);

        if (Input.GetMouseButton(0))
        {
            if (_godForce > LandCost && LandTileMap.GetTile(position) == null)     //create land on left click
            {
                LandTileMap.SetTile(position, LandTile);                           //remove water
                WaterTileMap.SetTile(position, null);                              // create land

                resourcesDataController.UpdateResourceAmount(GODFORCE, -LandCost); // update god force
                resourcesDataController.UpdateResourcesValue();

                //refresh colliders
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = false;
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = true;

                // update positions for pathfinder
                position.x += mapCreator.MapWidth / 2;
                position.y += mapCreator.MapHeight / 2;
                Utils.UpdatePathfinderNode(position, true);
            }
        }

        if (Input.GetMouseButton(1)) // remove land on right click
        {
            if (LandTileMap.GetTile(position) != null)
            {
                LandTileMap.SetTile(position, null);       //remove land
                WaterTileMap.SetTile(position, WaterTile); // return water

                //refresh colliders
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = false;
                WaterTileMap.GetComponent <CompositeCollider2D>().enabled = true;

                resourcesDataController.UpdateResourceAmount(GODFORCE, LandCost);;  // update god force
                resourcesDataController.UpdateResourcesValue();

                // update positions for pathfinder
                position.x += mapCreator.MapWidth / 2;
                position.y += mapCreator.MapHeight / 2;

                Utils.UpdatePathfinderNode(position, false);
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            note.SetActive(false);
            hoverTile.transform.position = new Vector3(0f, -20f, 0f);
            LevelManagerRef.StateMachineRef.ChangeState(LevelManagerRef.States[LevelManager.StatesEnum.BaseState]);
        }
    }