public void GetPrimaryBody_WhenFirstParentPhysicsBodyIsDisabled_ReturnsFirstEnabledAncestor( [Values( #if LEGACY_PHYSICS typeof(LegacyRigidBody), #endif typeof(PhysicsBodyAuthoring) )] Type rootBodyType, [Values( #if LEGACY_PHYSICS typeof(LegacyRigidBody), #endif typeof(PhysicsBodyAuthoring) )] Type parentBodyType ) { CreateHierarchy(new[] { rootBodyType }, new[] { parentBodyType }, new[] { typeof(PhysicsBodyAuthoring) }); // if root is PhysicsBodyAuthoring, test assumes it is enabled; Rigidbody is Component and cannot be disabled Assume.That(Root.GetComponent <PhysicsBodyAuthoring>()?.enabled ?? true, Is.True); Child.GetComponent <PhysicsBodyAuthoring>().enabled = false; var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Parent)); }
public void GetPrimaryBody_WhenHierarchyContainsNoBodies_ReturnsTopMostShape( [Values( #if LEGACY_PHYSICS typeof(LegacyBox), #endif typeof(PhysicsShapeAuthoring) )] Type rootShapeType, [Values( #if LEGACY_PHYSICS typeof(LegacyBox), #endif typeof(PhysicsShapeAuthoring) )] Type parentShapeType, [Values( #if LEGACY_PHYSICS typeof(LegacyBox), #endif typeof(PhysicsShapeAuthoring) )] Type childShapeType ) { CreateHierarchy(new[] { rootShapeType }, new[] { parentShapeType }, new[] { childShapeType }); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Root)); }
public void GetPrimaryBody_WhenHierarchyContainsNoBodies_IsStaticOptimized_ReturnsStaticOptimizeEntity( [Values(typeof(UnityEngine.BoxCollider), typeof(PhysicsShapeAuthoring))] Type childShapeType ) { CreateHierarchy(new[] { typeof(StaticOptimizeEntity) }, Array.Empty <Type>(), new[] { childShapeType }); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Root)); }
public static MessageType GetHierarchyStatusMessage(IReadOnlyList <UnityObject> targets, out string statusMessage) { statusMessage = string.Empty; if (targets.Count == 0) { return(MessageType.None); } var numChildTargets = 0; foreach (Component c in targets) { // hierarchy roots and leaf shapes do not emit a message if ( c == null || c.transform.parent == null || PhysicsShapeExtensions.GetPrimaryBody(c.gameObject) != c.gameObject ) { continue; } var targetType = c.GetType(); // only bodies (both explicit and implicit static bodies) will emit a message if ( targetType == typeof(PhysicsBodyAuthoring) #if LEGACY_PHYSICS || targetType == typeof(LegacyRigidBody) #endif || c.GetComponent <PhysicsBodyAuthoring>() == null #if LEGACY_PHYSICS && c.GetComponent <LegacyRigidBody>() == null #endif ) { ++numChildTargets; } } switch (numChildTargets) { case 0: return(MessageType.None); case 1: statusMessage = L10n.Tr("Target will be un-parented during the conversion process in order to take part in physics simulation."); return(MessageType.Warning); default: statusMessage = L10n.Tr("One or more targets will be un-parented during the conversion process in order to take part in physics simulation."); return(MessageType.Warning); } }
public void GetPrimaryBody_WhenHierarchyContainsBody_AndIsStaticOptimized_ReturnsBody( [Values(typeof(Rigidbody), typeof(PhysicsBodyAuthoring))] Type parentBodyType, [Values(typeof(UnityEngine.BoxCollider), typeof(PhysicsShapeAuthoring))] Type childShapeType ) { CreateHierarchy(new[] { typeof(StaticOptimizeEntity) }, new[] { parentBodyType }, new[] { childShapeType }); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Parent)); }
public void GetPrimaryBody_WhenHierarchyContainsMultipleBodies_ReturnsFirstParent( [Values(typeof(Rigidbody), typeof(PhysicsBodyAuthoring))] Type rootBodyType, [Values(typeof(Rigidbody), typeof(PhysicsBodyAuthoring))] Type parentBodyType ) { CreateHierarchy(new[] { rootBodyType }, new[] { parentBodyType }, Array.Empty <Type>()); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Parent)); }
public void GetHierarchyStatusMessage_WhenChild_AndChildIsPrimaryBody_MessageNotNullOrEmpty( [Values(typeof(PhysicsBodyAuthoring), typeof(PhysicsShapeAuthoring), typeof(PxBox), typeof(PxCapsule), typeof(PxMesh), typeof(PxSphere), typeof(Rigidbody))] Type childComponentType ) { CreateHierarchy(Array.Empty <Type>(), Array.Empty <Type>(), new[] { childComponentType }); Assume.That(PhysicsShapeExtensions.GetPrimaryBody(Child), Is.EqualTo(Child)); StatusMessageUtility.GetHierarchyStatusMessage(new[] { Child.GetComponent(childComponentType) }, out var msg); Assert.That(msg, Is.Not.Null.Or.Empty); }
public void GetPrimaryBody_WhenHierarchyContainsNoBodies_ReturnsTopMostShape( [Values(typeof(UnityEngine.BoxCollider), typeof(PhysicsShapeAuthoring))] Type rootShapeType, [Values(typeof(UnityEngine.BoxCollider), typeof(PhysicsShapeAuthoring))] Type parentShapeType, [Values(typeof(UnityEngine.BoxCollider), typeof(PhysicsShapeAuthoring))] Type childShapeType ) { CreateHierarchy(new[] { rootShapeType }, new[] { parentShapeType }, new[] { childShapeType }); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Root)); }
public void GetPrimaryBody_WhenHierarchyContainsNoBodies_IsStaticOptimized_ReturnsStaticOptimizeEntity( [Values( #if LEGACY_PHYSICS typeof(LegacyBox), #endif typeof(PhysicsShapeAuthoring) )] Type childShapeType ) { CreateHierarchy(new[] { typeof(StaticOptimizeEntity) }, Array.Empty <Type>(), new[] { childShapeType }); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Root)); }
public void GetPrimaryBody_WhenHierarchyContainsBody_AndIsStaticOptimized_ReturnsBody( [Values( #if LEGACY_PHYSICS typeof(LegacyRigidBody), #endif typeof(PhysicsBodyAuthoring) )] Type parentBodyType, [Values( #if LEGACY_PHYSICS typeof(LegacyBox), #endif typeof(PhysicsShapeAuthoring) )] Type childShapeType ) { CreateHierarchy(new[] { typeof(StaticOptimizeEntity) }, new[] { parentBodyType }, new[] { childShapeType }); var primaryBody = PhysicsShapeExtensions.GetPrimaryBody(Child); Assert.That(primaryBody, Is.EqualTo(Parent)); }
public void GetHierarchyStatusMessage_WhenChild_AndChildHasBodyAndShape_QueryingBodyReturnsMessage( [Values( #if LEGACY_PHYSICS typeof(LegacyRigidBody), #endif typeof(PhysicsBodyAuthoring) )] Type bodyType, [Values( #if LEGACY_PHYSICS typeof(LegacyBox), typeof(LegacyCapsule), typeof(LegacyMesh), typeof(LegacySphere), #endif typeof(PhysicsShapeAuthoring) )] Type shapeType ) { CreateHierarchy(Array.Empty <Type>(), Array.Empty <Type>(), new[] { bodyType, shapeType }); Assume.That(PhysicsShapeExtensions.GetPrimaryBody(Child), Is.EqualTo(Child)); StatusMessageUtility.GetHierarchyStatusMessage(new[] { Child.GetComponent(bodyType) }, out var msg); Assert.That(msg, Is.Not.Null.Or.Empty); }
public void GetHierarchyStatusMessage_WhenChild_AndChildIsNotPrimaryBody_MessageNullOrEmpty( [Values( #if LEGACY_PHYSICS typeof(LegacyRigidBody), typeof(LegacyBox), #endif typeof(PhysicsBodyAuthoring), typeof(PhysicsShapeAuthoring) )] Type parentComponentType, [Values( #if LEGACY_PHYSICS typeof(LegacyBox), typeof(LegacyCapsule), typeof(LegacyMesh), typeof(LegacySphere), #endif typeof(PhysicsShapeAuthoring) )] Type childComponentType ) { CreateHierarchy(Array.Empty <Type>(), new[] { parentComponentType }, new[] { childComponentType }); Assume.That(PhysicsShapeExtensions.GetPrimaryBody(Child), Is.EqualTo(Parent)); StatusMessageUtility.GetHierarchyStatusMessage(new[] { Child.GetComponent(childComponentType) }, out var msg); Assert.That(msg, Is.Null.Or.Empty); }
public int GetMaxAxis_ReturnsLargestAxis(float3 v) { return(PhysicsShapeExtensions.GetMaxAxis(v)); }
public int GetDeviantAxis_ReturnsTheMostDifferentAxis(float3 v) { return(PhysicsShapeExtensions.GetDeviantAxis(v)); }