protected void TryToAdd(Collidable a, Collidable b, Material materialA, Material materialB)
{
CollisionRule rule;
if ((rule = CollisionRules.collisionRuleCalculator(a.collisionRules, b.collisionRules)) < CollisionRule.NoNarrowPhasePair)
{
//Clamp the rule to the parent's rule. Always use the more restrictive option.
//Don't have to test for NoNarrowPhasePair rule on the parent's rule because then the parent wouldn't exist!
if (rule < CollisionRule)
{
rule = CollisionRule;
}
var pair = new CollidablePair(a, b);
if (!subPairs.ContainsKey(pair))
{
CollidablePairHandler newPair = NarrowPhaseHelper.GetPairHandler(ref pair, rule);
if (newPair != null)
{
newPair.UpdateMaterialProperties(materialA, materialB); //Override the materials, if necessary.
newPair.Parent = this;
subPairs.Add(pair, newPair);
}
}
containedPairs.Add(pair);
}
}