コード例 #1
0
        public IEnumerator TestAddingAndSettingNewState()
        {
            // Create an interactive cube
            InteractiveElement interactiveElement = CreateInteractiveCube();

            yield return(null);

            // Create a new state and add it to Tracked States
            interactiveElement.AddNewState(newStateName);

            // Change the value of my new state by using the focus state events to set the new state
            InteractionState focusState = interactiveElement.GetState(CoreInteractionState.Focus.ToString());

            var focusEventConfiguration = interactiveElement.GetStateEvents <FocusEvents>(focusStateName);

            yield return(null);

            focusEventConfiguration.OnFocusOn.AddListener((focusEventData) =>
            {
                // When the object comes into focus, set my new state to on
                interactiveElement.SetStateOn(newStateName);
            });

            focusEventConfiguration.OnFocusOff.AddListener((focusEventData) =>
            {
                // When the object comes out of  focus, set my new state to off
                interactiveElement.SetStateOff(newStateName);
            });

            // Make sure MyNewState is being tracked
            InteractionState myNewState = interactiveElement.GetState(newStateName);

            Assert.IsNotNull(myNewState);

            // Make sure the value is 0/off initially
            Assert.AreEqual(0, myNewState.Value);

            // Create a new hand and initialize it with an object in focus
            var leftHand = new TestHand(Handedness.Left);

            yield return(ShowHandWithObjectInFocus(leftHand));

            // Make sure the value of MyNewState was changed when the object is in focus
            Assert.AreEqual(1, myNewState.Value);

            // Move hand away from object to remove focus
            yield return(MoveHandOutOfFocus(leftHand));

            // Make sure the value of MyNewState was changed when the object is no longer in focus
            Assert.AreEqual(0, myNewState.Value);
        }
コード例 #2
0
        public IEnumerator TestEventConfigOfNewState()
        {
            // Create an interactive cube
            InteractiveElement interactiveElement = CreateInteractiveCube();

            yield return(null);

            // Create a new state
            interactiveElement.AddNewState(newStateName);

            // Get the event configuration
            var eventConfiguration = interactiveElement.GetStateEvents <StateEvents>(newStateName);

            bool onStateOn  = false;
            bool onStateOff = false;

            eventConfiguration.OnStateOn.AddListener(() =>
            {
                onStateOn = true;
            });

            eventConfiguration.OnStateOff.AddListener(() =>
            {
                onStateOff = true;
            });

            interactiveElement.SetStateOn(newStateName);
            yield return(null);

            // Check if OnFocusOn has fired
            Assert.True(onStateOn);

            interactiveElement.SetStateOff(newStateName);
            yield return(null);

            // Check if OnFocusOn has fired
            Assert.True(onStateOff);

            yield return(null);
        }
コード例 #3
0
        public IEnumerator TestDefaultStateSetting()
        {
            // Create an interactive cube
            InteractiveElement interactiveElement = CreateInteractiveCube();

            yield return(null);

            int newStateCount = 5;

            // Add new states
            for (int i = 0; i < newStateCount; i++)
            {
                interactiveElement.AddNewState("State" + i.ToString());
                yield return(null);
            }

            // The Default state should only be active if no other states are active
            Assert.True(interactiveElement.IsStateActive(defaultStateName));

            // Set each new states to active
            for (int i = 0; i < newStateCount; i++)
            {
                interactiveElement.SetStateOn("State" + i.ToString());

                // If any other state is active, the Default state should not be active
                Assert.False(interactiveElement.IsStateActive(defaultStateName));
            }

            // Set all states to not be active
            for (int i = 0; i < newStateCount; i++)
            {
                interactiveElement.SetStateOff("State" + i.ToString());
            }

            yield return(null);

            // After all the states are deactivated, the Default state should be active
            Assert.True(interactiveElement.IsStateActive(defaultStateName));
        }