Exemplo n.º 1
0
        public IEnumerator InvalidSurfaceDueToTargetPointValidity()
        {
            Physics.autoSimulation = true;

            GameObject invalidSurface = GameObject.CreatePrimitive(PrimitiveType.Cube);
            GameObject searchOrigin   = new GameObject("SearchOrigin");

            UnityEventListenerMock surfaceLocatedMock = new UnityEventListenerMock();

            subject.SurfaceLocated.AddListener(surfaceLocatedMock.Listen);

            invalidSurface.transform.position = Vector3.forward * 5f;
            invalidSurface.AddComponent <RuleStub>();
            NegationRule    negationRule = invalidSurface.AddComponent <NegationRule>();
            Vector3RuleStub vector3Point = invalidSurface.AddComponent <Vector3RuleStub>();

            vector3Point.toMatch = invalidSurface.transform.position - (Vector3.forward * invalidSurface.transform.localScale.z * 0.5f);
            yield return(null);

            negationRule.Rule = new RuleContainer
            {
                Interface = vector3Point
            };
            subject.TargetPointValidity = new RuleContainer
            {
                Interface = negationRule
            };

            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(invalidSurface);
            Object.DestroyImmediate(searchOrigin);
        }
        public IEnumerator CastPointsInvalidTargetPoint()
        {
            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>();
            Vector3RuleStub pointRule    = validSurface.AddComponent <Vector3RuleStub>();

            yield return(null);

            negationRule.Rule = new RuleContainer
            {
                Interface = pointRule
            };
            subject.TargetPointValidity = new RuleContainer
            {
                Interface = negationRule
            };

            Vector3 expectedStart = Vector3.zero;
            Vector3 expectedEnd   = validSurface.transform.position - (Vector3.forward * (validSurface.transform.localScale.z / 2f));

            pointRule.toMatch = expectedEnd;

            subject.ManualOnEnable();
            Physics.Simulate(Time.fixedDeltaTime);
            subject.Process();

            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);
        }