|
6 | 6 |
|
7 | 7 | namespace Unity.Netcode.Components |
8 | 8 | { |
| 9 | + /// <summary> |
| 10 | + /// Information a <see cref="Rigidbody"/> returns to <see cref="RigidbodyContactEventManager"/> via <see cref="IContactEventHandlerWithInfo.GetContactEventHandlerInfo"/> <br /> |
| 11 | + /// if the <see cref="Rigidbody"/> registers itself with <see cref="IContactEventHandlerWithInfo"/> as opposed to <see cref="IContactEventHandler"/>. |
| 12 | + /// </summary> |
9 | 13 | public struct ContactEventHandlerInfo |
10 | 14 | { |
| 15 | + /// <summary> |
| 16 | + /// When set to true, the <see cref="RigidbodyContactEventManager"/> will include non-Rigidbody based contact events.<br /> |
| 17 | + /// When the <see cref="RigidbodyContactEventManager"/> invokes the <see cref="IContactEventHandler.ContactEvent"/> it will return null in place <br /> |
| 18 | + /// of the collidingBody parameter if the contact event occurred with a collider that is not registered with the <see cref="RigidbodyContactEventManager"/>. |
| 19 | + /// </summary> |
11 | 20 | public bool ProvideNonRigidBodyContactEvents; |
| 21 | + /// <summary> |
| 22 | + /// When set to true, the <see cref="RigidbodyContactEventManager"/> will prioritize invoking <see cref="IContactEventHandler.ContactEvent(ulong, Vector3, Rigidbody, Vector3, bool, Vector3)"/> <br /></br> |
| 23 | + /// if it is the 2nd colliding body in the contact pair being processed. With distributed authority, setting this value to true when a <see cref="NetworkObject"/> is owned by the local client <br /> |
| 24 | + /// will assure <see cref="IContactEventHandler.ContactEvent(ulong, Vector3, Rigidbody, Vector3, bool, Vector3)"/> is only invoked on the authoritative side. |
| 25 | + /// </summary> |
12 | 26 | public bool HasContactEventPriority; |
13 | 27 | } |
14 | 28 |
|
| 29 | + /// <summary> |
| 30 | + /// Default implementation required to register a <see cref="Rigidbody"/> with a <see cref="RigidbodyContactEventManager"/> instance. |
| 31 | + /// </summary> |
| 32 | + /// <remarks> |
| 33 | + /// Recommended to implement this method on a <see cref="NetworkBehaviour"/> component |
| 34 | + /// </remarks> |
15 | 35 | public interface IContactEventHandler |
16 | 36 | { |
| 37 | + /// <summary> |
| 38 | + /// Should return a <see cref="Rigidbody"/>. |
| 39 | + /// </summary> |
17 | 40 | Rigidbody GetRigidbody(); |
18 | 41 |
|
| 42 | + /// <summary> |
| 43 | + /// Invoked by the <see cref="RigidbodyContactEventManager"/> instance. |
| 44 | + /// </summary> |
| 45 | + /// <param name="eventId">A unique contact event identifier.</param> |
| 46 | + /// <param name="averagedCollisionNormal">The average normal of the collision between two colliders.</param> |
| 47 | + /// <param name="collidingBody">If not null, this will be a registered <see cref="Rigidbody"/> that was part of the collision contact event.</param> |
| 48 | + /// <param name="contactPoint">The world space location of the contact event.</param> |
| 49 | + /// <param name="hasCollisionStay">Will be set if this is a collision stay contact event (i.e. it is not the first contact event and continually has contact)</param> |
| 50 | + /// <param name="averagedCollisionStayNormal">The average normal of the collision stay contact over time.</param> |
19 | 51 | void ContactEvent(ulong eventId, Vector3 averagedCollisionNormal, Rigidbody collidingBody, Vector3 contactPoint, bool hasCollisionStay = false, Vector3 averagedCollisionStayNormal = default); |
20 | 52 | } |
21 | 53 |
|
| 54 | + /// <summary> |
| 55 | + /// This is an extended version of <see cref="IContactEventHandler"/> and can be used to register a <see cref="Rigidbody"/> with a <see cref="RigidbodyContactEventManager"/> instance. <br /> |
| 56 | + /// This provides additional <see cref="ContactEventHandlerInfo"/> information to the <see cref="RigidbodyContactEventManager"/> for each set of contact events it is processing. |
| 57 | + /// </summary> |
22 | 58 | public interface IContactEventHandlerWithInfo : IContactEventHandler |
23 | 59 | { |
| 60 | + /// <summary> |
| 61 | + /// Invoked by <see cref="RigidbodyContactEventManager"/> for each set of contact events it is processing (prior to processing). |
| 62 | + /// </summary> |
| 63 | + /// <returns><see cref="ContactEventHandlerInfo"/></returns> |
24 | 64 | ContactEventHandlerInfo GetContactEventHandlerInfo(); |
25 | 65 | } |
26 | 66 |
|
| 67 | + /// <summary> |
| 68 | + /// Add this component to an in-scene placed GameObject to provide faster collision event processing between <see cref="Rigidbody"/> instances and optionally static colliders. |
| 69 | + /// <see cref="IContactEventHandler"/> <br /> |
| 70 | + /// <see cref="IContactEventHandlerWithInfo"/> <br /> |
| 71 | + /// <see cref="ContactEventHandlerInfo"/> <br /> |
| 72 | + /// </summary> |
27 | 73 | [AddComponentMenu("Netcode/Rigidbody Contact Event Manager")] |
28 | 74 | public class RigidbodyContactEventManager : MonoBehaviour |
29 | 75 | { |
@@ -61,6 +107,15 @@ private void OnEnable() |
61 | 107 | Instance = this; |
62 | 108 | } |
63 | 109 |
|
| 110 | + /// <summary> |
| 111 | + /// Any <see cref="IContactEventHandler"/> implementation can register a <see cref="Rigidbody"/> to be handled by this <see cref="RigidbodyContactEventManager"/> instance. |
| 112 | + /// </summary> |
| 113 | + /// <remarks> |
| 114 | + /// You should enable <see cref="Collider.providesContacts"/> for each <see cref="Collider"/> associated with the <see cref="Rigidbody"/> being registered.<br/> |
| 115 | + /// You can enable this during run time or within the editor's inspector view. |
| 116 | + /// </remarks> |
| 117 | + /// <param name="contactEventHandler"><see cref="IContactEventHandler"/> or <see cref="IContactEventHandlerWithInfo"/></param> |
| 118 | + /// <param name="register">true to register and false to remove from being registered</param> |
64 | 119 | public void RegisterHandler(IContactEventHandler contactEventHandler, bool register = true) |
65 | 120 | { |
66 | 121 | var rigidbody = contactEventHandler.GetRigidbody(); |
|
0 commit comments