80 lines
2.1 KiB
C#
80 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.MyPhysics
|
|
{
|
|
public class EntityGoreComponent : MonoBehaviour,IDamagable
|
|
{
|
|
[SerializeReference, SubclassSelector] private IReference myTag;
|
|
[SerializeField] private new Rigidbody rigidbody;
|
|
[SerializeField] private new Collider collider;
|
|
[SerializeField] private Renderer[] renderers;
|
|
[SerializeField] private EntityGoreComponent childComponent;
|
|
[SerializeField] private ConfigurableJoint joint;
|
|
[SerializeField] private int health;
|
|
[SerializeField] private int maxHealth;
|
|
public string Tag =>myTag is not null? myTag.Value : string.Empty;
|
|
public IHealth Health => null;
|
|
public IUnityEntity UnityEntity => null;
|
|
public Rigidbody Rigidbody => rigidbody;
|
|
public Collider Collider => collider;
|
|
public void GiveDamage(DamageMessage message)
|
|
{
|
|
health -= message.Damage;
|
|
if(health>=0)return;
|
|
|
|
Break(this);
|
|
return;
|
|
|
|
void Break(EntityGoreComponent component)
|
|
{
|
|
if (component.childComponent)
|
|
{
|
|
Break(component.childComponent);
|
|
}
|
|
component.rigidbody.isKinematic = true;
|
|
component.Collider.enabled = false;
|
|
foreach (var x in component.renderers)
|
|
{
|
|
x.enabled = false;
|
|
}
|
|
component.joint.xMotion = ConfigurableJointMotion.Free;
|
|
component.joint.yMotion = ConfigurableJointMotion.Free;
|
|
component.joint.zMotion = ConfigurableJointMotion.Free;
|
|
component.joint.angularXMotion = ConfigurableJointMotion.Free;
|
|
component.joint.angularYMotion = ConfigurableJointMotion.Free;
|
|
component.joint.angularZMotion = ConfigurableJointMotion.Free;
|
|
}
|
|
}
|
|
private void OnValidate()
|
|
{
|
|
var isDirty = false;
|
|
if (!rigidbody)
|
|
{
|
|
rigidbody = GetComponent<Rigidbody>();
|
|
isDirty = true;
|
|
}
|
|
if (!collider)
|
|
{
|
|
collider = GetComponent<Collider>();
|
|
isDirty = true;
|
|
}
|
|
if (!joint)
|
|
{
|
|
joint = GetComponent<ConfigurableJoint>();
|
|
isDirty = true;
|
|
}
|
|
if (isDirty)
|
|
{
|
|
#if UNITY_EDITOR
|
|
UnityEditor.EditorUtility.SetDirty(this);
|
|
#endif
|
|
}
|
|
}
|
|
}
|
|
|
|
} |