Danro/Assets/Scripts/Animations/PlayerAnimationEvents.cs
Danil Iarosh 7f14981d8b added dialogue system
- Добавил систему диалогов
- Создал классы Sequencer.cs и SequenceAction.cs для воссоздания последовательности действий
- Добавил иеханику последовательности действий в Message.cs и MessageController.cs
2025-12-10 08:32:15 +03:00

87 lines
3.1 KiB
C#

using UnityEngine;
using RR.Common.Audio;
using RR.Game2D.Core.Managers;
using RR.Game2D.Behaviour;
using RR.Game2D.Behaviour.ScriptableObjects;
using UnityEngine.VFX;
namespace RR.Game2D.Animations
{
public class PlayerAnimationEvents : MonoBehaviour, CreatureAnimationEvents
{
[SerializeField] private VisualEffectAsset deathVFX;
[SerializeField] private Vector3 deathVFXOffset = Vector3.zero;
private SFXAsset _stepSounds;
private SFXAsset _hurtSounds;
private SFXAsset _jumpSounds;
private Rigidbody2D _rb;
private Vector3 _vfxSpawnPoint;
private void OnEnable() => LevelPlayerSFX.Instance.SFXChanged += UpdateSFX;
private void OnDisable() => LevelPlayerSFX.Instance.SFXChanged -= UpdateSFX;
private void Awake()
{
PlayerController controller = GetComponent<PlayerController>();
UpdateSFX();
_rb = GetComponent<Rigidbody2D>();
Collider2D col = GetComponent<Collider2D>();
// Учитываем поворот объекта при вычислении смещения
Vector3 rotatedOffset = transform.rotation * deathVFXOffset;
_vfxSpawnPoint = (col ? col.bounds.center : transform.position) + rotatedOffset;
}
public void UpdateSFX()
{
PlayerController controller = GetComponent<PlayerController>();
_stepSounds = controller.stepSounds;
_hurtSounds = controller.hurtSounds;
_jumpSounds = controller.jumpSounds;
}
public void OnDeath() {}
public void OnDeathBegin()
{
if (_hurtSounds && _hurtSounds.soundEffects.Length > 0)
GameManager.Instance.Audio.PlayRandomSfxAt(_hurtSounds.soundEffects, transform.position);
PlayerFireScript fireScript = GetComponent<PlayerFireScript>();
if (fireScript.enableFire) fireScript.enableFire = false;
}
public void OnDeathEnd()
{
Collider2D col = GetComponent<Collider2D>();
Vector3 rotatedOffset = transform.rotation * deathVFXOffset;
_vfxSpawnPoint = col ? col.bounds.center : transform.position + rotatedOffset;
if (deathVFX) VFXPool.Instance.Spawn(deathVFX, _vfxSpawnPoint, 1f);
gameObject.layer = LayerMask.NameToLayer("Default");
_rb.constraints = RigidbodyConstraints2D.FreezeRotation;
PlayerFireScript fireScript = GetComponent<PlayerFireScript>();
if (!fireScript.enableFire) fireScript.enableFire = true;
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);
}
}
}