Namespace: MDPackage.Modifiers
Damage a mesh by external forces or rigibodies - CPU based solution with multithreading support.
Read more here (Online documentation slide)
Properties
public bool ThreadUseMultithreading { get; set; }
public bool ThreadEditorThreadSupported { get; }
public bool ThreadIsDone { get; }
public int ThreadSleep { get; set; }
public bool AutoDetectRadiusSize { get; set; }
public float ImpactRadius { get; set; }
public float ImpactRadiusMultiplier { get; set; }
public float ImpactRadiusSoftness { get; set; }
public bool DetectForceImpact { get; set; }
public float ImpactForceAmount { get; set; }
public float ImpactForceMultiplier { get; set; }
public float ImpactForceDetectionLimit { get; set; }
public bool ContinuousDamage { get; set; }
public bool CollisionWithSpecificTag { get; set; }
public string CollideWithTag { get; set; }
Events
public event System.Action<Vector3> OnMeshDamaged;
public UnityEvent OnMeshDamagedUnityEvent;
Public Methods
public void MeshDamage_ModifyMesh(Vector3 worldSpacePoint, float radius, float force, Vector3 direction)
public void MeshDamage_RefreshMesh()
public void MeshDamage_BakeVertices()
public void MeshDamage_RestoreMesh(float restorationSpeed = 0.1f)
Examples
The following paragraphs contain Mesh Damage modifier component used in a practical example - damage specific mesh with raycast at runtime.
using UnityEngine;
using MDPackage.Modifiers;
[RequireComponent(typeof(MeshFilter))]
public class SampleScript : MonoBehaviour
{
[SerializeField] private Camera mainCam;
[Space]
[SerializeField] private float damageRadius = 0.25f;
[SerializeField] private float damageForce = 0.5f;
[SerializeField] private bool continuousEffect = true;
private MDM_MeshDamage damageable;
private void Start()
{
damageable = MD_ModifierBase.CreateModifier<MDM_MeshDamage>(gameObject, MD_ModifierBase.MeshReferenceType.CreateNewReference);
damageable.gameObject.AddComponent<MDPackage.MD_MeshColliderRefresher>();
}
private void Update()
{
if (!mainCam)
return;
if (Input.GetKey(KeyCode.R))
damageable.MeshDamage_RestoreMesh(4 * Time.deltaTime);
damageable.ContinuousDamage = continuousEffect;
if (Input.GetMouseButtonDown(0))
{
Ray r = mainCam.ScreenPointToRay(Input.mousePosition);
bool hit = Physics.Raycast(r, out RaycastHit h) && h.transform == damageable.transform;
if (hit)
damageable.MeshDamage_ModifyMesh(h.point, Mathf.Abs(damageRadius), -Mathf.Abs(damageForce), h.normal);
}
}
}