public override void OnSelect(PlayerInput input) { base.OnSelect(input); // I'm calling Start here because it is not being // automatically called before OnSelect is called // for some reason. Start(); laserLine.enabled = false; hitFlare.SetActive(false); muzzle.SetActive(false); }
private void Update() { if (settings == null) return; // IMPORTANT: // This script should be set to be the first to update // in script execution order to clean the cache before // evryone else try to get an updated version of the // input. // Clear cache. cachedPlayerInput = null; UpdateSources(); UpdateVibration(); }
public virtual void OnSelect(PlayerInput input) { gameObject.SetActive(true); }
private void SelectSecondaryWeapon(PlayerInput input, SecondaryWeapon weapon, bool silent = false) { if (weapon == selectedSecondaryWeapon) { //Debug.LogFormat("Secondary weapon '{0}' already selected.", weapon); return; } if (selectedLeftSecondaryWeapon != null) selectedLeftSecondaryWeapon.OnDeselect(); if (selectedRightSecondaryWeapon != null) selectedRightSecondaryWeapon.OnDeselect(); switch (weapon) { case SecondaryWeapon.None: selectedLeftSecondaryWeapon = null; selectedRightSecondaryWeapon = null; leftWeaponIndicatorIcon.enabled = false; leftWeaponIndicatorNoneIcon.enabled = true; leftWeaponIndicatorInfiniteIcon.enabled = false; leftWeaponIndicatorAmmoLabel.enabled = false; TurnLockingSystemOff(); break; case SecondaryWeapon.UnguidedMissiles: selectedLeftSecondaryWeapon = leftUnguidedMissileCannon; selectedRightSecondaryWeapon = rightUnguidedMissileCannon; leftWeaponIndicatorIcon.sprite = unguidedMissilesIcon; leftWeaponIndicatorIcon.enabled = true; leftWeaponIndicatorNoneIcon.enabled = false; leftWeaponIndicatorInfiniteIcon.enabled = false; leftWeaponIndicatorAmmoLabel.enabled = true; TurnLockingSystemOff(); break; case SecondaryWeapon.GuidedMissiles: selectedLeftSecondaryWeapon = leftGuidedMissileCannon; selectedRightSecondaryWeapon = rightGuidedMissileCannon; leftWeaponIndicatorIcon.sprite = guidedMissilesIcon; leftWeaponIndicatorIcon.enabled = true; leftWeaponIndicatorNoneIcon.enabled = false; leftWeaponIndicatorInfiniteIcon.enabled = false; leftWeaponIndicatorAmmoLabel.enabled = true; TurnLockingSystemOn(); break; default: throw new Exception("Unexpected PrimaryWeapon."); } if (selectedLeftSecondaryWeapon != null) selectedLeftSecondaryWeapon.OnSelect(input); if (selectedRightSecondaryWeapon != null) selectedRightSecondaryWeapon.OnSelect(input); selectedSecondaryWeapon = weapon; }
private void SelectPrimaryWeapon(PlayerInput input, PrimaryWeapon weapon, bool silent = false) { if (weapon == selectedPrimaryWeapon) { //Debug.LogFormat("Primary weapon '{0}' already selected.", weapon); return; } if (selectedLeftPrimaryWeapon != null) selectedLeftPrimaryWeapon.OnDeselect(); if (selectedRightPrimaryWeapon != null) selectedRightPrimaryWeapon.OnDeselect(); switch (weapon) { case PrimaryWeapon.None: selectedLeftPrimaryWeapon = null; selectedRightPrimaryWeapon = null; rightWeaponIndicatorIcon.enabled = false; rightWeaponIndicatorNoneIcon.enabled = true; rightWeaponIndicatorInfiniteIcon.enabled = false; rightWeaponIndicatorAmmoLabel.enabled = false; break; case PrimaryWeapon.PlasmaGun: selectedLeftPrimaryWeapon = leftPlasmaGun; selectedRightPrimaryWeapon = rightPlasmaGun; rightWeaponIndicatorIcon.sprite = plasmaGunIcon; rightWeaponIndicatorIcon.enabled = true; rightWeaponIndicatorNoneIcon.enabled = false; rightWeaponIndicatorInfiniteIcon.enabled = true; rightWeaponIndicatorAmmoLabel.enabled = false; break; case PrimaryWeapon.Laser: selectedLeftPrimaryWeapon = leftLaser; selectedRightPrimaryWeapon = rightLaser; rightWeaponIndicatorIcon.sprite = laserIcon; rightWeaponIndicatorIcon.enabled = true; rightWeaponIndicatorNoneIcon.enabled = false; rightWeaponIndicatorInfiniteIcon.enabled = false; rightWeaponIndicatorAmmoLabel.enabled = true; break; default: throw new Exception("Unexpected PrimaryWeapon."); } if (selectedLeftPrimaryWeapon != null) selectedLeftPrimaryWeapon.OnSelect(input); if (selectedRightPrimaryWeapon != null) selectedRightPrimaryWeapon.OnSelect(input); selectedPrimaryWeapon = weapon; }
private void UpdateWeaponChange(PlayerInput input) { if (input.CiclePrimaryWeapon) { if (selectedPrimaryWeapon == PrimaryWeapon.PlasmaGun) { SelectPrimaryWeapon(input, PrimaryWeapon.Laser); } else if (selectedPrimaryWeapon == PrimaryWeapon.Laser) { SelectPrimaryWeapon(input, PrimaryWeapon.PlasmaGun); } } if (input.CicleSecondaryWeapon) { if (selectedSecondaryWeapon == SecondaryWeapon.UnguidedMissiles) { SelectSecondaryWeapon(input, SecondaryWeapon.GuidedMissiles); } else if (selectedSecondaryWeapon == SecondaryWeapon.GuidedMissiles) { SelectSecondaryWeapon(input, SecondaryWeapon.UnguidedMissiles); } } if (input.SelectPlasmaGun) { SelectPrimaryWeapon(input, PrimaryWeapon.PlasmaGun); } if (input.SelectLaser) { SelectPrimaryWeapon(input, PrimaryWeapon.Laser); } if (input.SelectUnguidedMissiles) { SelectSecondaryWeapon(input, SecondaryWeapon.UnguidedMissiles); } if (input.SelectGuidedMissiles) { SelectSecondaryWeapon(input, SecondaryWeapon.GuidedMissiles); } }
private void UpdateShoot(PlayerInput input) { var primaryWeaponFired = false; var secondaryWeaponFired = false; if (primaryWeaponInfiniteAmmo[selectedPrimaryWeapon] || primaryWeaponAmmo[selectedPrimaryWeapon] > 0) { if (selectedLeftPrimaryWeapon != null) { if (input.ShootPrimaryWeapon) if (selectedLeftPrimaryWeapon.Shoot()) primaryWeaponFired = true; } if (selectedRightPrimaryWeapon != null) { if (input.ShootPrimaryWeapon) if (selectedRightPrimaryWeapon.Shoot()) primaryWeaponFired = true; } } else if (input.ShootPrimaryWeapon) { PlayDepletedSoundFx(); } if (secondaryWeaponInfiniteAmmo[selectedSecondaryWeapon] || secondaryWeaponAmmo[selectedSecondaryWeapon] > 0) { if (selectedLeftSecondaryWeapon != null) { if (input.ShootSecondaryWeapon) if (selectedLeftSecondaryWeapon.Shoot()) secondaryWeaponFired = true; } if (selectedRightSecondaryWeapon != null) { if (input.ShootSecondaryWeapon) if (selectedRightSecondaryWeapon.Shoot()) secondaryWeaponFired = true; } } else if (input.ShootSecondaryWeapon) { PlayDepletedSoundFx(); } if (primaryWeaponFired && !primaryWeaponInfiniteAmmo[selectedPrimaryWeapon]) { primaryWeaponAmmo[selectedPrimaryWeapon]--; } if (secondaryWeaponFired && !secondaryWeaponInfiniteAmmo[selectedSecondaryWeapon]) { secondaryWeaponAmmo[selectedSecondaryWeapon]--; } }
private void UpdateMovement(PlayerInput input) { rb.AddRelativeForce(0, 0, input.MoveForward * moveForward); rb.AddRelativeForce(input.StrafeRight * strafeForce, 0, 0); rb.AddRelativeForce(0, input.StrafeUp * strafeForce, 0); rb.AddRelativeTorque(0, 0, input.RollLeft * barrelRollTorque); rb.AddRelativeTorque(0, input.YawDelta * yawTorque, 0); rb.AddRelativeTorque(input.PitchDelta * pitchTorque, 0, 0); if(input.MoveForward != 0) { if (!isMovingForward) AudioManager.instance.Play(AudioBank.SFX_SHIP_FORBACK, this.gameObject); //AudioManager.instance.Play(AudioBank.SFX_SHIP_BACK, this.gameObject); isMovingForward = true; forwardValue += input.MoveForward; forwardValue = Mathf.Clamp(forwardValue, 1, 3); AkSoundEngine.SetRTPCValue("Pitch", forwardValue); } if (input.StrafeRight != 0) { if (!isMovingSideways) AudioManager.instance.Play(AudioBank.SFX_SHIP_SIDE, this.gameObject); //AudioManager.instance.Play(AudioBank.SFX_SHIP_BURST, this.gameObject); //AudioManager.instance.Play(AudioBank.SFX_SHIP_SWAY, this.gameObject); isMovingSideways = true; sideValue += input.StrafeRight; sideValue = Mathf.Clamp(sideValue, 1, 3); AkSoundEngine.SetRTPCValue("Roll", sideValue); } if (input.StrafeUp != 0) { if (!isMovingUp) AudioManager.instance.Play(AudioBank.SFX_SHIP_UPDOWN, this.gameObject); isMovingUp = true; upValue += input.StrafeUp; upValue = Mathf.Clamp(upValue, 1, 3); AkSoundEngine.SetRTPCValue("Yaw", upValue); } if (input.StrafeRight == 0 && input.MoveForward == 0 && input.StrafeUp == 0 && (isMovingForward || isMovingSideways || isMovingUp)) { isMovingSideways = false; isMovingForward = false; isMovingUp = false; forwardValue = 50; sideValue = 50; upValue = 50; AudioManager.instance.Play(AudioBank.SFX_SHIP_STOP, this.gameObject); } }
private void UpdateHeadlights(PlayerInput input) { if (input.ToggleHeadlights) { //SoundFxsManager.instance.PlayOneShot(SoundFx.UIBlip01, transform.position); headlights.gameObject.SetActive(!headlights.gameObject.activeSelf); UIUtils.BlinkUI(headlightsIndicator); } if (headlights.gameObject.activeSelf) { headlightsIndicator.color = indicatorEnabledColor; headlightsIndicator.text = "HEADLIGHTS ENABLED"; } else { headlightsIndicator.color = indicatorDisabledColor; headlightsIndicator.text = "HEADLIGHTS DISABLED"; } }
private void UpdateAutoLevel(PlayerInput input) { if (input.ToggleAutoLevel) { //SoundFxsManager.instance.PlayOneShot(SoundFx.UIBlip01, transform.position); leveler.gameObject.SetActive(!leveler.gameObject.activeSelf); UIUtils.BlinkUI(autoLevelIndicator); } if (leveler.gameObject.activeSelf) { autoLevelIndicator.color = indicatorEnabledColor; autoLevelIndicator.text = "AUTO LEVEL ENABLED"; } else { autoLevelIndicator.color = indicatorDisabledColor; autoLevelIndicator.text = "AUTO LEVEL DISABLED"; } }
public PlayerInput GetPlayerInput() { if (cachedPlayerInput == null) { cachedPlayerInput = new PlayerInput(); cachedPlayerInput.MoveForward = settings.MoveForwardMap.GetAxisCurrentState(settings.mouseSensibility, settings.joystickSensibility, settings.invertVerticalAxis); cachedPlayerInput.StrafeRight = settings.StrafeRightMap.GetAxisCurrentState(settings.mouseSensibility, settings.joystickSensibility, settings.invertVerticalAxis); cachedPlayerInput.RollLeft = settings.RollLeftMap.GetAxisCurrentState(settings.mouseSensibility, settings.joystickSensibility, settings.invertVerticalAxis); cachedPlayerInput.StrafeUp = settings.StrafeUpMap.GetAxisCurrentState(settings.mouseSensibility, settings.joystickSensibility, settings.invertVerticalAxis); cachedPlayerInput.YawDelta = settings.YawDeltaMap.GetAxisCurrentState(settings.mouseSensibility, settings.joystickSensibility, settings.invertVerticalAxis); cachedPlayerInput.PitchDelta = settings.PitchDeltaMap.GetAxisCurrentState(settings.mouseSensibility, settings.joystickSensibility, settings.invertVerticalAxis); cachedPlayerInput.SelectPlasmaGun = settings.SelectPlasmaGunMap.GetButtonCurrentState(); cachedPlayerInput.SelectLaser = settings.SelectLaserMap.GetButtonCurrentState(); cachedPlayerInput.SelectUnguidedMissiles = settings.SelectUnguidedMissilesMap.GetButtonCurrentState(); cachedPlayerInput.SelectGuidedMissiles = settings.SelectGuidedMissilesMap.GetButtonCurrentState(); cachedPlayerInput.CiclePrimaryWeapon = settings.CiclePrimaryWeaponMap.GetButtonCurrentState(); cachedPlayerInput.CicleSecondaryWeapon = settings.CicleSecondaryWeaponMap.GetButtonCurrentState(); cachedPlayerInput.ShootPrimaryWeapon = settings.ShootPrimaryWeaponMap.GetButtonCurrentState(); cachedPlayerInput.ShootSecondaryWeapon = settings.ShootSecondaryWeaponMap.GetButtonCurrentState(); cachedPlayerInput.ToggleAutoLevel = settings.ToggleAutoLevelMap.GetButtonCurrentState(); cachedPlayerInput.ToggleHeadlights = settings.ToggleHeadlightsMap.GetButtonCurrentState(); cachedPlayerInput.Pause = settings.PauseMap.GetButtonCurrentState(); } return cachedPlayerInput; }