BITFALL/Assets/Artists/Scripts/Feel/PlayerGraphics.cs

99 lines
2.2 KiB
C#
Raw Normal View History

2023-10-20 19:31:12 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Entities;
2024-02-21 01:40:53 +08:00
using BITFALL.Player.Movement;
2024-03-29 00:58:24 +08:00
using BITFALL.Props;
2023-10-20 19:31:12 +08:00
using BITKit;
using BITKit.Entities;
using BITKit.Entities.Player;
using BITKit.Events;
using UnityEngine;
2024-02-21 01:40:53 +08:00
using UnityEngine.Rendering;
2023-10-20 19:31:12 +08:00
namespace BITFALL.Feel
{
public class PlayerGraphics : MonoBehaviour
{
[SerializeReference, SubclassSelector] private IPlayerService playerService;
[SerializeField] private UnityEvent _unityEvent;
[SerializeField] private UnityEvent playerDeathEvent;
2024-02-21 01:40:53 +08:00
[SerializeField] private Volume vignettingVolume;
2024-03-29 00:58:24 +08:00
[SerializeField] private Volume playerFlashVolume;
2024-02-21 01:40:53 +08:00
[SerializeField] private AnimationCurve vignettingCurve;
2023-10-20 19:31:12 +08:00
[Inject]
private IKnockdown _knockdown;
[Inject]
private IHealth _health;
2024-02-21 01:40:53 +08:00
[Inject]
private IPlayerMovement _playerMovement;
2024-03-29 00:58:24 +08:00
[Inject] private IStunObject _stunObject;
2023-10-20 19:31:12 +08:00
private void Start()
{
playerService.OnPlayerInitialized += OnPlayerInitialized;
playerService.OnPlayerDisposed += OnPlayerDisposed;
2024-02-21 01:40:53 +08:00
vignettingVolume.weight = 0;
2024-03-29 00:58:24 +08:00
playerFlashVolume.weight = 0;
2024-02-21 01:40:53 +08:00
}
private void Update()
{
if (_playerMovement is not null)
vignettingVolume.weight = vignettingCurve.Evaluate(_playerMovement.Stamina*0.01f);
2023-10-20 19:31:12 +08:00
}
private void OnPlayerDisposed(Entity obj)
{
_unityEvent.Invoke(false);
playerDeathEvent.Invoke(false);
2024-02-21 01:40:53 +08:00
_playerMovement = null;
vignettingVolume.weight = 0;
2023-10-20 19:31:12 +08:00
}
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;
2024-03-29 00:58:24 +08:00
_stunObject.OnWeightChanged += OnWeightChanged;
playerFlashVolume.weight = 0;
}
private void OnWeightChanged(float obj)
{
playerFlashVolume.weight= obj;
2023-10-20 19:31:12 +08:00
}
private void OnSetAlive(bool obj)
{
_unityEvent.Invoke(false);
playerDeathEvent.Invoke(!obj);
}
private void OnRevive()
{
_unityEvent.Invoke(false);
}
private void OnKnockdown()
{
_unityEvent.Invoke(true);
}
}
}