示例#1
0
        /// <summary>
        ///     This function controls the button events from UVC.
        ///     This code if not run in background process, will not be able to handle button pressed events when app is suspended.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void smtc_ButtonPressed(SystemMediaTransportControls sender,
                                        SystemMediaTransportControlsButtonPressedEventArgs args)
        {
            switch (args.Button)
            {
            case SystemMediaTransportControlsButton.Play:
                Debug.WriteLine("UVC play button pressed");
                PlayPressed?.Invoke(this, null);
                break;

            case SystemMediaTransportControlsButton.Pause:
                Debug.WriteLine("UVC pause button pressed");
                PausePressed?.Invoke(this, null);
                break;

            case SystemMediaTransportControlsButton.Next:
                Debug.WriteLine("UVC next button pressed");
                NextPressed?.Invoke(this, null);
                break;

            case SystemMediaTransportControlsButton.Previous:
                Debug.WriteLine("UVC previous button pressed");
                PrevPressed?.Invoke(this, null);
                break;
            }
        }
示例#2
0
 public void OnPauseButtonAction(InputAction.CallbackContext context)
 {
     if (context.ReadValueAsButton() && !context.performed)
     {
         PausePressed?.Invoke();
     }
 }
        void Update()
        {
            if (GameManager.Instance.GameState != GameState.InGame)
            {
                return;
            }
            if (GameManager.Instance.IsGamePaused)
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.Space))
            {
                PausePressed?.Invoke(null, null);
            }
            if (Input.GetKeyDown(KeyCode.F3))
            {
                canUseSlowMo = !canUseSlowMo;
            }

            if (Input.GetMouseButtonDown(0))
            {
                if (inSlowMo)
                {
                    SetSlowMo(false);
                }
                else
                {
                    Shot?.Invoke(null, null);
                    ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                    if (Physics.Raycast(ray, out var hit))
                    {
                        var newBullet = Instantiate(Bullet, transform.position, Quaternion.identity);
                        Destroy(newBullet, 0.5f);

                        newBullet.transform.LookAt(hit.point);
                        bullets.Add(newBullet.GetComponent <Rigidbody>());

                        if (hit.transform.gameObject.CompareTag("Target"))
                        {
                            SetSlowMo(true, newBullet.transform);
                        }
                    }

                    audioSource.volume = GameManager.Instance.SoundVolume / 5;
                    audioSource.DOPitch(inSlowMo ? UnityEngine.Random.Range(0.2f, 0.2f) : 1, 0.1f);
                    audioSource.Play();
                }
            }

            for (int i = 0; i < bullets.Count; i++)
            {
                if (bullets[i] == null || bullets[i].transform == null)
                {
                    SetSlowMo(false);
                    bullets.RemoveAt(i);
                }
            }
        }
示例#4
0
        private void SystemMediaTransportControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
        {
            switch (args.Button)
            {
            case SystemMediaTransportControlsButton.Play:
                PlayPressed?.Invoke();
                break;

            case SystemMediaTransportControlsButton.Pause:
                PausePressed?.Invoke();
                break;

            case SystemMediaTransportControlsButton.Next:
                NextPressed?.Invoke();
                break;

            case SystemMediaTransportControlsButton.Previous:
                PreviousPressed?.Invoke();
                break;

            default:
                break;
            }
        }
示例#5
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.L))
        {
        }

        switch (state)
        {
        case GameState.LineDraw:
            if (Input.GetMouseButton(0))
            {
                if (OnLeftClick != null)
                {
                    OnLeftClick.Invoke();
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                if (OnLeftMouseRelease != null)
                {
                    OnLeftMouseRelease.Invoke();
                }
            }
            if (Input.GetKeyDown(KeyCode.Return))
            {
                ReleasePlayer();
            }
            if (Input.GetButtonDown("Reset"))
            {
                Reset();
            }
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                state     = GameState.Paused;
                lastState = GameState.LineDraw;
                if (PausePressed != null)
                {
                    PausePressed.Invoke(true);
                }
                else
                {
                    Debug.Log("Not subsrcibed to pause event");
                }
                Time.timeScale = 0;
            }
            break;

        case GameState.MovePlayer:
            if (Input.GetButton("Left"))
            {
                if (OnMoveLeft != null)
                {
                    OnMoveLeft.Invoke();
                }
            }
            if (Input.GetButton("Right"))
            {
                if (OnMoveRight != null)
                {
                    OnMoveRight.Invoke();
                }
            }
            if (Input.GetButtonDown("Jump"))
            {
                if (OnJump != null)
                {
                    OnJump.Invoke();
                }
            }
            if (Input.GetButtonDown("Reset"))
            {
                Reset();
            }
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                state     = GameState.Paused;
                lastState = GameState.MovePlayer;
                if (PausePressed != null)
                {
                    PausePressed.Invoke(true);
                }
                Time.timeScale = 0;
            }
            break;

        case GameState.Paused:
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                state          = lastState;
                Time.timeScale = 1;
                if (PausePressed != null)
                {
                    PausePressed.Invoke(false);
                }
            }
            break;

        case GameState.LevelEnd:
            if (Input.GetButtonDown("Reset"))
            {
                Reset();
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                state          = GameState.Paused;
                lastState      = GameState.LevelEnd;
                Time.timeScale = 0;
                if (PausePressed != null)
                {
                    PausePressed.Invoke(true);
                }
            }
            else if (Input.anyKeyDown)
            {
                Manager <GameManager> .Instance.totalScore += Manager <UIManager> .Instance.score;
                int levelIndex = SceneManager.GetActiveScene().buildIndex;
                if (levelIndex >= SceneManager.sceneCountInBuildSettings - 1)
                {
                    Manager <GameManager> .Instance.LoadMainMenu();
                }
                else
                {
                    Manager <GameManager> .Instance.LoadNewScene(levelIndex + 1);
                }
            }
            break;

        default:
            break;
        }
    }
 protected virtual void OnPausePressed()
 {
     PausePressed?.Invoke(this, EventArgs.Empty);
 }