using System; using System.Collections; using System.Collections.Generic; using BITFALL.Entities; using BITFALL.Player.Movement; using BITFALL.Props; using BITKit; using BITKit.Entities; using BITKit.Entities.Player; using BITKit.Events; using UnityEngine; using UnityEngine.Rendering; namespace BITFALL.Feel { public class PlayerGraphics : MonoBehaviour { [SerializeReference, SubclassSelector] private IPlayerService playerService; [SerializeField] private UnityEvent _unityEvent; [SerializeField] private UnityEvent playerDeathEvent; [SerializeField] private Volume vignettingVolume; [SerializeField] private Volume playerFlashVolume; [SerializeField] private AnimationCurve vignettingCurve; [Inject] private IKnockdown _knockdown; [Inject] private IHealth _health; [Inject] private IPlayerMovement _playerMovement; [Inject] private IStunObject _stunObject; private void Start() { playerService.OnPlayerInitialized += OnPlayerInitialized; playerService.OnPlayerDisposed += OnPlayerDisposed; vignettingVolume.weight = 0; playerFlashVolume.weight = 0; } private void Update() { if (_playerMovement is not null) vignettingVolume.weight = vignettingCurve.Evaluate(_playerMovement.Stamina*0.01f); } private void OnPlayerDisposed(Entity obj) { _unityEvent.Invoke(false); playerDeathEvent.Invoke(false); _playerMovement = null; vignettingVolume.weight = 0; } private void OnDestroy() { playerService.OnPlayerInitialized -= OnPlayerInitialized; playerService.OnPlayerDisposed -= OnPlayerDisposed; } private void OnPlayerInitialized(Entity obj) { obj.Inject(this); _knockdown.OnKnockdown += OnKnockdown; _knockdown.OnRevive += OnRevive; _health.OnSetAlive += OnSetAlive; _stunObject.OnWeightChanged += OnWeightChanged; playerFlashVolume.weight = 0; } private void OnWeightChanged(float obj) { playerFlashVolume.weight= obj; } private void OnSetAlive(bool obj) { _unityEvent.Invoke(false); playerDeathEvent.Invoke(!obj); } private void OnRevive() { _unityEvent.Invoke(false); } private void OnKnockdown() { _unityEvent.Invoke(true); } } }