book_4_sparkGenerated
code_blocksInput

Description

The Pairs property in the CollisionRules class is a dictionary that defines the collision behavior between pairs of objects. Each entry in the dictionary maps a Pair to a Result, indicating what should happen when the specified pair of objects collide.

Usage

Use the Pairs property to specify custom collision rules between specific pairs of objects in your physics simulation. This property is particularly useful when you need to define unique collision behaviors that differ from the default rules.

Note that this property is marked with the JsonIgnore attribute, meaning it will not be serialized or deserialized when using JSON serialization. If you need to serialize the collision rules, use the SerializedPairs property instead.

Example

// Example of accessing and modifying the Pairs property
var collisionRules = new CollisionRules();

// Define a new pair and result
var pair = new CollisionRules.Pair("ObjectA", "ObjectB");
var result = CollisionRules.Result.Ignore;

// Add the pair and result to the Pairs dictionary
collisionRules.Pairs[pair] = result;

// Accessing a collision result for a specific pair
var collisionResult = collisionRules.Pairs[pair];

// Output the collision result
// Console.WriteLine(collisionResult); // Avoid using Console.WriteLine in s&box