Пример #1
0
        public IEnumerator ValidSurfaceDueToPolicy()
        {
            Physics.autoSimulation = true;
            UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock();

            subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen);

            validSurface.transform.position = Vector3.forward * 5f;
            validSurface.AddComponent <RuleStub>();
            AnyComponentTypeRule anyComponentTypeRule     = validSurface.AddComponent <AnyComponentTypeRule>();
            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;

            yield return(waitForFixedUpdate);

            subject.Locate();
            yield return(waitForFixedUpdate);

            Assert.IsTrue(surfaceLocatedMock.Received);
        }
Пример #2
0
        public IEnumerator RefusesDifferent()
        {
            containingObject.AddComponent <Light>();
            SerializableTypeComponentObservableList componentTypes = containingObject.AddComponent <SerializableTypeComponentObservableList>();

            yield return(null);

            subject.ComponentTypes = componentTypes;
            componentTypes.Add(typeof(TestScript));

            Assert.IsFalse(container.Accepts(containingObject));
        }
Пример #3
0
        public IEnumerator AcceptsMatch()
        {
            containingObject.AddComponent <TestScript>();
            SerializableTypeComponentObservableList componentTypes = containingObject.AddComponent <SerializableTypeComponentObservableList>();

            yield return(null);

            subject.ComponentTypes = componentTypes;
            componentTypes.Add(typeof(TestScript));

            Assert.IsTrue(container.Accepts(containingObject));
        }
        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);
        }
Пример #5
0
        public IEnumerator RefusesInactiveGameObject()
        {
            containingObject.AddComponent <TestScript>();
            SerializableTypeComponentObservableList componentTypes = containingObject.AddComponent <SerializableTypeComponentObservableList>();

            yield return(null);

            subject.ComponentTypes = componentTypes;
            componentTypes.Add(typeof(TestScript));

            subject.gameObject.SetActive(false);
            Assert.IsFalse(container.Accepts(containingObject));
        }
Пример #6
0
        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);
        }
Пример #8
0
        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);
        }
Пример #10
0
        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));
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }