Rasagar/Library/PackageCache/com.unity.visualeffectgraph/Runtime/Utilities/EventBinding/Implementation/VFXRigidBodyCollisionEventBinder.cs

33 lines
991 B
C#
Raw Normal View History

2024-08-26 13:07:20 -07:00
#if VFX_HAS_PHYSICS
using System.Collections;
using System.Collections.Generic;
namespace UnityEngine.VFX.Utility
{
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(Collider))]
class VFXRigidBodyCollisionEventBinder : VFXEventBinderBase
{
private ExposedProperty positionParameter = "position";
private ExposedProperty directionParameter = "velocity";
protected override void SetEventAttribute(object[] parameters)
{
ContactPoint contact = (ContactPoint)parameters[0];
eventAttribute.SetVector3(positionParameter, contact.point);
eventAttribute.SetVector3(directionParameter, contact.normal);
}
void OnCollisionEnter(Collision collision)
{
// Debug-draw all contact points and normals
foreach (ContactPoint contact in collision.contacts)
{
SendEventToVisualEffect(contact);
}
}
}
}
#endif