public NewtonBodyCollision(NewtonBody body) { List <ColliderShapePair> colliderList = new List <ColliderShapePair>(); TraverseColliders(body.gameObject, colliderList, body.gameObject, body); if (body.m_isScene) { m_collidersArray = new ColliderShapePair[colliderList.Count + 1]; NewtonSceneCollider sceneCollider = body.gameObject.AddComponent <NewtonSceneCollider>(); dNewtonCollisionScene sceneShape = (dNewtonCollisionScene)sceneCollider.Create(body.m_world); m_collidersArray[0].m_shape = sceneShape; m_collidersArray[0].m_collider = sceneCollider; int index = 1; sceneShape.BeginAddRemoveCollision(); foreach (ColliderShapePair pair in colliderList) { m_collidersArray[index] = pair; sceneShape.AddCollision(pair.m_shape); index++; } sceneShape.EndAddRemoveCollision(); } else if (colliderList.Count == 0) { m_collidersArray = new ColliderShapePair[1]; NewtonCollider collider = body.gameObject.AddComponent <NewtonNullCollider>(); m_collidersArray[0].m_collider = collider; m_collidersArray[0].m_shape = collider.Create(body.m_world); } else if (colliderList.Count == 1) { m_collidersArray = new ColliderShapePair[1]; m_collidersArray[0] = colliderList[0]; } else { m_collidersArray = new ColliderShapePair[colliderList.Count + 1]; NewtonCompoundCollider compoundCollider = body.gameObject.AddComponent <NewtonCompoundCollider>(); dNewtonCollisionCompound compoundShape = (dNewtonCollisionCompound)compoundCollider.Create(body.m_world); m_collidersArray[0].m_shape = compoundShape; m_collidersArray[0].m_collider = compoundCollider; int index = 1; compoundShape.BeginAddRemoveCollision(); foreach (ColliderShapePair pair in colliderList) { m_collidersArray[index] = pair; compoundShape.AddCollision(pair.m_shape); index++; } compoundShape.EndAddRemoveCollision(); } }
public NewtonBodyCollision(NewtonBody body) { if (body.m_world.GetWorld() == null) { throw new NullReferenceException("Native world instance is null. The World component was probably destroyed"); } List <ColliderShapePair> colliderList = new List <ColliderShapePair>(); TraverseColliders(body.gameObject, colliderList, body.gameObject, body); if (body.m_isScene) { m_collidersArray = new ColliderShapePair[colliderList.Count + 1]; NewtonSceneCollider sceneCollider = body.gameObject.AddComponent <NewtonSceneCollider>(); dNewtonCollisionScene sceneShape = (dNewtonCollisionScene)sceneCollider.Create(body.m_world); m_collidersArray[0].m_shape = sceneShape; m_collidersArray[0].m_collider = sceneCollider; int index = 1; sceneShape.BeginAddRemoveCollision(); foreach (ColliderShapePair pair in colliderList) { m_collidersArray[index] = pair; sceneShape.AddCollision(pair.m_shape); index++; } sceneShape.EndAddRemoveCollision(); } else if (colliderList.Count == 0) { m_collidersArray = new ColliderShapePair[1]; NewtonCollider collider = body.gameObject.AddComponent <NewtonNullCollider>(); m_collidersArray[0].m_collider = collider; m_collidersArray[0].m_shape = collider.Create(body.m_world); } else if (colliderList.Count == 1) { m_collidersArray = new ColliderShapePair[1]; m_collidersArray[0] = colliderList[0]; } else { m_collidersArray = new ColliderShapePair[colliderList.Count + 1]; NewtonCompoundCollider compoundCollider = body.gameObject.AddComponent <NewtonCompoundCollider>(); dNewtonCollisionCompound compoundShape = (dNewtonCollisionCompound)compoundCollider.Create(body.m_world); m_collidersArray[0].m_shape = compoundShape; m_collidersArray[0].m_collider = compoundCollider; int index = 1; compoundShape.BeginAddRemoveCollision(); foreach (ColliderShapePair pair in colliderList) { m_collidersArray[index] = pair; compoundShape.AddCollision(pair.m_shape); index++; } compoundShape.EndAddRemoveCollision(); } }