public override bool ShouldActivateModule() { if (!base.ShouldActivateModule()) { return(false); } _controller = DadaInput.GetJoystick(0); var shouldActivate = _controller.GetButtonDown(m_SubmitButton); shouldActivate |= _controller.GetButtonDown(m_CancelButton); shouldActivate |= !Mathf.Approximately(_controller.GetAxis(m_HorizontalAxis), 0.0f); shouldActivate |= !Mathf.Approximately(_controller.GetAxis(m_VerticalAxis), 0.0f); shouldActivate |= (m_MousePosition - m_LastMousePosition).sqrMagnitude > 0.0f; shouldActivate |= Input.GetMouseButtonDown(0); return(shouldActivate); }
/// <summary> /// Process submit keys. /// </summary> private bool SendSubmitEventToSelectedObject() { if (eventSystem.currentSelectedGameObject == null) { return(false); } var data = GetBaseEventData(); if (_controller.GetButtonDown(m_SubmitButton)) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler); } if (_controller.GetButtonDown(m_CancelButton)) { ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.cancelHandler); } return(data.used); }
protected virtual void ProcessJump() { AbstractController _controller = _hero.PlayerInstance.Controller; if (_controller.GetButtonDown(VirtualKey.JUMP) && Physics2D.Linecast(transform.position, transform.position - _wallCheck.localPosition, 1 << LayerMask.NameToLayer("Ground"))) { _jumpStartTime = Time.time; _jump = true; _walljump = 1; //_anim.SetBool("Slide", true); } else if (_controller.GetButtonDown(VirtualKey.JUMP) && Physics2D.Linecast(transform.position, transform.position + _wallCheck.localPosition, 1 << LayerMask.NameToLayer("Ground"))) { _jumpStartTime = Time.time; _jump = true; _walljump = 2; //_anim.SetBool("Slide", true); } else { _walljump = 0; } // If the jump button is pressed and the player is grounded then the player should jump. if (_controller.GetButtonDown(VirtualKey.JUMP) && _grounded) { _jumpStartTime = Time.time; _jumpStart = true; _jump = true; } else if (_controller.GetButtonUp(VirtualKey.JUMP) || Time.time - _jumpStartTime > _hero.JumpLength) { _jump = false; } }
protected virtual void ProcessWeapons() { AbstractController _controller = _hero.PlayerInstance.Controller; //Use the ranged weapon from the muzzle if (_controller.GetButtonDown(VirtualKey.SHOOT)) { _hero.RangedWeapon.OnTriggerDown(); } else if (_controller.GetButtonUp(VirtualKey.SHOOT)) { _hero.RangedWeapon.OnTriggerUp(); } //use the melee weapon if (_controller.GetButtonDown(VirtualKey.MELEE)) { _hero.MeleeWeapon.OnTriggerDown(); } else if (_controller.GetButtonUp(VirtualKey.MELEE)) { _hero.MeleeWeapon.OnTriggerUp(); } }
// Update is called once per frame void Update() { if (_currentScreen == Screen.START) { //highlight Start text if (_controller.GetButtonDown(VirtualKey.UP) && !_startFadeText.IsFading) { _startFadeText.Fade(); _creditsFadeText.Stop(1, 0.15f); StartGameText.color = Color.yellow; CreditsText.color = Color.white; MenuBipAudio.PlayEffect(); } //highlight Credits text if (_controller.GetButtonDown(VirtualKey.DOWN) && !_creditsFadeText.IsFading) { _creditsFadeText.Fade(); _startFadeText.Stop(1, 0.15f); CreditsText.color = Color.yellow; StartGameText.color = Color.white; MenuBipAudio.PlayEffect(); } //player pressed submit if (_controller.GetButtonDown(VirtualKey.SUBMIT)) { //Go to credits if (_creditsFadeText.IsFading) { _creditsFadeText.Stop(1, 0.15f); CreditsText.color = Color.white; StartPage.Fade(1, 0, 0, 0.3f); CreditsPage.Fade(0, 1, 0.3f, 0.3f); _currentScreen = Screen.CREDITS; } //Go to player selection else { _creditsFadeText.Stop(1, 0.15f); CreditsText.color = Color.white; StartPage.Fade(1, 0, 0, 0.3f); EggsAnimator.SetTrigger("PopIn"); _currentScreen = Screen.PLAYER_SELECTION; SelectPlayerLabel.Fade(0, 1, 0.5f, 0.3f); } LogoAnimator.SetTrigger("Reduce"); MenuConfirmAudio.PlayEffect(); } } else if (_currentScreen == Screen.CREDITS) { //player pressed back if (_controller.GetButtonDown(VirtualKey.BACK)) { //Go to start _startFadeText.Fade(); StartGameText.color = Color.yellow; LogoAnimator.SetTrigger("Enlarge"); CreditsPage.Fade(1, 0, 0, 0.2f); StartPage.Fade(0, 1, 0.3f, 0.3f); _currentScreen = Screen.START; MenuBackAudio.PlayEffect(); } } else if (_currentScreen == Screen.PLAYER_SELECTION) { //Go to Start and close eggs if (_controller.GetButtonDown(VirtualKey.BACK)) { _startFadeText.Fade(); StartGameText.color = Color.yellow; for (int i = _playerNum - 1; i >= 0; i--) { PlayerEggsAnim[i].SetTrigger("Close"); } LogoAnimator.SetTrigger("Enlarge"); EggsAnimator.SetTrigger("PopOut"); StartPage.Fade(0, 1, 1f, 0.3f); SelectPlayerLabel.Fade(1, 0, 0, 0.2f); _currentScreen = Screen.START; _playerNum = 0; MenuBackAudio.PlayEffect(); } //open new egg if (_controller.GetButtonDown(VirtualKey.RIGHT)) { if (_playerNum < DadaInput.ControllerCount) { PlayerEggsAnim[_playerNum].SetTrigger("Crack"); _playerNum++; MenuBipAudio.PlayEffect(); } } //close egg if (_controller.GetButtonDown(VirtualKey.LEFT)) { if (_playerNum > 0) { _playerNum--; PlayerEggsAnim[_playerNum].SetTrigger("Close"); MenuBipAudio.PlayEffect(); } } //Smash eggs and show Levels if (_controller.GetButtonDown(VirtualKey.SUBMIT) && _playerNum > 0) { EggsAnimator.SetTrigger("Smash"); for (int i = 0; i < CowLevels.Length; i++) { CowLevels[i].SetBool("IsDancing", false); CowLevels[i].SetTrigger("Appear"); CowLevels[i].transform.parent.gameObject.SetActive(true); } CowLevels[0].SetBool("IsDancing", true); SelectPlayerLabel.Fade(1, 0, 0, 0.1f); SelectLevelLabel.Fade(0, 1, 0.5f, 0.3f); MenuConfirmAudio.PlayEffect(); _currentScreen = Screen.LEVEL_SELECTION; } } else if (_currentScreen == Screen.LEVEL_SELECTION) { //Go to Start and close eggs if (_controller.GetButtonDown(VirtualKey.BACK)) { MenuBackAudio.PlayEffect(); EggsAnimator.SetTrigger("UnSmash"); SelectLevelLabel.Fade(1, 0, 0, 0.1f); SelectPlayerLabel.Fade(0, 1, 0.5f, 0.3f); for (int i = 0; i < CowLevels.Length; i++) { CowLevels[i].SetTrigger("Disappear"); } for (int i = 0; i < _playerNum; i++) { PlayerEggsAnim[i].SetTrigger("Crack"); } _levelNum = 0; _currentScreen = Screen.PLAYER_SELECTION; } //make next cowlevel dance if (_controller.GetButtonDown(VirtualKey.RIGHT)) { if (_levelNum + 1 < CowLevels.Length) { CowLevels[_levelNum].SetBool("IsDancing", false); CowLevels[_levelNum + 1].SetBool("IsDancing", true); MenuChangeLevelsAudio.PlayEffect(); _levelNum++; } } ///make previous cowlevel dance if (_controller.GetButtonDown(VirtualKey.LEFT)) { if (_levelNum > 0) { CowLevels[_levelNum].SetBool("IsDancing", false); CowLevels[_levelNum - 1].SetBool("IsDancing", true); MenuChangeLevelsAudio.PlayEffect(); _levelNum--; } } //go to mode selection if (_controller.GetButtonDown(VirtualKey.SUBMIT)) { for (int i = 0; i < CowLevels.Length; i++) { if (i != _levelNum) { CowLevels[i].SetTrigger("Disappear"); } } //Go to start _teamFadeText.Fade(); _allvsFadeText.Stop(1, 0.15f); TeamModeText.color = Color.yellow; AllVsAllModeText.color = Color.white; ModePage.Fade(0, 1, 0.5f, 0.3f); SelectLevelLabel.Fade(1, 0, 0, 0.2f); _isTeamMode = true; MenuConfirmAudio.PlayEffect(); _currentScreen = Screen.MODE_SELECTION; } } else if (_currentScreen == Screen.MODE_SELECTION) { //highlight team mode text if (_controller.GetButtonDown(VirtualKey.LEFT) && !_teamFadeText.IsFading) { _teamFadeText.Fade(); _allvsFadeText.Stop(1, 0.15f); TeamModeText.color = Color.yellow; AllVsAllModeText.color = Color.white; _isTeamMode = true; MenuBipAudio.PlayEffect(); } //highlight Credits text if (_controller.GetButtonDown(VirtualKey.RIGHT) && !_creditsFadeText.IsFading) { _allvsFadeText.Fade(); _teamFadeText.Stop(1, 0.15f); AllVsAllModeText.color = Color.yellow; TeamModeText.color = Color.white; _isTeamMode = false; MenuBipAudio.PlayEffect(); } if (_controller.GetButtonDown(VirtualKey.BACK)) { MenuBackAudio.PlayEffect(); ModePage.Fade(1, 0, 0, 0.2f); SelectLevelLabel.Fade(0, 1, 0.3f, 0.2f); for (int i = 0; i < CowLevels.Length; i++) { if (i != _levelNum) { CowLevels[i].SetTrigger("Appear"); } } _currentScreen = Screen.LEVEL_SELECTION; } if (_controller.GetButtonDown(VirtualKey.SUBMIT)) { BlackScreen.Fade(); MenuConfirmAudio.PlayEffect(); Invoke("BeginGame", 0.6f); _currentScreen = Screen.BLACKSCREEN; } } }
void Update() { //waiting that a controller is assigned, or the player is ready to play if (_controller == null || confirmed) { return; } //Player confirms his selection. Set it as ready if (_controller.GetButtonDown(VirtualKey.START)) { confirmed = true; //lock the hero and let the player use it while all the other players are ready _currentHero.SetPlayer(_player); OnPlayerReady(_player); return; } //moving selection up/down: browse buttons if (_controller.GetButtonDown(VirtualKey.UP) && _btnSelected > 0) { _btnSelected--; UpdateBtnSelection(); } else if (_controller.GetButtonDown(VirtualKey.DOWN) && _btnSelected < _buttons.Length - 1) { _btnSelected++; UpdateBtnSelection(); } //change selection else if (_controller.GetButtonDown(VirtualKey.LEFT)) { //hero changed if (_btnSelected == 0 && _iHero > 0) { _iHero--; AssemblePlayer(); } //ranged weapon changed else if (_btnSelected == 1 && _iRange > 0) { _iRange--; AssemblePlayer(); } //melee weapon changed /*else if(_btnSelected == 2 && _iMelee > 0){ * _iMelee--; * AssemblePlayer(); * }*/ else if (_btnSelected == 2 && _iTeam > 0) { _iTeam--; AssemblePlayer(); } } //change selection. Same thing as before, but else if (_controller.GetButtonDown(VirtualKey.RIGHT)) { if (_btnSelected == 0 && _iHero < Resource.Heroes.Length - 1) { _iHero++; AssemblePlayer(); } else if (_btnSelected == 1 && _iRange < Resource.RangedWepons.Length - 1) { _iRange++; AssemblePlayer(); } /*else if(_btnSelected == 2 && _iMelee < Resource.MeleeWepons.Length-1){ * _iMelee++; * AssemblePlayer(); * }*/ else if (_btnSelected == 2 && _iTeam < Team.Teams.Length - 1) { _iTeam++; AssemblePlayer(); } } }
void Update() { bool startPressed = DadaInput.GetButtonDown(VirtualKey.START); //Pause game if (!_isPaused && startPressed && !_gameEnded) { Time.timeScale = 0.0000001f; _isPaused = true; _pauseScreen.gameObject.SetActive(true); } else if (_isPaused) { //resume game if (startPressed) { Time.timeScale = 1; _isPaused = false; _pauseScreen.gameObject.SetActive(false); } else if (DadaInput.GetButtonDown(VirtualKey.SELECT)) { Time.timeScale = 1; _isPaused = false; DadaGame.Reset(); Application.LoadLevel("MainScreen"); } } //game ended. if (_gameEnded) { if (_controller1.GetButtonDown(VirtualKey.LEFT) && !_restartYes.IsFading) { _restartYes.Fade(); _restartNo.Stop(1, 0); _restartYes.GetComponent <Text>().color = _teams[_winningTeam].TeamColor; _restartNo.GetComponent <Text>().color = Color.white; } if (_controller1.GetButtonDown(VirtualKey.RIGHT) && !_restartNo.IsFading) { _restartNo.Fade(); _restartYes.Stop(1, 0); _restartNo.GetComponent <Text>().color = _teams[_winningTeam].TeamColor; _restartYes.GetComponent <Text>().color = Color.white; } if (_controller1.GetButtonDown(VirtualKey.SUBMIT)) { if (_restartYes.IsFading) { Application.LoadLevel(Application.loadedLevelName); } else { Application.LoadLevel("MainScreen"); } } } }
protected virtual void ProcessMovement() { AbstractController _controller = _hero.PlayerInstance.Controller; // Cache the horizontal input. float h = _hero.PlayerInstance.Controller.XAxis; //h = Mathf.Abs(h) < 0.25f ? 0 : h; h = JoystickDeadzone(h, 0.25f); // The Speed animator parameter is set to the absolute value of the horizontal input. //_anim.SetFloat("Speed", _grounded ? Mathf.Abs(h) : 0); // If the player is changing direction (h has a different sign to velocity.x) or hasn't reached _hero.MaxSpeed yet... if (h * _rigidbody.velocity.x < _hero.MaxSpeed) { // ... add a force to the player. _rigidbody.AddForce(transform.right * h * _hero.MoveForce, ForceMode2D.Force); } // The player is grounded if a linecast to the groundcheck position hits anything on the ground layer. _grounded = IsGrounded(); if (_controller.GetButtonDown(VirtualKey.JUMP)) { _jumpPressedLastTime = Time.time; } // Jump if the jump button has been pressed in last 0.1s and the character is on solid ground if (Time.time - _jumpPressedLastTime < 0.1f && _grounded) { //_jumpStartTime = Time.time; //_jumpStart = true; //_jump = true; if (_hero.JumpSound != null) { _hero.JumpSound.PlayEffect(); } _rigidbody.velocity = new Vector2(_rigidbody.velocity.x, _hero.JumpSpeed); } //if (_grounded) // _anim.SetBool("Slide", false); // If the player should jump... //if(_jumpStart) //{ // Set the Jump animator trigger parameter. //_anim.SetBool("Slide", false); //_anim.SetTrigger("Jump"); // Play a random jump audio clip. //if (JumpClips.Length > 0) // DadaAudio.PlayRandom(JumpClips); // if (_hero.JumpSound != null) // _hero.JumpSound.PlayEffect(); // Add a vertical force to the player. // _rigidbody.AddForce(transform.up * _hero.JumpForce); // _rigidbody.velocity = new Vector2(_rigidbody.velocity.x, _hero.JumpSpeed); // Make sure the player can't jump again until the jump conditions from Update are satisfied. // _jumpStart = false; //} // if (_jump) // { // _rigidbody.AddForce( transform.up * _hero.JumpForce * _hero.JumpAirModifier); // } /* * if (_walljump > 0 && !_grounded) * { * //_anim.SetBool("Slide", false); * //_anim.SetTrigger("Jump"); * * // Play a random jump audio clip. * //if (JumpClips.Length > 0) * // DadaAudio.PlayRandom(JumpClips); * if (_hero.JumpSound != null) * _hero.JumpSound.PlayEffect(); * * // Add a vertical force to the player. * if (_walljump == 1) * { * _rigidbody.velocity = Vector2.zero; * _rigidbody.AddForce(new Vector2(_hero.JumpForce, _hero.JumpForce)); * } * else * { * _rigidbody.velocity = Vector2.zero; * _rigidbody.AddForce(new Vector2(-_hero.JumpForce, _hero.JumpForce)); * } * _walljump = 0; * }*/ }