69 lines
1.4 KiB
C#
69 lines
1.4 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITFALL.Entities;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.Entities.Player;
|
|
using BITKit.Events;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Feel
|
|
{
|
|
public class PlayerGraphics : MonoBehaviour
|
|
{
|
|
[SerializeReference, SubclassSelector] private IPlayerService playerService;
|
|
|
|
[SerializeField] private UnityEvent _unityEvent;
|
|
[SerializeField] private UnityEvent playerDeathEvent;
|
|
[Inject]
|
|
private IKnockdown _knockdown;
|
|
[Inject]
|
|
private IHealth _health;
|
|
private void Start()
|
|
{
|
|
playerService.OnPlayerInitialized += OnPlayerInitialized;
|
|
playerService.OnPlayerDisposed += OnPlayerDisposed;
|
|
}
|
|
|
|
private void OnPlayerDisposed(Entity obj)
|
|
{
|
|
_unityEvent.Invoke(false);
|
|
playerDeathEvent.Invoke(false);
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
private void OnSetAlive(bool obj)
|
|
{
|
|
_unityEvent.Invoke(false);
|
|
playerDeathEvent.Invoke(!obj);
|
|
}
|
|
|
|
private void OnRevive()
|
|
{
|
|
_unityEvent.Invoke(false);
|
|
}
|
|
|
|
private void OnKnockdown()
|
|
{
|
|
_unityEvent.Invoke(true);
|
|
}
|
|
}
|
|
|
|
}
|