2023-12-26 20:07:19 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Runtime.Remoting.Messaging;
|
|
|
|
using BITFALL.Feel;
|
|
|
|
using BITKit;
|
|
|
|
using BITKit.Entities;
|
|
|
|
using PaintIn3D;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BITFALL.Feel
|
|
|
|
{
|
|
|
|
public class EntityBloodDecal : EntityBehavior
|
|
|
|
{
|
|
|
|
[SerializeField] private P3dModel model;
|
|
|
|
[SerializeField] private P3dPaintableTexture texture;
|
|
|
|
|
|
|
|
[Inject] private IHealth _health;
|
|
|
|
private bool isDead;
|
|
|
|
public override void OnStart()
|
|
|
|
{
|
|
|
|
base.OnStart();
|
|
|
|
_health.OnDamageRelease += OnDamageRelease;
|
|
|
|
_health.OnSetAlive += OnSetAlive;
|
2024-01-27 04:09:57 +08:00
|
|
|
_health.OnDamageVoid += OnDamageVoid;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDamageVoid(DamageMessage obj)
|
|
|
|
{
|
|
|
|
if(_health.IsAlive) return;
|
|
|
|
OnDamageRelease(obj);
|
2023-12-26 20:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnSetAlive(bool obj)
|
|
|
|
{
|
|
|
|
if (obj)
|
|
|
|
{
|
|
|
|
texture.Clear();
|
|
|
|
}
|
|
|
|
// switch (obj)
|
|
|
|
// {
|
|
|
|
// case true when isDead:
|
|
|
|
// texture.Clear();
|
|
|
|
// break;
|
|
|
|
// case false:
|
|
|
|
// isDead = true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDamageRelease(DamageMessage obj)
|
|
|
|
{
|
|
|
|
if (obj.Hit is not EntityHitbox) return;
|
|
|
|
if (obj.RaycastHit.HasValue is false) return;
|
|
|
|
var raycastHit = obj.RaycastHit.Value;
|
|
|
|
//var rotation = Quaternion.LookRotation(raycastHit.normal) * Quaternion.Euler(0, 180, 0);
|
|
|
|
var rotation = Quaternion.LookRotation(
|
|
|
|
obj.Position - raycastHit.point
|
|
|
|
) * Quaternion.Euler(0, 180, 0);
|
|
|
|
|
|
|
|
BloodDecalService.Decal.TargetModel = model;
|
|
|
|
BloodDecalService.Decal.TargetTexture = texture;
|
|
|
|
BloodDecalService.Decal.HandleHitLine(
|
|
|
|
false,
|
|
|
|
0,
|
|
|
|
1.0f,
|
|
|
|
0,
|
|
|
|
raycastHit.point+raycastHit.normal*1,
|
|
|
|
raycastHit.point-raycastHit.normal*1,
|
|
|
|
rotation,true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|