コード例 #1
0
        public void AddToEnd()
        {
            UnityEventListenerMock becamePopulatedMock = new UnityEventListenerMock();
            UnityEventListenerMock elementAddedMock    = new UnityEventListenerMock();
            UnityEventListenerMock elementRemovedMock  = new UnityEventListenerMock();
            UnityEventListenerMock becameEmptyMock     = new UnityEventListenerMock();

            subject.BecamePopulated.AddListener(becamePopulatedMock.Listen);
            subject.ElementAdded.AddListener(elementAddedMock.Listen);
            subject.ElementRemoved.AddListener(elementRemovedMock.Listen);
            subject.BecameEmpty.AddListener(becameEmptyMock.Listen);
            GameObject elementOne = new GameObject();
            GameObject elementTwo = new GameObject();

            Assert.IsEmpty(subject.Elements);

            subject.AddToEnd(elementOne);

            Assert.AreEqual(1, subject.Elements.Count);
            Assert.IsTrue(becamePopulatedMock.Received);
            Assert.IsTrue(elementAddedMock.Received);
            Assert.IsFalse(elementRemovedMock.Received);
            Assert.IsFalse(becameEmptyMock.Received);

            becamePopulatedMock.Reset();
            elementAddedMock.Reset();
            elementRemovedMock.Reset();
            becameEmptyMock.Reset();

            subject.AddToEnd(elementTwo);
            Assert.AreEqual(2, subject.Elements.Count);
            Assert.AreEqual(elementTwo, subject.Elements[1]);

            Assert.IsFalse(becamePopulatedMock.Received);
            Assert.IsTrue(elementAddedMock.Received);
            Assert.IsFalse(elementRemovedMock.Received);
            Assert.IsFalse(becameEmptyMock.Received);

            Object.DestroyImmediate(elementOne);
            Object.DestroyImmediate(elementTwo);
        }
コード例 #2
0
        public void Match()
        {
            GameObject             objectOne      = new GameObject();
            GameObject             objectTwo      = new GameObject();
            UnityEventListenerMock ruleOneMatched = new UnityEventListenerMock();
            UnityEventListenerMock ruleTwoMatched = new UnityEventListenerMock();

            RulesMatcher.Element elementOne = new RulesMatcher.Element()
            {
                rule = CreateRule(objectOne)
            };
            RulesMatcher.Element elementTwo = new RulesMatcher.Element()
            {
                rule = CreateRule(objectTwo)
            };

            elementOne.Matched.AddListener(ruleOneMatched.Listen);
            elementTwo.Matched.AddListener(ruleTwoMatched.Listen);

            subject.elements.Add(elementOne);
            subject.elements.Add(elementTwo);

            Assert.IsFalse(ruleOneMatched.Received);
            Assert.IsFalse(ruleTwoMatched.Received);

            subject.Match(objectOne);

            Assert.IsTrue(ruleOneMatched.Received);
            Assert.IsFalse(ruleTwoMatched.Received);

            ruleOneMatched.Reset();
            ruleTwoMatched.Reset();

            subject.Match(objectTwo);

            Assert.IsFalse(ruleOneMatched.Received);
            Assert.IsTrue(ruleTwoMatched.Received);

            Object.DestroyImmediate(objectOne);
            Object.DestroyImmediate(objectTwo);
        }
コード例 #3
0
        public void ClearSources()
        {
            UnityEventListenerMock activatedListenerMock   = new UnityEventListenerMock();
            UnityEventListenerMock deactivatedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock changedListenerMock     = new UnityEventListenerMock();

            subject.Activated.AddListener(activatedListenerMock.Listen);
            subject.Deactivated.AddListener(deactivatedListenerMock.Listen);
            subject.ValueChanged.AddListener(changedListenerMock.Listen);

            GameObject        sourceObject = new GameObject();
            BooleanActionMock sourceMock   = sourceObject.AddComponent <BooleanActionMock>();

            subject.AddSource(sourceMock);

            Assert.AreEqual(1, subject.Sources.Count);

            sourceMock.Receive(true);

            Assert.IsTrue(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsTrue(changedListenerMock.Received);

            subject.ClearSources();

            sourceMock.SetIsActivated(false);
            sourceMock.SetValue(false);
            activatedListenerMock.Reset();
            deactivatedListenerMock.Reset();
            changedListenerMock.Reset();

            Assert.AreEqual(0, subject.Sources.Count);

            sourceMock.Receive(true);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);

            Object.DestroyImmediate(sourceObject);
        }
コード例 #4
0
        public void ReceiveWithRuleRestrictions()
        {
            UnityEventListenerMock emittedMock = new UnityEventListenerMock();

            subject.Emitted.AddListener(emittedMock.Listen);
            GameObject  digestValid   = new GameObject();
            GameObject  digestInvalid = new GameObject();
            SurfaceData validData     = new SurfaceData(digestValid.transform);
            SurfaceData invalidData   = new SurfaceData(digestInvalid.transform);

            ListContainsRule          rule    = subject.gameObject.AddComponent <ListContainsRule>();
            UnityObjectObservableList objects = containingObject.AddComponent <UnityObjectObservableList>();

            rule.Objects = objects;

            objects.Add(digestValid);
            subject.ReceiveValidity = new RuleContainer
            {
                Interface = rule
            };

            Assert.IsNull(subject.Payload);
            Assert.IsFalse(emittedMock.Received);

            subject.Receive(validData);

            Assert.AreEqual(validData, subject.Payload);
            Assert.IsTrue(emittedMock.Received);

            emittedMock.Reset();

            Assert.IsFalse(emittedMock.Received);

            subject.Receive(invalidData);

            Assert.AreEqual(validData, subject.Payload);
            Assert.IsFalse(emittedMock.Received);

            Object.DestroyImmediate(digestValid);
            Object.DestroyImmediate(digestInvalid);
        }
コード例 #5
0
        public void ContainsNotFound()
        {
            UnityEventListenerMock elementFoundMock    = new UnityEventListenerMock();
            UnityEventListenerMock elementNotFoundMock = new UnityEventListenerMock();

            subject.ElementFound.AddListener(elementFoundMock.Listen);
            subject.ElementNotFound.AddListener(elementNotFoundMock.Listen);
            GameObject elementOne = new GameObject();
            GameObject elementTwo = new GameObject();

            subject.AddElement(elementTwo);
            elementFoundMock.Reset();
            elementNotFoundMock.Reset();

            Assert.IsFalse(subject.Contains(elementOne));
            Assert.IsTrue(elementNotFoundMock.Received);
            Assert.IsFalse(elementFoundMock.Received);

            Object.DestroyImmediate(elementOne);
            Object.DestroyImmediate(elementTwo);
        }
コード例 #6
0
        public IEnumerator SetAt()
        {
            UnityEventListenerMock addedMock   = new UnityEventListenerMock();
            UnityEventListenerMock removedMock = new UnityEventListenerMock();

            subject.Added.AddListener(addedMock.Listen);
            subject.Removed.AddListener(removedMock.Listen);

            GameObject elementOne   = new GameObject("One");
            GameObject elementTwo   = new GameObject("Two");
            GameObject elementThree = new GameObject("Three");
            GameObject elementFour  = new GameObject("Four");

            yield return(null);

            subject.Add(elementOne);
            subject.Add(elementTwo);
            subject.Add(elementThree);

            addedMock.Reset();
            removedMock.Reset();

            Assert.AreEqual(elementOne, subject.NonSubscribableElements[0]);
            Assert.AreEqual(elementTwo, subject.NonSubscribableElements[1]);
            Assert.AreEqual(elementThree, subject.NonSubscribableElements[2]);

            subject.SetAt(elementFour, 1);

            Assert.AreEqual(elementOne, subject.NonSubscribableElements[0]);
            Assert.AreEqual(elementFour, subject.NonSubscribableElements[1]);
            Assert.AreEqual(elementThree, subject.NonSubscribableElements[2]);

            Assert.IsTrue(addedMock.Received);
            Assert.IsTrue(removedMock.Received);

            Object.DestroyImmediate(elementOne);
            Object.DestroyImmediate(elementTwo);
            Object.DestroyImmediate(elementThree);
            Object.DestroyImmediate(elementFour);
        }
コード例 #7
0
        public void SetAtCurrentIndex()
        {
            UnityEventListenerMock addedMock   = new UnityEventListenerMock();
            UnityEventListenerMock removedMock = new UnityEventListenerMock();

            subject.Added.AddListener(addedMock.Listen);
            subject.Removed.AddListener(removedMock.Listen);

            subject.CurrentIndex = 1;

            GameObject elementOne   = new GameObject();
            GameObject elementTwo   = new GameObject();
            GameObject elementThree = new GameObject();
            GameObject elementFour  = new GameObject();

            subject.Add(elementOne);
            subject.Add(elementTwo);
            subject.Add(elementThree);

            addedMock.Reset();
            removedMock.Reset();

            Assert.AreEqual(elementOne, subject.NonSubscribableElements[0]);
            Assert.AreEqual(elementTwo, subject.NonSubscribableElements[1]);
            Assert.AreEqual(elementThree, subject.NonSubscribableElements[2]);

            subject.SetAtCurrentIndex(elementFour);

            Assert.AreEqual(elementOne, subject.NonSubscribableElements[0]);
            Assert.AreEqual(elementFour, subject.NonSubscribableElements[1]);
            Assert.AreEqual(elementThree, subject.NonSubscribableElements[2]);

            Assert.IsTrue(addedMock.Received);
            Assert.IsTrue(removedMock.Received);

            Object.DestroyImmediate(elementOne);
            Object.DestroyImmediate(elementTwo);
            Object.DestroyImmediate(elementThree);
            Object.DestroyImmediate(elementFour);
        }
コード例 #8
0
        public void PushExceedsEventCount()
        {
            UnityEventListenerMock elementOnePushedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementOnePoppedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementOneForcePoppedMock = new UnityEventListenerMock();

            GameObjectObservableStack.GameObjectElementEvents eventsOne = new GameObjectObservableStack.GameObjectElementEvents();
            eventsOne.Pushed.AddListener(elementOnePushedMock.Listen);
            eventsOne.Popped.AddListener(elementOnePoppedMock.Listen);
            eventsOne.ForcePopped.AddListener(elementOneForcePoppedMock.Listen);

            GameObject objectOne = new GameObject();
            GameObject objectTwo = new GameObject();

            subject.elementEvents.Add(eventsOne);

            Assert.IsFalse(elementOnePushedMock.Received);
            Assert.IsFalse(elementOnePoppedMock.Received);
            Assert.IsFalse(elementOneForcePoppedMock.Received);

            subject.Push(objectOne);

            Assert.IsTrue(elementOnePushedMock.Received);
            Assert.IsFalse(elementOnePoppedMock.Received);
            Assert.IsFalse(elementOneForcePoppedMock.Received);

            elementOnePushedMock.Reset();
            elementOnePoppedMock.Reset();
            elementOneForcePoppedMock.Reset();

            subject.Push(objectTwo);

            Assert.IsFalse(elementOnePushedMock.Received);
            Assert.IsFalse(elementOnePoppedMock.Received);
            Assert.IsFalse(elementOneForcePoppedMock.Received);

            Object.DestroyImmediate(objectOne);
            Object.DestroyImmediate(objectTwo);
        }
コード例 #9
0
        public void InvalidRemove()
        {
            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);

            Assert.IsFalse(firstStartedMock.Received);
            Assert.IsFalse(countChangedMock.Received);
            Assert.IsFalse(contentsChangedMock.Received);
            Assert.IsFalse(allStoppedMock.Received);

            firstStartedMock.Reset();
            countChangedMock.Reset();
            contentsChangedMock.Reset();
            allStoppedMock.Reset();

            Assert.AreEqual(0, subject.Elements.Count);

            subject.Remove(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);
        }
コード例 #10
0
        public void Process()
        {
            UnityEventListenerMock extractedListenerMock = new UnityEventListenerMock();

            subject.Extracted.AddListener(extractedListenerMock.Listen);
            subject.Source = containingObject;

            subject.Process();

            Assert.AreEqual(Vector3.zero, subject.LastExtractedValue);
            Assert.IsTrue(extractedListenerMock.Received);

            containingObject.transform.position = Vector3.one;
            extractedListenerMock.Reset();

            Assert.IsFalse(extractedListenerMock.Received);

            subject.Process();

            Assert.AreEqual(Vector3.one, subject.LastExtractedValue);
            Assert.IsTrue(extractedListenerMock.Received);
        }
        public void RegisterUnregisterOnConsumerContainer()
        {
            UnityEventListenerMock registeredMock   = new UnityEventListenerMock();
            UnityEventListenerMock unregisteredMock = new UnityEventListenerMock();

            subject.Registered.AddListener(registeredMock.Listen);
            subject.Unregistered.AddListener(unregisteredMock.Listen);

            GameObject containerOne = new GameObject();
            GameObject containerTwo = new GameObject();

            ActiveCollisionConsumerMock oneConsumerA = containerOne.AddComponent <ActiveCollisionConsumerMock>();
            ActiveCollisionConsumerMock oneConsumerB = containerOne.AddComponent <ActiveCollisionConsumerMock>();
            ActiveCollisionConsumerMock twoConsumer  = containerTwo.AddComponent <ActiveCollisionConsumerMock>();

            oneConsumerA.SetConsumerContainer(containerOne);
            oneConsumerB.SetConsumerContainer(containerOne);
            twoConsumer.SetConsumerContainer(containerTwo);

            subject.Register(oneConsumerA, null);
            subject.Register(oneConsumerB, null);
            subject.Register(twoConsumer, null);

            Assert.IsFalse(unregisteredMock.Received);
            Assert.AreEqual(3, subject.RegisteredConsumers.Count);

            registeredMock.Reset();
            unregisteredMock.Reset();

            subject.UnregisterConsumersOnContainer(containerOne);

            Assert.IsFalse(registeredMock.Received);
            Assert.IsTrue(unregisteredMock.Received);
            Assert.AreEqual(1, subject.RegisteredConsumers.Count);

            Object.DestroyImmediate(containerOne);
            Object.DestroyImmediate(containerTwo);
        }
コード例 #12
0
        public void ClearInactiveComponent()
        {
            UnityEventListenerMock addedMock   = new UnityEventListenerMock();
            UnityEventListenerMock removedMock = new UnityEventListenerMock();

            subject.Added.AddListener(addedMock.Listen);
            subject.Removed.AddListener(removedMock.Listen);
            GameObject elementOne = new GameObject();
            GameObject elementTwo = new GameObject();

            subject.IncreaseCount(elementOne);
            subject.IncreaseCount(elementOne);
            subject.IncreaseCount(elementTwo);
            subject.IncreaseCount(elementTwo);

            addedMock.Reset();
            removedMock.Reset();

            subject.enabled = false;

            Assert.IsFalse(addedMock.Received);
            Assert.IsFalse(removedMock.Received);
            Assert.AreEqual(2, subject.GetCount(elementOne));
            Assert.AreEqual(2, subject.GetCount(elementTwo));

            subject.Clear();

            Assert.IsFalse(addedMock.Received);
            Assert.IsFalse(removedMock.Received);
            Assert.AreEqual(2, subject.GetCount(elementOne));
            Assert.AreEqual(2, subject.GetCount(elementTwo));

            Assert.IsTrue(subject.ElementsCounter.ContainsKey(elementOne));
            Assert.IsTrue(subject.ElementsCounter.ContainsKey(elementTwo));

            Object.DestroyImmediate(elementOne);
            Object.DestroyImmediate(elementTwo);
        }
コード例 #13
0
        public void ClearInactiveGameObject()
        {
            UnityEventListenerMock elementAddedMock   = new UnityEventListenerMock();
            UnityEventListenerMock elementRemovedMock = new UnityEventListenerMock();

            subject.ElementAdded.AddListener(elementAddedMock.Listen);
            subject.ElementRemoved.AddListener(elementRemovedMock.Listen);
            GameObject elementOne = new GameObject();
            GameObject elementTwo = new GameObject();

            subject.IncreaseCount(elementOne);
            subject.IncreaseCount(elementOne);
            subject.IncreaseCount(elementTwo);
            subject.IncreaseCount(elementTwo);

            elementAddedMock.Reset();
            elementRemovedMock.Reset();

            subject.gameObject.SetActive(false);

            Assert.IsFalse(elementAddedMock.Received);
            Assert.IsFalse(elementRemovedMock.Received);
            Assert.AreEqual(2, subject.GetCount(elementOne));
            Assert.AreEqual(2, subject.GetCount(elementTwo));

            subject.Clear();

            Assert.IsFalse(elementAddedMock.Received);
            Assert.IsFalse(elementRemovedMock.Received);
            Assert.AreEqual(2, subject.GetCount(elementOne));
            Assert.AreEqual(2, subject.GetCount(elementTwo));

            Assert.IsTrue(subject.ElementsCounter.ContainsKey(elementOne));
            Assert.IsTrue(subject.ElementsCounter.ContainsKey(elementTwo));

            Object.DestroyImmediate(elementOne);
            Object.DestroyImmediate(elementTwo);
        }
        public void EventsNotEmittedOnDisabledComponent()
        {
            UnityEventListenerMock activatedListenerMock   = new UnityEventListenerMock();
            UnityEventListenerMock deactivatedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock changedListenerMock     = new UnityEventListenerMock();
            UnityEventListenerMock unchangedListenerMock   = new UnityEventListenerMock();

            subject.enabled = false;
            subject.Activated.AddListener(activatedListenerMock.Listen);
            subject.Deactivated.AddListener(deactivatedListenerMock.Listen);
            subject.ValueChanged.AddListener(changedListenerMock.Listen);
            subject.ValueUnchanged.AddListener(unchangedListenerMock.Listen);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);
            Assert.IsFalse(unchangedListenerMock.Received);

            subject.Receive(true);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);
            Assert.IsFalse(unchangedListenerMock.Received);

            activatedListenerMock.Reset();
            deactivatedListenerMock.Reset();
            changedListenerMock.Reset();
            unchangedListenerMock.Reset();

            subject.Receive(false);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);
            Assert.IsFalse(unchangedListenerMock.Received);
        }
        public void EventsNotEmittedOnInactiveGameObject()
        {
            UnityEventListenerMock activatedListenerMock   = new UnityEventListenerMock();
            UnityEventListenerMock deactivatedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock changedListenerMock     = new UnityEventListenerMock();
            UnityEventListenerMock unchangedListenerMock   = new UnityEventListenerMock();

            subject.gameObject.SetActive(false);
            subject.Activated.AddListener(activatedListenerMock.Listen);
            subject.Deactivated.AddListener(deactivatedListenerMock.Listen);
            subject.ValueChanged.AddListener(changedListenerMock.Listen);
            subject.ValueUnchanged.AddListener(unchangedListenerMock.Listen);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);
            Assert.IsFalse(unchangedListenerMock.Received);

            subject.Receive(true);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);
            Assert.IsFalse(unchangedListenerMock.Received);

            activatedListenerMock.Reset();
            deactivatedListenerMock.Reset();
            changedListenerMock.Reset();
            unchangedListenerMock.Reset();

            subject.Receive(false);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);
            Assert.IsFalse(changedListenerMock.Received);
            Assert.IsFalse(unchangedListenerMock.Received);
        }
        public void Extract()
        {
            UnityEventListenerMock extractedListenerMock = new UnityEventListenerMock();

            subject.Extracted.AddListener(extractedListenerMock.Listen);
            subject.Source = containingObject;

            Vector3 result = subject.Extract();

            Assert.AreEqual(Vector3.zero, result);
            Assert.AreEqual(Vector3.zero, subject.LastExtractedValue);
            Assert.IsTrue(extractedListenerMock.Received);

            containingObject.transform.eulerAngles = Vector3.one;
            extractedListenerMock.Reset();

            Assert.IsFalse(extractedListenerMock.Received);

            result = subject.Extract();

            Assert.AreEqual(Vector3.one.ToString(), result.ToString());
            Assert.AreEqual(Vector3.one.ToString(), subject.LastExtractedValue.ToString());
            Assert.IsTrue(extractedListenerMock.Received);
        }
コード例 #17
0
        public IEnumerator FacingThenNotFacing()
        {
            UnityEventListenerMock targetFacedMock    = new UnityEventListenerMock();
            UnityEventListenerMock targetNotFacedMock = new UnityEventListenerMock();

            subject.TargetFaced.AddListener(targetFacedMock.Listen);
            subject.TargetNotFaced.AddListener(targetNotFacedMock.Listen);

            GameObject objectA = GameObject.CreatePrimitive(PrimitiveType.Cube);
            GameObject objectB = GameObject.CreatePrimitive(PrimitiveType.Cube);

            objectA.transform.position = Vector3.left * 2f;
            objectB.transform.position = Vector3.right * 2f;

            subject.Source = objectA;
            subject.Target = objectB;

            Assert.IsFalse(targetFacedMock.Received);
            Assert.IsFalse(targetNotFacedMock.Received);

            targetFacedMock.Reset();
            targetNotFacedMock.Reset();

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsFalse(targetFacedMock.Received);
            Assert.IsTrue(targetNotFacedMock.Received);

            targetFacedMock.Reset();
            targetNotFacedMock.Reset();

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsFalse(targetFacedMock.Received);
            Assert.IsFalse(targetNotFacedMock.Received);

            targetFacedMock.Reset();
            targetNotFacedMock.Reset();

            objectA.transform.eulerAngles = Vector3.up * 90f;

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsTrue(targetFacedMock.Received);
            Assert.IsFalse(targetNotFacedMock.Received);

            targetFacedMock.Reset();
            targetNotFacedMock.Reset();

            objectA.transform.eulerAngles = Vector3.up * 180f;

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsFalse(targetFacedMock.Received);
            Assert.IsTrue(targetNotFacedMock.Received);

            Object.Destroy(objectA);
            Object.Destroy(objectB);
        }
コード例 #18
0
        public void TransformToRadians()
        {
            UnityEventListenerMock transformedListenerMock = new UnityEventListenerMock();

            subject.Transformed.AddListener(transformedListenerMock.Listen);
            subject.Unit = Vector2ToAngle.AngleUnit.Radians;

            subject.Origin = new Vector2(0f, 1f);

            Assert.AreEqual(0f, subject.Result);
            Assert.IsFalse(transformedListenerMock.Received);

            float result = subject.Transform(new Vector2(0f, 0f));

            Assert.AreEqual(0f, result);
            Assert.AreEqual(0f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(0f, 1f));
            Assert.AreEqual(0f, result);
            Assert.AreEqual(0f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(1f, 1f));
            Assert.AreEqual(0.785398185f, result);
            Assert.AreEqual(0.785398185f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(1f, 0f));
            Assert.AreEqual(1.57079637f, result);
            Assert.AreEqual(1.57079637f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(0f, -1f));
            Assert.AreEqual(3.14159274f, result);
            Assert.AreEqual(3.14159274f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(-1f, -1f));
            Assert.AreEqual(3.92699075f, result);
            Assert.AreEqual(3.92699075f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(-1f, 0f));
            Assert.AreEqual(4.71238899f, result);
            Assert.AreEqual(4.71238899f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            subject.Origin = new Vector2(-1f, 0f);

            result = subject.Transform(new Vector2(0f, -1f));
            Assert.AreEqual(4.71238899f, result);
            Assert.AreEqual(4.71238899f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);
        }
コード例 #19
0
        public void TransformToDegrees()
        {
            UnityEventListenerMock transformedListenerMock = new UnityEventListenerMock();

            subject.Transformed.AddListener(transformedListenerMock.Listen);
            subject.Unit   = Vector2ToAngle.AngleUnit.Degrees;
            subject.Origin = new Vector2(0f, 1f);

            Assert.AreEqual(0f, subject.Result);
            Assert.IsFalse(transformedListenerMock.Received);

            float result = subject.Transform(new Vector2(0f, 0f));

            Assert.AreEqual(0f, result);
            Assert.AreEqual(0f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(0f, 1f));
            Assert.AreEqual(0f, result);
            Assert.AreEqual(0f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(1f, 1f));
            Assert.AreEqual(45f, result);
            Assert.AreEqual(45f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(1f, 0f));
            Assert.AreEqual(90f, result);
            Assert.AreEqual(90f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(0f, -1f));
            Assert.AreEqual(180f, result);
            Assert.AreEqual(180f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(-1f, -1f));
            Assert.AreEqual(225f, result);
            Assert.AreEqual(225f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(-1f, 0f));
            Assert.AreEqual(270f, result);
            Assert.AreEqual(270f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            subject.Origin = new Vector2(-1f, 0f);

            result = subject.Transform(new Vector2(0f, -1f));
            Assert.AreEqual(270f, result);
            Assert.AreEqual(270f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);
        }
コード例 #20
0
        public void EnterExitHover()
        {
            SetUpElements();

            UnityEventListenerMock enterListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock exitListenerMock  = new UnityEventListenerMock();
            UnityEventListenerMock hoverListenerMock = new UnityEventListenerMock();

            subject.Entered.AddListener(enterListenerMock.Listen);
            subject.Exited.AddListener(exitListenerMock.Listen);
            subject.Hovering.AddListener(hoverListenerMock.Listen);

            subject.ManualOnEnable();

            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);

            subject.Activate();
            subject.Process();

            //No valid target so still should be false
            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);
            Assert.IsNull(subject.HoverTarget);

            //Place an object in the way to make a valid target
            GameObject blocker = GameObject.CreatePrimitive(PrimitiveType.Cube);

            blocker.name = "blocker";
            blocker.transform.position = Vector3.forward * 5f;

            List <Vector3> castPoints = new List <Vector3> {
                Vector3.zero, blocker.transform.position
            };

            PointsCast.EventData straightCast;

            straightCast = CastPoints(castPoints, true, true, new Ray(Vector3.zero, Vector3.forward));

            subject.HandleData(straightCast);

            //The target should be entered and be hovered over
            Assert.IsTrue(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsTrue(hoverListenerMock.Received);
            Assert.AreEqual(blocker, subject.HoverTarget.CollisionData.transform.gameObject);

            enterListenerMock.Reset();
            hoverListenerMock.Reset();

            //Move the target
            blocker.transform.position = Vector3.left * 10f;

            straightCast = CastPoints(castPoints, false);

            subject.HandleData(straightCast);

            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsTrue(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);
            Assert.IsNull(subject.HoverTarget);

            Object.DestroyImmediate(blocker);
        }
コード例 #21
0
        public void Select()
        {
            SetUpElements();

            UnityEventListenerMock enterListenerMock  = new UnityEventListenerMock();
            UnityEventListenerMock exitListenerMock   = new UnityEventListenerMock();
            UnityEventListenerMock hoverListenerMock  = new UnityEventListenerMock();
            UnityEventListenerMock selectListenerMock = new UnityEventListenerMock();

            subject.Entered.AddListener(enterListenerMock.Listen);
            subject.Exited.AddListener(exitListenerMock.Listen);
            subject.Hovering.AddListener(hoverListenerMock.Listen);
            subject.Selected.AddListener(selectListenerMock.Listen);

            subject.ManualOnEnable();

            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);
            Assert.IsFalse(selectListenerMock.Received);

            subject.Activate();
            subject.Process();
            subject.Select();

            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);
            Assert.IsTrue(selectListenerMock.Received);
            Assert.IsNull(subject.HoverTarget);

            enterListenerMock.Reset();
            exitListenerMock.Reset();
            hoverListenerMock.Reset();
            selectListenerMock.Reset();

            //Now add a valid target that can be selected
            GameObject blocker = GameObject.CreatePrimitive(PrimitiveType.Cube);

            blocker.transform.position = Vector3.forward * 5f;

            List <Vector3> castPoints = new List <Vector3>
            {
                Vector3.zero,
                blocker.transform.position
            };

            PointsCast.EventData straightCast = CastPoints(castPoints, true, true, new Ray(Vector3.zero, Vector3.forward));

            subject.HandleData(straightCast);
            subject.Process();
            subject.Select();

            Assert.IsTrue(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsTrue(hoverListenerMock.Received);
            Assert.IsTrue(selectListenerMock.Received);
            Assert.AreEqual(blocker, subject.HoverTarget.CollisionData.transform.gameObject);
            Assert.AreEqual(blocker, subject.SelectedTarget.CollisionData.transform.gameObject);

            Object.DestroyImmediate(blocker);
        }
コード例 #22
0
        public void ActivateAndDeactivate()
        {
            SetUpElements();

            UnityEventListenerMock activatedListenerMock   = new UnityEventListenerMock();
            UnityEventListenerMock deactivatedListenerMock = new UnityEventListenerMock();

            subject.Activated.AddListener(activatedListenerMock.Listen);
            subject.Deactivated.AddListener(deactivatedListenerMock.Listen);

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);

            subject.ManualOnEnable();

            Assert.IsFalse(validOriginMesh.activeInHierarchy);
            Assert.IsFalse(invalidOriginMesh.activeInHierarchy);
            Assert.IsFalse(validSegmentMesh.activeInHierarchy);
            Assert.IsFalse(invalidSegmentMesh.activeInHierarchy);
            Assert.IsFalse(validDestinationMesh.activeInHierarchy);
            Assert.IsFalse(invalidDestinationMesh.activeInHierarchy);

            subject.Activate();
            subject.Process();

            Assert.IsTrue(activatedListenerMock.Received);
            Assert.IsFalse(deactivatedListenerMock.Received);

            Assert.IsFalse(validOriginMesh.activeInHierarchy);
            Assert.IsTrue(invalidOriginMesh.activeInHierarchy);
            Assert.IsFalse(validSegmentMesh.activeInHierarchy);
            Assert.IsTrue(invalidSegmentMesh.activeInHierarchy);
            Assert.IsFalse(validDestinationMesh.activeInHierarchy);
            Assert.IsTrue(invalidDestinationMesh.activeInHierarchy);

            GameObject blocker = GameObject.CreatePrimitive(PrimitiveType.Cube);

            blocker.transform.position = Vector3.forward * 5f;

            List <Vector3> castPoints = new List <Vector3>
            {
                Vector3.zero,
                blocker.transform.position
            };

            PointsCast.EventData straightCast = CastPoints(castPoints);

            subject.HandleData(straightCast);
            subject.Process();

            Assert.IsTrue(validOriginMesh.activeInHierarchy);
            Assert.IsFalse(invalidOriginMesh.activeInHierarchy);
            Assert.IsTrue(validSegmentMesh.activeInHierarchy);
            Assert.IsFalse(invalidSegmentMesh.activeInHierarchy);
            Assert.IsTrue(validDestinationMesh.activeInHierarchy);
            Assert.IsFalse(invalidDestinationMesh.activeInHierarchy);

            activatedListenerMock.Reset();
            deactivatedListenerMock.Reset();
            subject.Deactivate();
            subject.Process();

            Assert.IsFalse(activatedListenerMock.Received);
            Assert.IsTrue(deactivatedListenerMock.Received);

            Assert.IsFalse(validOriginMesh.activeInHierarchy);
            Assert.IsFalse(invalidOriginMesh.activeInHierarchy);
            Assert.IsFalse(validSegmentMesh.activeInHierarchy);
            Assert.IsFalse(invalidSegmentMesh.activeInHierarchy);
            Assert.IsFalse(validDestinationMesh.activeInHierarchy);
            Assert.IsFalse(invalidDestinationMesh.activeInHierarchy);

            Object.DestroyImmediate(blocker);
        }
コード例 #23
0
        public IEnumerator ProcessFirstActiveSourceAgainstTargetThenCease()
        {
            GameObject source1 = new GameObject("source1");
            GameObject source2 = new GameObject("source2");
            GameObject source3 = new GameObject("source3");
            GameObject target1 = new GameObject("target1");

            subject.Sources = containingObject.AddComponent <GameObjectObservableList>();
            subject.Targets = containingObject.AddComponent <GameObjectObservableList>();
            UnityEventListenerMock activeSourceChangedListenerMock = new UnityEventListenerMock();

            subject.ActiveSourceChanging.AddListener(activeSourceChangedListenerMock.Listen);
            yield return(null);

            subject.CeaseAfterFirstSourceProcessed = true;

            subject.gameObject.AddComponent <RuleStub>();
            ActiveInHierarchyRule activeInHierarchyRule = subject.gameObject.AddComponent <ActiveInHierarchyRule>();

            subject.SourceValidity = new RuleContainer
            {
                Interface = activeInHierarchyRule
            };

            subject.Sources.Add(source1);
            subject.Sources.Add(source2);
            subject.Sources.Add(source3);
            subject.Targets.Add(target1);

            Assert.AreEqual("source1", source1.name);
            Assert.AreEqual("source2", source2.name);
            Assert.AreEqual("source3", source3.name);
            Assert.AreEqual("target1", target1.name);

            source1.SetActive(false);
            source2.SetActive(true);
            source3.SetActive(true);

            Assert.IsNull(subject.ActiveSource);
            Assert.IsFalse(activeSourceChangedListenerMock.Received);
            subject.Process();
            Assert.IsTrue(activeSourceChangedListenerMock.Received);
            Assert.AreEqual("source2", subject.ActiveSource.name);

            Assert.AreEqual("source1", source1.name);
            Assert.AreEqual("source2", source2.name);
            Assert.AreEqual("source3", source3.name);
            Assert.AreEqual("source2", target1.name);

            source1.SetActive(false);
            source2.SetActive(false);
            source3.SetActive(true);

            activeSourceChangedListenerMock.Reset();
            subject.Process();
            Assert.IsTrue(activeSourceChangedListenerMock.Received);
            Assert.AreEqual("source3", subject.ActiveSource.name);

            Assert.AreEqual("source1", source1.name);
            Assert.AreEqual("source2", source2.name);
            Assert.AreEqual("source3", source3.name);
            Assert.AreEqual("source3", target1.name);

            source1.SetActive(true);
            source2.SetActive(true);
            source3.SetActive(true);

            activeSourceChangedListenerMock.Reset();
            subject.Process();
            Assert.IsTrue(activeSourceChangedListenerMock.Received);
            Assert.AreEqual("source1", subject.ActiveSource.name);

            Assert.AreEqual("source1", source1.name);
            Assert.AreEqual("source2", source2.name);
            Assert.AreEqual("source3", source3.name);
            Assert.AreEqual("source1", target1.name);

            activeSourceChangedListenerMock.Reset();
            subject.Process();
            Assert.IsFalse(activeSourceChangedListenerMock.Received);
            Assert.AreEqual("source1", subject.ActiveSource.name);

            Object.DestroyImmediate(source1);
            Object.DestroyImmediate(source2);
            Object.DestroyImmediate(source3);
            Object.DestroyImmediate(target1);
        }
コード例 #24
0
        public void TransformToSignedRadians()
        {
            UnityEventListenerMock transformedListenerMock = new UnityEventListenerMock();

            subject.Transformed.AddListener(transformedListenerMock.Listen);
            subject.Unit = Vector2ToAngle.AngleUnit.SignedRadians;

            subject.Origin = new Vector2(0f, 1f);

            Assert.AreApproximatelyEqual(0f, subject.Result);
            Assert.IsFalse(transformedListenerMock.Received);

            float result = subject.Transform(new Vector2(0f, 0f));

            Assert.AreApproximatelyEqual(0f, result);
            Assert.AreApproximatelyEqual(0f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(0f, 1f));
            Assert.AreApproximatelyEqual(0f, result);
            Assert.AreApproximatelyEqual(0f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(1f, 1f));
            Assert.AreApproximatelyEqual(0.785398185f, result);
            Assert.AreApproximatelyEqual(0.785398185f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(1f, 0f));
            Assert.AreApproximatelyEqual(1.57079637f, result);
            Assert.AreApproximatelyEqual(1.57079637f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(0f, -1f));
            Assert.AreApproximatelyEqual(3.141593f, result);
            Assert.AreApproximatelyEqual(3.141593f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(-1f, -1f));
            Assert.AreApproximatelyEqual(-2.356194f, result);
            Assert.AreApproximatelyEqual(-2.356194f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result = subject.Transform(new Vector2(-1f, 0f));
            Assert.AreApproximatelyEqual(-1.570796f, result);
            Assert.AreApproximatelyEqual(-1.570796f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            subject.Origin = new Vector2(-1f, 0f);

            result = subject.Transform(new Vector2(0f, -1f));
            Assert.AreApproximatelyEqual(-1.570796f, result);
            Assert.AreApproximatelyEqual(-1.570796f, subject.Result);
            Assert.IsTrue(transformedListenerMock.Received);
        }
コード例 #25
0
        public IEnumerator CollisionDoesNotEndOnTrackerGameObjectDisable()
        {
            WaitForFixedUpdate yieldInstruction = new WaitForFixedUpdate();

            GameObject trackerContainer = GameObject.CreatePrimitive(PrimitiveType.Cube);

            trackerContainer.GetComponent <Collider>().isTrigger    = true;
            trackerContainer.AddComponent <Rigidbody>().isKinematic = true;
            trackerContainer.transform.position = Vector3.forward;
            CollisionTrackerMock tracker = trackerContainer.AddComponent <CollisionTrackerMock>();

            tracker.SetStopCollisionsOnDisable(false);

            GameObject notifierContainer = GameObject.CreatePrimitive(PrimitiveType.Cube);

            notifierContainer.GetComponent <Collider>().isTrigger    = true;
            notifierContainer.AddComponent <Rigidbody>().isKinematic = true;
            notifierContainer.transform.position = Vector3.back;
            CollisionNotifier notifier = notifierContainer.AddComponent <CollisionNotifier>();

            UnityEventListenerMock trackerCollisionStartedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock trackerCollisionChangedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock trackerCollisionStoppedListenerMock = new UnityEventListenerMock();

            tracker.CollisionStarted.AddListener(trackerCollisionStartedListenerMock.Listen);
            tracker.CollisionChanged.AddListener(trackerCollisionChangedListenerMock.Listen);
            tracker.CollisionStopped.AddListener(trackerCollisionStoppedListenerMock.Listen);

            UnityEventListenerMock notifierCollisionStartedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock notifierCollisionChangedListenerMock = new UnityEventListenerMock();
            UnityEventListenerMock notifierCollisionStoppedListenerMock = new UnityEventListenerMock();

            notifier.CollisionStarted.AddListener(notifierCollisionStartedListenerMock.Listen);
            notifier.CollisionChanged.AddListener(notifierCollisionChangedListenerMock.Listen);
            notifier.CollisionStopped.AddListener(notifierCollisionStoppedListenerMock.Listen);

            yield return(yieldInstruction);

            Assert.IsFalse(trackerCollisionStartedListenerMock.Received);
            Assert.IsFalse(trackerCollisionChangedListenerMock.Received);
            Assert.IsFalse(trackerCollisionStoppedListenerMock.Received);

            Assert.IsFalse(notifierCollisionStartedListenerMock.Received);
            Assert.IsFalse(notifierCollisionChangedListenerMock.Received);
            Assert.IsFalse(notifierCollisionStoppedListenerMock.Received);

            trackerCollisionStartedListenerMock.Reset();
            trackerCollisionChangedListenerMock.Reset();
            trackerCollisionStoppedListenerMock.Reset();

            notifierCollisionStartedListenerMock.Reset();
            notifierCollisionChangedListenerMock.Reset();
            notifierCollisionStoppedListenerMock.Reset();

            trackerContainer.transform.position  = Vector3.zero;
            notifierContainer.transform.position = Vector3.zero;

            yield return(yieldInstruction);

            Assert.IsTrue(trackerCollisionStartedListenerMock.Received);
            Assert.IsTrue(trackerCollisionChangedListenerMock.Received);
            Assert.IsFalse(trackerCollisionStoppedListenerMock.Received);

            Assert.IsTrue(notifierCollisionStartedListenerMock.Received);
            Assert.IsTrue(notifierCollisionChangedListenerMock.Received);
            Assert.IsFalse(notifierCollisionStoppedListenerMock.Received);

            trackerCollisionStartedListenerMock.Reset();
            trackerCollisionChangedListenerMock.Reset();
            trackerCollisionStoppedListenerMock.Reset();

            notifierCollisionStartedListenerMock.Reset();
            notifierCollisionChangedListenerMock.Reset();
            notifierCollisionStoppedListenerMock.Reset();

            trackerContainer.SetActive(false);

            yield return(yieldInstruction);

            Assert.IsFalse(trackerCollisionStartedListenerMock.Received);
            Assert.IsFalse(trackerCollisionChangedListenerMock.Received);
            Assert.IsFalse(trackerCollisionStoppedListenerMock.Received);

            Assert.IsFalse(notifierCollisionStartedListenerMock.Received);
            Assert.IsFalse(notifierCollisionChangedListenerMock.Received);
            Assert.IsFalse(notifierCollisionStoppedListenerMock.Received);

            Object.DestroyImmediate(trackerContainer);
            Object.DestroyImmediate(notifierContainer);
        }
コード例 #26
0
        public void PopAtIndexAlreadyPopped()
        {
            UnityEventListenerMock elementOnePushedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementOnePoppedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementOneForcePoppedMock = new UnityEventListenerMock();

            GameObjectObservableStack.GameObjectElementEvents eventsOne = new GameObjectObservableStack.GameObjectElementEvents();
            eventsOne.Pushed.AddListener(elementOnePushedMock.Listen);
            eventsOne.Popped.AddListener(elementOnePoppedMock.Listen);
            eventsOne.ForcePopped.AddListener(elementOneForcePoppedMock.Listen);

            UnityEventListenerMock elementTwoPushedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementTwoPoppedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementTwoForcePoppedMock = new UnityEventListenerMock();

            GameObjectObservableStack.GameObjectElementEvents eventsTwo = new GameObjectObservableStack.GameObjectElementEvents();
            eventsTwo.Pushed.AddListener(elementTwoPushedMock.Listen);
            eventsTwo.Popped.AddListener(elementTwoPoppedMock.Listen);
            eventsTwo.ForcePopped.AddListener(elementTwoForcePoppedMock.Listen);

            UnityEventListenerMock elementThreePushedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementThreePoppedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementThreeForcePoppedMock = new UnityEventListenerMock();

            GameObjectObservableStack.GameObjectElementEvents eventsThree = new GameObjectObservableStack.GameObjectElementEvents();
            eventsThree.Pushed.AddListener(elementThreePushedMock.Listen);
            eventsThree.Popped.AddListener(elementThreePoppedMock.Listen);
            eventsThree.ForcePopped.AddListener(elementThreeForcePoppedMock.Listen);

            GameObject objectOne   = new GameObject();
            GameObject objectTwo   = new GameObject();
            GameObject objectThree = new GameObject();

            subject.elementEvents.Add(eventsOne);
            subject.elementEvents.Add(eventsTwo);
            subject.elementEvents.Add(eventsThree);

            subject.Push(objectOne);
            subject.Push(objectTwo);
            subject.Push(objectThree);

            subject.PopAt(objectTwo);

            elementOnePushedMock.Reset();
            elementOnePoppedMock.Reset();
            elementOneForcePoppedMock.Reset();
            elementTwoPushedMock.Reset();
            elementTwoPoppedMock.Reset();
            elementTwoForcePoppedMock.Reset();
            elementThreePushedMock.Reset();
            elementThreePoppedMock.Reset();
            elementThreeForcePoppedMock.Reset();

            Assert.IsFalse(elementOnePushedMock.Received);
            Assert.IsFalse(elementOnePoppedMock.Received);
            Assert.IsFalse(elementOneForcePoppedMock.Received);
            Assert.IsFalse(elementTwoPushedMock.Received);
            Assert.IsFalse(elementTwoPoppedMock.Received);
            Assert.IsFalse(elementTwoForcePoppedMock.Received);
            Assert.IsFalse(elementThreePushedMock.Received);
            Assert.IsFalse(elementThreePoppedMock.Received);
            Assert.IsFalse(elementThreeForcePoppedMock.Received);

            subject.PopAt(1);

            Assert.IsFalse(elementOnePushedMock.Received);
            Assert.IsFalse(elementOnePoppedMock.Received);
            Assert.IsFalse(elementOneForcePoppedMock.Received);
            Assert.IsFalse(elementTwoPushedMock.Received);
            Assert.IsFalse(elementTwoPoppedMock.Received);
            Assert.IsFalse(elementTwoForcePoppedMock.Received);
            Assert.IsFalse(elementThreePushedMock.Received);
            Assert.IsFalse(elementThreePoppedMock.Received);
            Assert.IsFalse(elementThreeForcePoppedMock.Received);

            Object.DestroyImmediate(objectOne);
            Object.DestroyImmediate(objectTwo);
            Object.DestroyImmediate(objectThree);
        }
        public void HasRelationship()
        {
            UnityEventListenerMock relationshipFoundMock    = new UnityEventListenerMock();
            UnityEventListenerMock relationshipNotFoundMock = new UnityEventListenerMock();

            subject.RelationshipFound.AddListener(relationshipFoundMock.Listen);
            subject.RelationshipNotFound.AddListener(relationshipNotFoundMock.Listen);

            GameObject keyOne   = new GameObject();
            GameObject valueOne = new GameObject();
            GameObject valueTwo = new GameObject();

            GameObject keyTwo     = new GameObject();
            GameObject valueThree = new GameObject();

            GameObject keyThree = new GameObject();

            GameObjectMultiRelationObservableList.MultiRelation relationOne = new GameObjectMultiRelationObservableList.MultiRelation
            {
                Key    = keyOne,
                Values = new List <GameObject>()
                {
                    valueOne, valueTwo
                }
            };

            GameObjectMultiRelationObservableList.MultiRelation relationTwo = new GameObjectMultiRelationObservableList.MultiRelation
            {
                Key    = keyTwo,
                Values = new List <GameObject>()
                {
                    valueThree
                }
            };

            subject.Add(relationOne);
            subject.Add(relationTwo);

            Assert.IsFalse(relationshipFoundMock.Received);
            Assert.IsFalse(relationshipNotFoundMock.Received);

            Assert.IsTrue(subject.HasRelationship(keyOne, out List <GameObject> resultsOne));
            Assert.AreEqual(valueOne, resultsOne[0]);
            Assert.AreEqual(valueTwo, resultsOne[1]);
            Assert.IsTrue(relationshipFoundMock.Received);
            Assert.IsFalse(relationshipNotFoundMock.Received);

            relationshipFoundMock.Reset();
            relationshipNotFoundMock.Reset();

            Assert.IsTrue(subject.HasRelationship(keyTwo, out List <GameObject> resultsTwo));
            Assert.AreEqual(valueThree, resultsTwo[0]);
            Assert.IsTrue(relationshipFoundMock.Received);
            Assert.IsFalse(relationshipNotFoundMock.Received);

            relationshipFoundMock.Reset();
            relationshipNotFoundMock.Reset();

            Assert.IsFalse(subject.HasRelationship(keyThree, out List <GameObject> resultsThree));
            Assert.IsNull(resultsThree);
            Assert.IsFalse(relationshipFoundMock.Received);
            Assert.IsTrue(relationshipNotFoundMock.Received);

            Object.DestroyImmediate(keyOne);
            Object.DestroyImmediate(valueOne);
            Object.DestroyImmediate(valueTwo);
            Object.DestroyImmediate(keyTwo);
            Object.DestroyImmediate(valueThree);
            Object.DestroyImmediate(keyThree);
        }
コード例 #28
0
        public IEnumerator ObscuredThenUnobscuredCompoundColliders()
        {
            UnityEventListenerMock targetObscuredMock   = new UnityEventListenerMock();
            UnityEventListenerMock targetUnobscuredMock = new UnityEventListenerMock();

            subject.TargetObscured.AddListener(targetObscuredMock.Listen);
            subject.TargetUnobscured.AddListener(targetUnobscuredMock.Listen);

            GameObject objectA = GameObject.CreatePrimitive(PrimitiveType.Cube);

            GameObject objectB = new GameObject();

            objectB.AddComponent <Rigidbody>();
            GameObject objectC = GameObject.CreatePrimitive(PrimitiveType.Cube);

            objectC.transform.SetParent(objectB.transform);

            objectA.transform.position = Vector3.left * 2f;
            objectB.transform.position = Vector3.right * 2f;

            subject.Source = objectA;
            subject.Target = objectB;

            Assert.IsFalse(targetObscuredMock.Received);
            Assert.IsFalse(targetUnobscuredMock.Received);

            targetObscuredMock.Reset();
            targetUnobscuredMock.Reset();

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsFalse(targetObscuredMock.Received);
            Assert.IsTrue(targetUnobscuredMock.Received);

            targetObscuredMock.Reset();
            targetUnobscuredMock.Reset();

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsFalse(targetObscuredMock.Received);
            Assert.IsFalse(targetUnobscuredMock.Received);

            targetObscuredMock.Reset();
            targetUnobscuredMock.Reset();

            GameObject obscurer = GameObject.CreatePrimitive(PrimitiveType.Cube);

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsTrue(targetObscuredMock.Received);
            Assert.IsFalse(targetUnobscuredMock.Received);

            targetObscuredMock.Reset();
            targetUnobscuredMock.Reset();

            Object.Destroy(obscurer);

            yield return(new WaitForEndOfFrame());

            subject.Process();

            yield return(new WaitForEndOfFrame());

            Assert.IsFalse(targetObscuredMock.Received);
            Assert.IsTrue(targetUnobscuredMock.Received);

            Object.Destroy(objectA);
            Object.Destroy(objectB);
            Object.Destroy(objectC);
        }
コード例 #29
0
        public void Transform()
        {
            UnityEventListenerMock transformedListenerMock = new UnityEventListenerMock();

            subject.Transformed.AddListener(transformedListenerMock.Listen);

            Assert.AreEqual(Vector2.zero, subject.Result);
            Assert.IsFalse(transformedListenerMock.Received);

            Vector2 result         = subject.Transform(5f);
            Vector2 expectedResult = new Vector2(1f, 0.1f);

            Assert.AreEqual(expectedResult.ToString(), result.ToString());
            Assert.AreEqual(expectedResult.ToString(), subject.Result.ToString());
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result         = subject.Transform(5f);
            expectedResult = new Vector2(1f, 0.2f);

            Assert.AreEqual(expectedResult.ToString(), result.ToString());
            Assert.AreEqual(expectedResult.ToString(), subject.Result.ToString());
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result         = subject.Transform(10f);
            expectedResult = new Vector2(1f, 0.4f);

            Assert.AreEqual(expectedResult.ToString(), result.ToString());
            Assert.AreEqual(expectedResult.ToString(), subject.Result.ToString());
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result         = subject.Transform(-10f);
            expectedResult = new Vector2(1f, 0.2f);

            Assert.AreEqual(expectedResult.ToString(), result.ToString());
            Assert.AreEqual(expectedResult.ToString(), subject.Result.ToString());
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result         = subject.Transform(35f);
            expectedResult = new Vector2(1f, 1f);

            Assert.AreEqual(expectedResult.ToString(), result.ToString());
            Assert.AreEqual(expectedResult.ToString(), subject.Result.ToString());
            Assert.IsTrue(transformedListenerMock.Received);

            transformedListenerMock.Reset();

            result         = subject.Transform(-45f);
            expectedResult = new Vector2(1f, 0f);

            Assert.AreEqual(expectedResult.ToString(), result.ToString());
            Assert.AreEqual(expectedResult.ToString(), subject.Result.ToString());
            Assert.IsTrue(transformedListenerMock.Received);
        }
コード例 #30
0
        public void Select()
        {
            SetUpElements();

            UnityEventListenerMock enterListenerMock  = new UnityEventListenerMock();
            UnityEventListenerMock exitListenerMock   = new UnityEventListenerMock();
            UnityEventListenerMock hoverListenerMock  = new UnityEventListenerMock();
            UnityEventListenerMock selectListenerMock = new UnityEventListenerMock();

            subject.Entered.AddListener(enterListenerMock.Listen);
            subject.Exited.AddListener(exitListenerMock.Listen);
            subject.Hovering.AddListener(hoverListenerMock.Listen);
            subject.Selected.AddListener(selectListenerMock.Listen);

            subject.ManualOnEnable();

            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);
            Assert.IsFalse(selectListenerMock.Received);

            subject.Activate();
            subject.Process();
            subject.Select();

            Assert.IsFalse(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsFalse(hoverListenerMock.Received);
            Assert.IsTrue(selectListenerMock.Received);
            Assert.IsNull(subject.HoverTarget);

            enterListenerMock.Reset();
            exitListenerMock.Reset();
            hoverListenerMock.Reset();
            selectListenerMock.Reset();

            //Now add a valid target that can be selected
            GameObject blocker = GameObject.CreatePrimitive(PrimitiveType.Cube);

            blocker.transform.position = Vector3.forward * 5f;

            List <Vector3> castPoints = new List <Vector3>
            {
                Vector3.zero,
                blocker.transform.position
            };

            PointsCast.EventData straightCast = CastPoints(castPoints, true, true, new Ray(Vector3.zero, Vector3.forward));

            subject.HandleData(straightCast);
            subject.Process();
            subject.Select();

            Assert.IsTrue(enterListenerMock.Received);
            Assert.IsFalse(exitListenerMock.Received);
            Assert.IsTrue(hoverListenerMock.Received);
            Assert.IsTrue(selectListenerMock.Received);
            Assert.AreEqual(subject.transform, subject.HoverTarget.Transform);
            Assert.AreEqual(blocker, subject.HoverTarget.CollisionData.transform.gameObject);
            Assert.AreEqual(blocker, subject.SelectedTarget.CollisionData.transform.gameObject);
            Assert.AreEqual("{ Transform = containingObject (UnityEngine.Transform) | UseLocalValues = False | PositionOverride = (0.0, 0.0, 0.0) | RotationOverride = (0.0, 0.0, 0.0, 1.0) | ScaleOverride = (1.0, 1.0, 1.0) | Origin = (0.0, 0.0, 0.0) | Direction = (0.0, 0.0, 1.0) | CollisionData = { barycentricCoordinate = (1.0, 0.0, 0.0) | Collider = Cube (UnityEngine.BoxCollider) | Distance = 4.5 | Lightmap Coord = (0.0, 0.0) | Normal = (0.0, 0.0, -1.0) | Point = (0.0, 0.0, 4.5) | Rigidbody = [null] | Texture Coord = (0.0, 0.0) | Texture Coord2 = (0.0, 0.0) | Transform = Cube (UnityEngine.Transform) | Triangle Index = -1 } | IsCurrentlyActive = True | IsCurrentlyHovering = True | CurrentHoverDuration = " + subject.SelectedTarget.CurrentHoverDuration + " | CurrentPointsCastData = { HitData = { barycentricCoordinate = (1.0, 0.0, 0.0) | Collider = Cube (UnityEngine.BoxCollider) | Distance = 4.5 | Lightmap Coord = (0.0, 0.0) | Normal = (0.0, 0.0, -1.0) | Point = (0.0, 0.0, 4.5) | Rigidbody = [null] | Texture Coord = (0.0, 0.0) | Texture Coord2 = (0.0, 0.0) | Transform = Cube (UnityEngine.Transform) | Triangle Index = -1 } | IsValid = True } }", subject.SelectedTarget.ToString());

            Object.DestroyImmediate(blocker);
        }