/// <summary> /// Sets the category bit mask of a body. Allows using an enum instead of uint bit values. /// </summary> /// <param name="body">Body.</param> /// <param name="bits">Bits.</param> /// <param name="overwrite">If set to <c>true</c> overwrite.</param> public static void SetCategoryBitMask(this SKPhysicsBody body, CONTACT_BITS bits, bool overwrite = true) { if(body == null) { return; } if (overwrite) { // Overwrite all bits. body.CategoryBitMask = (uint)bits; } else{ // Add missing bits. body.CategoryBitMask |= (uint)bits; } }
/// <summary> /// Determines if a body belongs to a specific category. /// </summary> /// <returns><c>true</c> body is of the category; otherwise, <c>false</c>.</returns> /// <param name="body">Body.</param> /// <param name="bits">Bits.</param> /// <param name="matchAll">If set to <c>true</c> match all bits.</param> public static bool IsOfCategory(this SKPhysicsBody body, CONTACT_BITS bits, bool matchAll = false) { if(body == null) { return false; } if(matchAll) { // All bits must match return (body.CategoryBitMask & (uint)bits) == (uint)bits; } else { // Any bit must match return (body.CategoryBitMask & (uint)bits) > 0; } }