コード例 #1
0
        private void Update()
        {
            _selectionManager.UpdateMouseMode(CurMouseMode);

            switch (CurMouseMode)
            {
            case MouseMode.PURCHASING:
            {
                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit))
                {
                    ShowGhostUnitsAndMaybePurchase(hit);
                }
                else
                {
                    _currentBuyTransaction.HidePreview();
                }

                MaybeExitPurchasingModeAndRefund();
                break;
            }

            case MouseMode.NORMAL:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (IsMouseOverCover())
                {
                    EnterNormalCoverMode();
                }

                break;
            }

            case MouseMode.NORMAL_COVER:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (!IsMouseOverCover())
                {
                    EnterNormalMode();
                }

                break;
            }

            case MouseMode.VISION_RULER:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, false);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }


                if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;
            }

            case MouseMode.FIRE_POS:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                RaycastHit hit;
                if (Util.GetTerrainClickLocation(out hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, true);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }

                // React to clicks
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchFirePosCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }

                break;
            }

            case MouseMode.REVERSE_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.REVERSE);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.FAST_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.FAST);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.SPLIT:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchSplitCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            default:
                throw new Exception("impossible state");
            }
        }
コード例 #2
0
        private void Update()
        {
            _selectionManager.UpdateMouseMode(CurMouseMode);

            switch (CurMouseMode)
            {
            case MouseMode.PURCHASING:
            {
                if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    ShowGhostUnitsAndMaybePurchase(hit);
                }
                else
                {
                    _currentBuyTransaction.HidePreview();
                }

                MaybeExitPurchasingModeAndRefund();
                break;
            }

            case MouseMode.FLARE:
            {
                if (Input.GetMouseButton(1))
                {
                    ExitFlareMode();
                }
                else if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    if (Input.GetMouseButton(0))
                    {
                        CommandConnection.Connection.CmdSpawnFlare(
                            _flare.Text,
                            MatchSession.Current.LocalPlayer.Data.Id,
                            hit.point);

                        ExitFlareMode();
                    }
                    else
                    {
                        _flare.transform.position = hit.point;
                        _flare.gameObject.SetActive(true);
                    }
                }
                else
                {
                    if (Input.GetMouseButton(0))
                    {
                        ExitFlareMode();
                    }
                    else
                    {
                        // We only hide the flare if the cursor is hovering somewhere bad
                        _flare.gameObject.SetActive(false);
                    }
                }

                break;
            }

            case MouseMode.NORMAL:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (IsMouseOverCover())
                {
                    EnterNormalCoverMode();
                }

                break;
            }

            case MouseMode.NORMAL_COVER:
            {
                ApplyHotkeys();
                _rightClickManager.Update();

                if (!IsMouseOverCover())
                {
                    EnterNormalMode();
                }

                break;
            }

            case MouseMode.VISION_RULER:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, false);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }


                if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;
            }

            case MouseMode.FIRE_POS:
            {
                ApplyHotkeys();

                // Show range and line of sight indicators
                if (Util.GetTerrainClickLocation(out RaycastHit hit))
                {
                    _selectionManager.ToggleTargetingPreview(true);
                    int minDistance = _selectionManager.PlaceTargetingPreview(
                        hit.point, true);
                    _rangeTooltipText.text = minDistance.ToString() + "m";
                    _rangeTooltip.SetActive(true);
                    _rangeTooltip.transform.position = Input.mousePosition;
                }
                else
                {
                    _selectionManager.ToggleTargetingPreview(false);
                    _rangeTooltip.SetActive(false);
                }

                // React to clicks
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchFirePosCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }

                break;
            }

            case MouseMode.REVERSE_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.REVERSE);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.FAST_MOVE:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    MoveGhostsToMouse();
                    _selectionManager.DispatchMoveCommand(
                        false, MoveCommandType.FAST);
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.SPLIT:
                ApplyHotkeys();
                if (Input.GetMouseButtonDown(0))
                {
                    _selectionManager.DispatchSplitCommand();
                }

                if ((Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) ||
                    Input.GetMouseButtonDown(1))
                {
                    EnterNormalModeNaive();
                }
                break;

            case MouseMode.IN_MENU:
            {
                if (_commands.ToggleMenu)
                {
                    _minimap.enabled = true;
                    if (_lastCameraWasSliding)
                    {
                        _slidingCamera.enabled = true;
                    }
                    else
                    {
                        _orbitCamera.enabled = true;
                    }
                    _menu.SetActive(false);
                    EnterNormalModeNaive();
                }
                break;
            }

            default:
                throw new Exception("impossible state");
            }
        }