Esempio n. 1
0
    void HandleWorkerInput(Worker worker)
    {
        if (Input.GetKeyDown(Worker.miningKey))
        {
            Ray inputRay = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(inputRay, out RaycastHit hit))
            {
                if (hit.collider != null)
                {
                    LayerMask colliderMask = 1 << hit.collider.gameObject.layer;

                    if (colliderMask == BaseMetrics.terrainMask)
                    {
                        Voxel targetVoxel = hit.collider.gameObject.GetComponent <Voxel>();

                        if (Input.GetKey(KeyCode.LeftShift))
                        {
                            worker.AddMineAction(targetVoxel);
                        }
                        else
                        {
                            worker.RemoveAllActions();
                            worker.AddMineAction(targetVoxel);
                        }
                    }
                }
            }
        }

        if (Input.GetKeyDown(Worker.selectionModeKey) || playerGUI.CurrentKeyPressed == Worker.selectionModeKey)
        {
            worker.BuildingStatus = BuildingStatus.Selection;
        }

        if (Input.GetKeyDown(Worker.cancelKey))
        {
            if (worker.BuildingStatus == BuildingStatus.Selection)
            {
                worker.BuildingStatus = BuildingStatus.None;
            }
            else if (worker.BuildingStatus == BuildingStatus.Selected)
            {
                // TODO: Still check this
                worker.BuildingStatus = BuildingStatus.Selection;
                worker.DestroyHologram();
            }
        }

        if (worker.BuildingStatus == BuildingStatus.Selection)
        {
            if (Input.GetKeyDown(Worker.selectTurretKey) || playerGUI.CurrentKeyPressed == Worker.selectTurretKey)
            {
                worker.CreateBuildingHologram(Worker.selectTurretKey);
            }
            else if (Input.GetKeyDown(Worker.selectBarracksKey) || playerGUI.CurrentKeyPressed == Worker.selectBarracksKey)
            {
                worker.CreateBuildingHologram(Worker.selectBarracksKey);
            }
        }

        if (Input.GetMouseButtonUp(0) && worker.BuildingStatus == BuildingStatus.Selected)
        {
            Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit))
            {
                if (!Input.GetKey(KeyCode.LeftShift))
                {
                    worker.RemoveAllActions();
                }
                worker.AddBuildAction(hit.transform.position + Vector3.up * BaseMetrics.VoxelDimension * 0.5f);
            }
        }
    }