using UnityEngine; using RR.Common.Audio; using RR.Game2D.Core.Managers; using RR.Game2D.Behaviour; using RR.Game2D.Behaviour.ScriptableObjects; namespace RR.Game2D.Animations { public class PlayerAnimationEvents : MonoBehaviour, CreatureAnimationEvents { private SFXAsset _stepSounds; private SFXAsset _hurtSounds; private SFXAsset _jumpSounds; private Rigidbody2D _rb; private void OnEnable() => LevelPlayerSFX.Instance.SFXChanged += UpdateSFX; private void OnDisable() => LevelPlayerSFX.Instance.SFXChanged -= UpdateSFX; private void Awake() { PlayerController controller = GetComponent(); UpdateSFX(); _rb = GetComponent(); } public void UpdateSFX() { PlayerController controller = GetComponent(); _stepSounds = controller.stepSounds; _hurtSounds = controller.hurtSounds; _jumpSounds = controller.jumpSounds; } public void OnDeath() { throw new System.NotImplementedException(); } public void OnDeathBegin() { if (_hurtSounds && _hurtSounds.soundEffects.Length > 0) GameManager.Instance.Audio.PlayRandomSfxAt(_hurtSounds.soundEffects, transform.position); } public void OnDeathEnd() { Animator animator = GetComponent(); // animator.ResetTrigger("Death"); gameObject.layer = LayerMask.NameToLayer("Default"); _rb.constraints = RigidbodyConstraints2D.FreezeRotation; GameManager.Instance.RespawnPlayer(); } public void OnStep() { if (_stepSounds && _stepSounds.soundEffects.Length > 0) GameManager.Instance.Audio.PlayRandomSfxAt(_stepSounds.soundEffects, transform.position); } public void OnJump() { if (_jumpSounds && _jumpSounds.soundEffects.Length > 0) GameManager.Instance.Audio.PlayRandomSfxAt(_jumpSounds.soundEffects, transform.position); } } }