/// <summary> /// Removes a collision delegate from the physics body /// </summary> /// <param name="callback">The delegate to be removed</param> /// <param name="body">The body to remove the delegate from</param> internal void UnregisterCollisionCallback(Collision2D.OnCollision callback, PhysicsBody2D body) { // First check to see if the registry contains this key if (registery_CollisionCallbacks.ContainsKey(body)) { body.collisionCallbacks.Remove(callback); } }
/// <summary> /// Adds a collision delegate to the physics bodies list of callbacks /// This enables something using the delegate to be alerted when the body in question collides with something else /// </summary> /// <param name="callback">The delegate to be added</param> /// <param name="body">The body to add the delegate to</param> internal void RegisterCollisionCallback(Collision2D.OnCollision callback, PhysicsBody2D body) { // First check to see if the registry contains this key if (!registery_CollisionCallbacks.ContainsKey(body)) { // If the registry does not contain the body, add the body, and its list of callbacks registery_CollisionCallbacks.Add(body, body.collisionCallbacks); } // Add the new callback to the list body.collisionCallbacks.Add(callback); }
// TODO 3D overload of this (Collision3D.OnCollision callback, PhysicsBody3D body) public static void UnregisterCollisionCallback(Collision2D.OnCollision callback, PhysicsBody2D body) { switch (EngineType) { case EngineTypes.Physics2D: (engine as PhysicsEngine2D).UnregisterCollisionCallback(callback, body); break; case EngineTypes.Physics3D: throw new PhysicsExceptions.InvalidCollisionCallback("Cannot unregister a Collision2D.OnCollision callback from a PhysicsBody2D in a PhysicsEngine3D"); } }
public void UnregisterCollisionCallback(Collision2D.OnCollision callback) { PhysicsEngine.UnregisterCollisionCallback(callback, this); }