public IEnumerator RefusesInactiveComponent() { containingObject.AddComponent <TestScript>(); SerializableTypeComponentObservableList componentTypes = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); subject.ComponentTypes = componentTypes; componentTypes.Add(typeof(TestScript)); subject.enabled = false; Assert.IsFalse(container.Accepts(containingObject)); }
public IEnumerator NearestSurface() { Physics.autoSimulation = true; GameObject validSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject validSurface2 = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject searchOrigin = new GameObject("SearchOrigin"); validSurface.name = "validSurface"; validSurface2.name = "validSurface2"; UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); validSurface.AddComponent <RuleStub>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); validSurface2.AddComponent <RuleStub>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); subject.TargetValidity = new RuleContainer { Interface = anyComponentTypeRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; validSurface.transform.position = Vector3.forward * 5f; validSurface2.transform.position = Vector3.forward * 4.9f; GameObject nearestSurface = validSurface2; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsTrue(surfaceLocatedMock.Received); Assert.IsTrue(nearestSurface.transform == subject.surfaceData.Transform, "The returned surfaceData.Transform is not the nearest"); Object.DestroyImmediate(validSurface); Object.DestroyImmediate(validSurface2); Object.DestroyImmediate(searchOrigin); }
public IEnumerator CastPointsInvalidTarget() { UnityEventListenerMock castResultsChangedMock = new UnityEventListenerMock(); subject.ResultsChanged.AddListener(castResultsChangedMock.Listen); subject.Origin = subject.gameObject; validSurface.transform.position = Vector3.forward * 5f + Vector3.down * 4f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); yield return(null); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.MaximumLength = new Vector2(5f, 5f); subject.SegmentCount = 5; Physics.Simulate(Time.fixedDeltaTime); subject.Process(); Vector3[] expectedPoints = new Vector3[] { Vector3.zero, new Vector3(0f, -0.1f, 2.9f), new Vector3(0f, -1.4f, 4.4f), new Vector3(0f, -2.8f, 4.9f), new Vector3(0f, validSurface.transform.position.y + (validSurface.transform.localScale.y / 2f), validSurface.transform.position.z) }; for (int index = 0; index < subject.Points.Count; index++) { Assert.AreEqual(expectedPoints[index].ToString(), subject.Points[index].ToString(), "Index " + index); } Assert.AreEqual(validSurface.transform, subject.TargetHit.Value.transform); Assert.IsFalse(subject.IsTargetHitValid); Assert.IsTrue(castResultsChangedMock.Received); }
public IEnumerator AddInvalidCollisionDueToRule() { UnityEventListenerMock firstStartedMock = new UnityEventListenerMock(); UnityEventListenerMock countChangedMock = new UnityEventListenerMock(); UnityEventListenerMock contentsChangedMock = new UnityEventListenerMock(); UnityEventListenerMock allStoppedMock = new UnityEventListenerMock(); subject.FirstStarted.AddListener(firstStartedMock.Listen); subject.CountChanged.AddListener(countChangedMock.Listen); subject.ContentsChanged.AddListener(contentsChangedMock.Listen); subject.AllStopped.AddListener(allStoppedMock.Listen); GameObject oneContainer; CollisionNotifier.EventData oneData = CollisionNotifierHelper.GetEventData(out oneContainer); oneContainer.AddComponent<RuleStub>(); NegationRule negationRule = oneContainer.AddComponent<NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = oneContainer.AddComponent<AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent<SerializableTypeComponentObservableList>(); yield return null; anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.CollisionValidity = new RuleContainer { Interface = negationRule }; Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); subject.Add(oneData); Assert.AreEqual(0, subject.Elements.Count); Assert.IsFalse(firstStartedMock.Received); Assert.IsFalse(countChangedMock.Received); Assert.IsFalse(contentsChangedMock.Received); Assert.IsFalse(allStoppedMock.Received); Object.DestroyImmediate(oneContainer); }
public IEnumerator ValidSurfaceDueToEventualTargetValidity() { Physics.autoSimulation = true; GameObject invalidSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject validSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject searchOrigin = new GameObject("SearchOrigin"); UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); validSurface.transform.position = Vector3.forward * 10f; invalidSurface.transform.position = Vector3.forward * 5f; invalidSurface.AddComponent <RuleStub>(); NegationRule negationRule = invalidSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = invalidSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsTrue(surfaceLocatedMock.Received); Assert.AreEqual(validSurface.transform, subject.surfaceData.Transform); Object.DestroyImmediate(invalidSurface); Object.DestroyImmediate(validSurface); Object.DestroyImmediate(searchOrigin); }
public IEnumerator ConsumeExclusion() { UnityEventListenerMock consumedMock = new UnityEventListenerMock(); UnityEventListenerMock clearedMock = new UnityEventListenerMock(); subject.Consumed.AddListener(consumedMock.Listen); subject.Cleared.AddListener(clearedMock.Listen); GameObject publisherObject = new GameObject(); ActiveCollisionPublisher.PayloadData publisher = new ActiveCollisionPublisher.PayloadData(); publisher.PublisherContainer = publisherObject; publisherObject.AddComponent <RuleStub>(); NegationRule negationRule = containingObject.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = containingObject.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.PublisherValidity = new RuleContainer { Interface = negationRule }; Assert.IsFalse(consumedMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.PublisherSource); subject.Consume(publisher, null); Assert.IsFalse(consumedMock.Received); Assert.IsFalse(clearedMock.Received); Assert.IsNull(subject.PublisherSource); Object.DestroyImmediate(publisherObject); }
public IEnumerator AcceptsInactiveGameObject() { containingObject.AddComponent <TestScript>(); SerializableTypeComponentObservableList componentTypes = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); subject.ComponentTypes = componentTypes; componentTypes.Add(typeof(TestScript)); subject.AutoRejectStates = BaseRule.RejectRuleStates.RuleComponentIsDisabled; subject.gameObject.SetActive(false); Assert.IsTrue(container.Accepts(containingObject)); subject.enabled = false; Assert.IsFalse(container.Accepts(containingObject)); }
public IEnumerator MissingSurfaceDueToLocatorTermination() { Physics.autoSimulation = true; GameObject terminatingSurface = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject searchOrigin = new GameObject("SearchOrigin"); UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); terminatingSurface.transform.position = Vector3.forward * 5f; terminatingSurface.AddComponent <RuleStub>(); AnyComponentTypeRule anyComponentTypeRule = terminatingSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); subject.LocatorTermination = new RuleContainer { Interface = anyComponentTypeRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsFalse(surfaceLocatedMock.Received); Assert.IsNull(subject.surfaceData.Transform); Object.DestroyImmediate(terminatingSurface); Object.DestroyImmediate(searchOrigin); }
public IEnumerator CastPointsInvalidTarget() { UnityEventListenerMock castResultsChangedMock = new UnityEventListenerMock(); subject.ResultsChanged.AddListener(castResultsChangedMock.Listen); subject.Origin = subject.gameObject; validSurface.transform.position = Vector3.forward * 5f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); yield return(null); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.ManualOnEnable(); Physics.Simulate(Time.fixedDeltaTime); subject.Process(); Vector3 expectedStart = Vector3.zero; Vector3 expectedEnd = validSurface.transform.position - (Vector3.forward * (validSurface.transform.localScale.z / 2f)); Assert.AreEqual(expectedStart, subject.Points[0]); Assert.AreEqual(expectedEnd, subject.Points[1]); Assert.AreEqual(validSurface.transform, subject.TargetHit.Value.transform); Assert.IsFalse(subject.IsTargetHitValid); Assert.IsTrue(castResultsChangedMock.Received); }
public IEnumerator InvalidSurfaceDueToPolicy() { Physics.autoSimulation = true; UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock(); subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen); validSurface.transform.position = Vector3.forward * 5f; validSurface.AddComponent <RuleStub>(); NegationRule negationRule = validSurface.AddComponent <NegationRule>(); AnyComponentTypeRule anyComponentTypeRule = validSurface.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList rules = containingObject.AddComponent <SerializableTypeComponentObservableList>(); yield return(null); anyComponentTypeRule.ComponentTypes = rules; rules.Add(typeof(RuleStub)); negationRule.Rule = new RuleContainer { Interface = anyComponentTypeRule }; subject.TargetValidity = new RuleContainer { Interface = negationRule }; subject.SearchOrigin = searchOrigin; subject.SearchDirection = Vector3.forward; yield return(waitForFixedUpdate); subject.Locate(); yield return(waitForFixedUpdate); Assert.IsFalse(surfaceLocatedMock.Received); }
protected virtual void CreateComponent(OptionType selectedOption) { GameObject componentContainer = new GameObject(componentName); if (selectedObject != null && nestInSelectedObject) { componentContainer.transform.SetParent(selectedObject.transform); } GameObject listContainer = new GameObject("ListContainer"); listContainer.transform.SetParent(componentContainer.transform); switch (selectedOption) { case OptionType.AllRule: AllRule allRule = componentContainer.AddComponent <AllRule>(); RuleContainerObservableList allList = listContainer.AddComponent <RuleContainerObservableList>(); allRule.Rules = allList; break; case OptionType.AnyRule: AnyRule anyRule = componentContainer.AddComponent <AnyRule>(); RuleContainerObservableList anyList = listContainer.AddComponent <RuleContainerObservableList>(); anyRule.Rules = anyList; break; case OptionType.AnyBehaviourEnabledRule: AnyBehaviourEnabledRule behaviourRule = componentContainer.AddComponent <AnyBehaviourEnabledRule>(); SerializableTypeBehaviourObservableList behaviourList = listContainer.AddComponent <SerializableTypeBehaviourObservableList>(); behaviourRule.BehaviourTypes = behaviourList; break; case OptionType.AnyComponentTypeRule: AnyComponentTypeRule componentRule = componentContainer.AddComponent <AnyComponentTypeRule>(); SerializableTypeComponentObservableList componentList = listContainer.AddComponent <SerializableTypeComponentObservableList>(); componentRule.ComponentTypes = componentList; break; case OptionType.AnyTagRule: AnyTagRule tagRule = componentContainer.AddComponent <AnyTagRule>(); StringObservableList tagList = listContainer.AddComponent <StringObservableList>(); tagRule.Tags = tagList; break; case OptionType.BehaviourEnabledObserver: BehaviourEnabledObserver behaviourEnabledObserver = componentContainer.AddComponent <BehaviourEnabledObserver>(); BehaviourObservableList behaviourObservableList = listContainer.AddComponent <BehaviourObservableList>(); behaviourEnabledObserver.Behaviours = behaviourObservableList; break; case OptionType.ListContainsRule: ListContainsRule listRule = componentContainer.AddComponent <ListContainsRule>(); UnityObjectObservableList listList = listContainer.AddComponent <UnityObjectObservableList>(); listRule.Objects = listList; break; case OptionType.RulesMatcher: RulesMatcher matcherRule = componentContainer.AddComponent <RulesMatcher>(); RulesMatcherElementObservableList matcherList = listContainer.AddComponent <RulesMatcherElementObservableList>(); matcherRule.Elements = matcherList; break; case OptionType.ActionRegistrar: ActionRegistrar actionRegistrar = componentContainer.AddComponent <ActionRegistrar>(); ActionRegistrarSourceObservableList registrarList = listContainer.AddComponent <ActionRegistrarSourceObservableList>(); GameObjectObservableList limitsList = listContainer.AddComponent <GameObjectObservableList>(); actionRegistrar.Sources = registrarList; actionRegistrar.SourceLimits = limitsList; break; case OptionType.AllAction: AllAction allAction = componentContainer.AddComponent <AllAction>(); ActionObservableList allActionList = listContainer.AddComponent <ActionObservableList>(); allAction.Actions = allActionList; break; case OptionType.AnyAction: AnyAction anyAction = componentContainer.AddComponent <AnyAction>(); ActionObservableList anyActionList = listContainer.AddComponent <ActionObservableList>(); anyAction.Actions = anyActionList; break; case OptionType.GameObjectsAssociationActivator: GameObjectsAssociationActivator gameObjectsAssociationActivator = componentContainer.AddComponent <GameObjectsAssociationActivator>(); GameObjectsAssociationObservableList gameObjectsAssociationList = listContainer.AddComponent <GameObjectsAssociationObservableList>(); gameObjectsAssociationActivator.Associations = gameObjectsAssociationList; break; case OptionType.GameObjectRelations: GameObjectRelations gameObjectRelations = componentContainer.AddComponent <GameObjectRelations>(); GameObjectRelationObservableList gameObjectsRelationsList = listContainer.AddComponent <GameObjectRelationObservableList>(); gameObjectRelations.Relations = gameObjectsRelationsList; break; case OptionType.GameObjectStateSwitcher: GameObjectStateSwitcher gameObjectStateSwitcher = componentContainer.AddComponent <GameObjectStateSwitcher>(); GameObjectObservableList gameObjectsList = listContainer.AddComponent <GameObjectObservableList>(); gameObjectStateSwitcher.Targets = gameObjectsList; break; case OptionType.PlatformDeviceAssociation: PlatformDeviceAssociation platformDeviceAssociation = componentContainer.AddComponent <PlatformDeviceAssociation>(); GameObjectObservableList platformGameObjectsList = listContainer.AddComponent <GameObjectObservableList>(); platformDeviceAssociation.GameObjects = platformGameObjectsList; break; case OptionType.HapticProcessor: HapticProcessor hapticProcessor = componentContainer.AddComponent <HapticProcessor>(); HapticProcessObservableList hapticList = listContainer.AddComponent <HapticProcessObservableList>(); hapticProcessor.HapticProcesses = hapticList; break; case OptionType.MeshStateModifier: MeshStateModifier meshStateModifier = componentContainer.AddComponent <MeshStateModifier>(); GameObjectMultiRelationObservableList gameObjectMultiRelationList = listContainer.AddComponent <GameObjectMultiRelationObservableList>(); meshStateModifier.MeshCollections = gameObjectMultiRelationList; break; case OptionType.MomentProcessor: MomentProcessor momentProcessor = componentContainer.AddComponent <MomentProcessor>(); MomentProcessObservableList momentProcessorList = listContainer.AddComponent <MomentProcessObservableList>(); momentProcessor.Processes = momentProcessorList; break; case OptionType.CompositeProcess: CompositeProcess compositeProcessor = componentContainer.AddComponent <CompositeProcess>(); MomentProcessObservableList compositeProcessorList = listContainer.AddComponent <MomentProcessObservableList>(); compositeProcessor.Processes = compositeProcessorList; break; case OptionType.VelocityTrackerProcessor: VelocityTrackerProcessor velocityTrackerProcessor = componentContainer.AddComponent <VelocityTrackerProcessor>(); VelocityTrackerObservableList velocityTrackerList = listContainer.AddComponent <VelocityTrackerObservableList>(); velocityTrackerProcessor.VelocityTrackers = velocityTrackerList; break; case OptionType.FloatAdder: FloatAdder floatAdder = componentContainer.AddComponent <FloatAdder>(); FloatObservableList floatList = listContainer.AddComponent <FloatObservableList>(); floatAdder.Collection = floatList; break; case OptionType.FloatMaxFinder: FloatMaxFinder floatMaxFinder = componentContainer.AddComponent <FloatMaxFinder>(); FloatObservableList floatMaxFinderList = listContainer.AddComponent <FloatObservableList>(); floatMaxFinder.Collection = floatMaxFinderList; break; case OptionType.FloatMeanFinder: FloatMeanFinder floatMeanFinder = componentContainer.AddComponent <FloatMeanFinder>(); FloatObservableList floatMeanFinderList = listContainer.AddComponent <FloatObservableList>(); floatMeanFinder.Collection = floatMeanFinderList; break; case OptionType.FloatMedianFinder: FloatMedianFinder floatMedianFinder = componentContainer.AddComponent <FloatMedianFinder>(); FloatObservableList floatMedianFinderList = listContainer.AddComponent <FloatObservableList>(); floatMedianFinder.Collection = floatMedianFinderList; break; case OptionType.FloatMinFinder: FloatMinFinder floatMinFinder = componentContainer.AddComponent <FloatMinFinder>(); FloatObservableList floatMinFinderList = listContainer.AddComponent <FloatObservableList>(); floatMinFinder.Collection = floatMinFinderList; break; case OptionType.FloatModeFinder: FloatModeFinder floatModeFinder = componentContainer.AddComponent <FloatModeFinder>(); FloatObservableList floatModeFinderList = listContainer.AddComponent <FloatObservableList>(); floatModeFinder.Collection = floatModeFinderList; break; case OptionType.FloatMultiplier: FloatMultiplier floatMultiplier = componentContainer.AddComponent <FloatMultiplier>(); FloatObservableList floatMultiplierList = listContainer.AddComponent <FloatObservableList>(); floatMultiplier.Collection = floatMultiplierList; break; case OptionType.FloatRangeFinder: FloatRangeFinder floatRangeFinder = componentContainer.AddComponent <FloatRangeFinder>(); FloatObservableList floatRangeFinderList = listContainer.AddComponent <FloatObservableList>(); floatRangeFinder.Collection = floatRangeFinderList; break; case OptionType.Vector2Multiplier: Vector2Multiplier vector2Multiplier = componentContainer.AddComponent <Vector2Multiplier>(); Vector2ObservableList vector2MultiplierList = listContainer.AddComponent <Vector2ObservableList>(); vector2Multiplier.Collection = vector2MultiplierList; break; case OptionType.Vector3Multiplier: Vector3Multiplier vector3Multiplier = componentContainer.AddComponent <Vector3Multiplier>(); Vector3ObservableList vector3MultiplierList = listContainer.AddComponent <Vector3ObservableList>(); vector3Multiplier.Collection = vector3MultiplierList; break; case OptionType.Vector3Subtractor: Vector3Subtractor vector3Subtractor = componentContainer.AddComponent <Vector3Subtractor>(); Vector3ObservableList vector3SubtractorList = listContainer.AddComponent <Vector3ObservableList>(); vector3Subtractor.Collection = vector3SubtractorList; break; } }