예제 #1
0
 /// <summary>
 /// Attempt to grab the Interactable to the given Interactor GameObject.
 /// </summary>
 /// <param name="interactor">The Interactor to attach the Interactable to.</param>
 public virtual void Grab(GameObject interactor)
 {
     //Process single handed grab
     if (gameObjectEventStack == null && grabAction.Count > 0)
     {
         gameObjectEventProxyEmitter?.Receive(interactor);
         grabAction[0]?.Receive(true);
     }
     //Process multi handle grab
     else if (grabAction.Count > gameObjectEventStack.EventIndex)
     {
         int grabIndex = gameObjectEventStack.EventIndex;
         gameObjectEventStack.Push(interactor);
         grabAction[grabIndex]?.Receive(true);
     }
 }
예제 #2
0
        public void Push()
        {
            UnityEventListenerMock elementOnePushedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementOnePoppedMock      = new UnityEventListenerMock();
            UnityEventListenerMock elementOneForcePoppedMock = new UnityEventListenerMock();

            GameObjectEventStack.ElementEvents eventsOne = new GameObjectEventStack.ElementEvents();
            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();

            GameObjectEventStack.ElementEvents eventsTwo = new GameObjectEventStack.ElementEvents();
            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();

            GameObjectEventStack.ElementEvents eventsThree = new GameObjectEventStack.ElementEvents();
            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);

            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.Push(objectOne);

            Assert.IsTrue(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);

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

            subject.Push(objectTwo);

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

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

            subject.Push(objectThree);

            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.IsTrue(elementThreePushedMock.Received);
            Assert.IsFalse(elementThreePoppedMock.Received);
            Assert.IsFalse(elementThreeForcePoppedMock.Received);

            Object.DestroyImmediate(objectOne);
            Object.DestroyImmediate(objectTwo);
            Object.DestroyImmediate(objectThree);
        }