public IEnumerator ScaleWorldDistances([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            // instantiate scene and button
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            yield return(null);

            PressableButton button = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(button);

            // check default value -> default must be using local space in order for the button to scale and function correctly
            Assert.IsTrue(button.DistanceSpaceMode == PressableButton.SpaceMode.Local);

            // Ensure uniform scale, non-zero start push distance, and world space distance
            testButton.transform.localScale = Vector3.one;
            button.DistanceSpaceMode        = PressableButton.SpaceMode.World;
            button.StartPushDistance        = 0.00003f;

            // get the buttons default values for the push planes
            float startPushDistance = button.StartPushDistance;
            float maxPushDistance   = button.MaxPushDistance;
            float pressDistance     = button.PressDistance;
            float releaseDistance   = pressDistance - button.ReleaseDistanceDelta;

            Vector3 zeroPushDistanceWorld = button.GetWorldPositionAlongPushDirection(0.0f);

            Vector3 startPushDistanceWorld = button.GetWorldPositionAlongPushDirection(startPushDistance) - zeroPushDistanceWorld;
            Vector3 maxPushDistanceWorld   = button.GetWorldPositionAlongPushDirection(maxPushDistance) - zeroPushDistanceWorld;
            Vector3 pressDistanceWorld     = button.GetWorldPositionAlongPushDirection(pressDistance) - zeroPushDistanceWorld;
            Vector3 releaseDistanceWorld   = button.GetWorldPositionAlongPushDirection(releaseDistance) - zeroPushDistanceWorld;

            // scale the button in z direction
            // scaling the button while in world space shouldn't influence our button plane distances
            testButton.transform.localScale = new Vector3(1.0f, 1.0f, 2.0f);

            Vector3 zeroPushDistanceWorldScaled = button.GetWorldPositionAlongPushDirection(0.0f);

            Vector3 startPushDistanceWorldScaled = button.GetWorldPositionAlongPushDirection(startPushDistance) - zeroPushDistanceWorldScaled;
            Vector3 maxPushDistanceWorldScaled   = button.GetWorldPositionAlongPushDirection(maxPushDistance) - zeroPushDistanceWorldScaled;
            Vector3 pressDistanceWorldScaled     = button.GetWorldPositionAlongPushDirection(pressDistance) - zeroPushDistanceWorldScaled;
            Vector3 releaseDistanceWorldScaled   = button.GetWorldPositionAlongPushDirection(releaseDistance) - zeroPushDistanceWorldScaled;

            // compare our distances
            Assert.IsTrue(startPushDistanceWorld == startPushDistanceWorldScaled, "Start Distance was modified while scaling button GameObject");
            Assert.IsTrue(maxPushDistanceWorld == maxPushDistanceWorldScaled, "Max Push Distance was modified while scaling button GameObject");
            Assert.IsTrue(pressDistanceWorld == pressDistanceWorldScaled, "Press Distance was modified while scaling button GameObject");
            Assert.IsTrue(releaseDistanceWorld == releaseDistanceWorldScaled, "Release Distance was modified while scaling button GameObject");

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
        public IEnumerator ScaleWorldDistances()
        {
            // instantiate scene and button
            GameObject testButton = InstantiateSceneAndDefaultPressableButton();

            yield return(null);

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);

            testButton.transform.Translate(new Vector3(10.0f, 5.0f, 20.0f));

            PressableButton.SpaceMode distanceMode = buttonComponent.DistanceSpaceMode;
            // check default value -> default must be using world space to not introduce a breaking change to the button
            Assert.IsTrue(distanceMode == PressableButton.SpaceMode.World, "Pressable button default value is using local space distances which introduces a breaking change for existing projects");

            // make sure there's no scale on our button
            testButton.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);

            // set start distance -> default is zero
            buttonComponent.StartPushDistance = 0.00003f;

            // get the buttons default values for the push planes
            float startPushDistance = buttonComponent.StartPushDistance;
            float maxPushDistance   = buttonComponent.MaxPushDistance;
            float pressDistance     = buttonComponent.PressDistance;
            float releaseDistance   = pressDistance - buttonComponent.ReleaseDistanceDelta;

            Vector3 startPushDistanceWorld = buttonComponent.GetWorldPositionAlongPushDirection(startPushDistance);
            Vector3 maxPushDistanceWorld   = buttonComponent.GetWorldPositionAlongPushDirection(maxPushDistance);
            Vector3 pressDistanceWorld     = buttonComponent.GetWorldPositionAlongPushDirection(pressDistance);
            Vector3 releaseDistanceWorld   = buttonComponent.GetWorldPositionAlongPushDirection(releaseDistance);

            // scale the button in z direction
            // scaling the button while in world space shouldn't influence our button plane distances
            testButton.transform.localScale = new Vector3(1.0f, 1.0f, 2.0f);

            Vector3 startPushDistanceWorldScaled = buttonComponent.GetWorldPositionAlongPushDirection(startPushDistance);
            Vector3 maxPushDistanceWorldScaled   = buttonComponent.GetWorldPositionAlongPushDirection(maxPushDistance);
            Vector3 pressDistanceWorldScaled     = buttonComponent.GetWorldPositionAlongPushDirection(pressDistance);
            Vector3 releaseDistanceWorldScaled   = buttonComponent.GetWorldPositionAlongPushDirection(releaseDistance);

            // compare our distances
            Assert.IsTrue(startPushDistanceWorld == startPushDistanceWorldScaled, "Start Distance was modified while scaling button gameobject");
            Assert.IsTrue(maxPushDistanceWorld == maxPushDistanceWorldScaled, "Max Push Distance was modified while scaling button gameobject");
            Assert.IsTrue(pressDistanceWorld == pressDistanceWorldScaled, "Press Distance was modified while scaling button gameobject");
            Assert.IsTrue(releaseDistanceWorld == releaseDistanceWorldScaled, "Release Distance was modified while scaling button gameobject");

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
        public IEnumerator ScaleLocalDistances([ValueSource(nameof(PressableButtonsTestPrefabFilenames))] string prefabFilename)
        {
            // instantiate scene and button
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            yield return(null);

            PressableButton button = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(button);

            // check default value -> default must be using local space in order for the button to scale and function correctly
            Assert.IsTrue(button.DistanceSpaceMode == PressableButton.SpaceMode.Local);

            // make sure there's no scale on our button and non-zero to start push distance
            testButton.transform.localScale = Vector3.one;
            button.StartPushDistance        = 0.00003f;

            float zeroPushDistanceWorld = button.GetWorldPositionAlongPushDirection(0.0f).z;

            // get the buttons default values for the push planes
            float startPushDistanceWorld = button.GetWorldPositionAlongPushDirection(button.StartPushDistance).z - zeroPushDistanceWorld;
            float maxPushDistanceWorld   = button.GetWorldPositionAlongPushDirection(button.MaxPushDistance).z - zeroPushDistanceWorld;
            float pressDistanceWorld     = button.GetWorldPositionAlongPushDirection(button.PressDistance).z - zeroPushDistanceWorld;
            float releaseDistanceWorld   = button.GetWorldPositionAlongPushDirection(button.PressDistance - button.ReleaseDistanceDelta).z - zeroPushDistanceWorld;

            // scale the button in z direction
            // scaling the button while in local space should keep plane distance ratios maintained
            Vector3 zScale = new Vector3(1.0f, 1.0f, 3.6f);

            testButton.transform.localScale = zScale;
            yield return(null);

            float zeroPushDistanceWorld_Scaled = button.GetWorldPositionAlongPushDirection(0.0f).z;

            float startPushDistanceWorld_Scaled = button.GetWorldPositionAlongPushDirection(button.StartPushDistance).z - zeroPushDistanceWorld_Scaled;
            float maxPushDistanceWorld_Scaled   = button.GetWorldPositionAlongPushDirection(button.MaxPushDistance).z - zeroPushDistanceWorld_Scaled;
            float pressDistanceWorld_Scaled     = button.GetWorldPositionAlongPushDirection(button.PressDistance).z - zeroPushDistanceWorld_Scaled;
            float releaseDistanceWorld_Scaled   = button.GetWorldPositionAlongPushDirection(button.PressDistance - button.ReleaseDistanceDelta).z - zeroPushDistanceWorld_Scaled;

            float tolerance = 0.00000001f;

            Assert.IsTrue(AreApproximatelyEqual(startPushDistanceWorld * zScale.z, startPushDistanceWorld_Scaled, tolerance), "Start push distance plane did not scale correctly");
            Assert.IsTrue(AreApproximatelyEqual(maxPushDistanceWorld * zScale.z, maxPushDistanceWorld_Scaled, tolerance), "Max push distance plane did not scale correctly");
            Assert.IsTrue(AreApproximatelyEqual(pressDistanceWorld * zScale.z, pressDistanceWorld_Scaled, tolerance), "Press distance plane did not scale correctly");
            Assert.IsTrue(AreApproximatelyEqual(releaseDistanceWorld * zScale.z, releaseDistanceWorld_Scaled, tolerance), "Release distance plane did not scale correctly");

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a chance to actually destroy the object
            yield return(null);
        }
예제 #4
0
        public IEnumerator ButtonInstantiate()
        {
            GameObject testButton = InstantiateDefaultPressableButton();

            yield return(null);

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
예제 #5
0
    private void Start()
    {
        if (manager != null)
        {
            manager.AddButton(this);
        }
        press       = GetComponent <PressableButton>();
        illuminator = GetComponent <IlluminatingObject>();

        if (illuminator != null && changeIlluminationWithPress)
        {
            illuminator.Illuminate();
        }
    }
예제 #6
0
        public IEnumerator ButtonInstantiate([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            yield return(null);

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
예제 #7
0
        public IEnumerator PressButtonWithHand()
        {
            GameObject testButton = InstantiateDefaultPressableButton();

            // Move the camera to origin looking at +z to more easily see the button.
            TestUtilities.PlayspaceToOriginLookingForward();

            // For some reason, we would only get null pointers when the hand tries to click a button
            // at specific positions, hence the unusal z value.
            testButton.transform.position = new Vector3(0, 0, 1.067121f);
            // The scale of the button was also unusual in the repro case
            testButton.transform.localScale = Vector3.one * 1.5f;

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);

            bool buttonPressed = false;

            buttonComponent.ButtonPressed.AddListener(() =>
            {
                buttonPressed = true;
            });

            // Move the hand forward to press button, then off to the right
            var     inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();
            int     numSteps = 30;
            Vector3 p1       = new Vector3(0, 0, 0.5f);
            Vector3 p2       = new Vector3(0, 0, 1.08f);
            Vector3 p3       = new Vector3(0.1f, 0, 1.08f);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHandFromTo(p1, p2, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHandFromTo(p2, p3, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService));

            Assert.IsTrue(buttonPressed, "Button did not get pressed when hand moved to press it.");

            Object.Destroy(testButton);

            yield return(null);
        }
예제 #8
0
    protected override void RegistKey()
    {
        PressableButton pressableButton = this.GetComponent <PressableButton>();
        TouchableButton touchableButton = this.GetComponent <TouchableButton>();

        if (pressableButton && touchableButton)
        {
            InteractionEvent interActionEvent = new InteractionEvent();
            interActionEvent.AddListener(OnSpecialKeyClick);
            pressableButton.Triggers.Add(new InteractionPressableEntry()
            {
                eventID = InteractionPressableType.PointerClick, callback = interActionEvent
            });
            touchableButton.Triggers.Add(new InteractionTouchableEntry()
            {
                eventID = InteractionTouchableType.PokePress, callback = interActionEvent
            });
        }
    }
예제 #9
0
        public IEnumerator DisablePressableButton([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            // Move the camera to origin looking at +z to more easily see the button.
            TestUtilities.PlayspaceToOriginLookingForward();

            // For some reason, we would only get null pointers when the hand tries to click a button
            // at specific positions, hence the unusual z value.
            testButton.transform.position = new Vector3(0, 0, 1.067121f);
            // The scale of the button was also unusual in the repro case
            testButton.transform.localScale = Vector3.one * 1.5f;

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);

            bool buttonPressed = false;

            buttonComponent.ButtonPressed.AddListener(() =>
            {
                buttonPressed = true;
            });

            yield return(null);

            // Test pressing button with hand when disabled
            testButton.SetActive(false);
            yield return(PressButtonWithHand());

            Assert.IsFalse(buttonPressed, "Button got pressed when component was disabled.");

            // Test pressing button with hand when enabled
            testButton.SetActive(true);
            yield return(PressButtonWithHand());

            Assert.IsTrue(buttonPressed, "Button did not get pressed when hand moved to press it.");

            Object.Destroy(testButton);

            yield return(null);
        }
예제 #10
0
        public IEnumerator PressButtonWhenSecondButtonIsNearby([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            GameObject testButton1 = InstantiateDefaultPressableButton(prefabFilename);
            GameObject testButton2 = InstantiateDefaultPressableButton(prefabFilename);

            // Move the camera to origin looking at +z to more easily see the button.
            TestUtilities.PlayspaceToOriginLookingForward();

            PressableButton buttonComponent = testButton1.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);
            Assert.IsTrue(buttonComponent.EnforceFrontPush, "Button default behavior should have enforce front push enabled");

            // Positioning the start push plane of the second button just before first button max push plane, creating a small overlap
            float distance = Mathf.Abs(buttonComponent.MaxPushDistance) + Mathf.Abs(buttonComponent.StartPushDistance);

            distance = buttonComponent.DistanceSpaceMode == SpaceMode.Local ? distance * buttonComponent.LocalToWorldScale : distance;
            testButton2.transform.position += Vector3.forward * distance;

            bool buttonPressed = false;

            buttonComponent.ButtonPressed.AddListener(() =>
            {
                buttonPressed = true;
            });

            // Move the hand so the pointer passes through the two buttons
            TestHand hand      = new TestHand(Handedness.Right);
            float    handReach = 0.1f;
            int      numSteps  = (int)Mathf.Ceil(handReach / (distance * 0.5f)); // Maximum hand speed in order to trigger touch started in the first button before the second button becomes the closest touchable to pointer

            yield return(hand.Show(new Vector3(0, 0, -handReach / 2)));

            yield return(hand.Move(new Vector3(0, 0, handReach), numSteps));

            Assert.IsTrue(buttonPressed, "Button did not get pressed when a second button is nearby");

            Object.Destroy(testButton1);
            Object.Destroy(testButton2);

            yield return(null);
        }
예제 #11
0
        public IEnumerator ButtonInstantiateDisableThenEnableBeforeStart([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            // Disable then re-enable the button in the same frame as it was instantiated, so that Start() does not execute.
            testButton.SetActive(false);
            testButton.SetActive(true);

            yield return(null);

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            var deltaPosition = GetBackPlateToFrontPlateVector(buttonComponent);

            Assert.IsTrue(deltaPosition.magnitude > 0.007f, "The button prefabs should all have their front plates at least 8mm away from the back plates.");

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
        private void OnEnable()
        {
            button    = (PressableButton)target;
            transform = button.transform;

            if (labelStyle == null)
            {
                labelStyle = new GUIStyle();
                labelStyle.normal.textColor = Color.white;
            }

            movingButtonVisuals  = serializedObject.FindProperty("movingButtonVisuals");
            distanceSpaceMode    = serializedObject.FindProperty("distanceSpaceMode");
            startPushDistance    = serializedObject.FindProperty("startPushDistance");
            maxPushDistance      = serializedObject.FindProperty("maxPushDistance");
            pressDistance        = serializedObject.FindProperty("pressDistance");
            releaseDistanceDelta = serializedObject.FindProperty("releaseDistanceDelta");

            touchable = button.GetComponent <NearInteractionTouchableSurface>();
        }
예제 #13
0
        private void OnEnable()
        {
            button    = (PressableButton)target;
            transform = button.transform;
            touchCage = button.GetComponent <BoxCollider>();

            if (labelStyle == null)
            {
                labelStyle = new GUIStyle();
                labelStyle.normal.textColor = Color.white;
            }

            maxPushDistance      = serializedObject.FindProperty("maxPushDistance");
            pressDistance        = serializedObject.FindProperty("pressDistance");
            releaseDistanceDelta = serializedObject.FindProperty("releaseDistanceDelta");
            movingButtonVisuals  = serializedObject.FindProperty("movingButtonVisuals");

            boxColliderObject = new SerializedObject(touchCage);
            boxColliderSize   = boxColliderObject.FindProperty("m_Size");
            boxColliderCenter = boxColliderObject.FindProperty("m_Center");
        }
예제 #14
0
        public IEnumerator PressButtonFast([ValueSource(nameof(PressableButtonsTestPrefabFilenames))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            // Move the camera to origin looking at +z to more easily see the button.
            TestUtilities.PlayspaceToOriginLookingForward();

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);
            Assert.IsTrue(buttonComponent.EnforceFrontPush, "Button default behavior should have enforce front push enabled");

            bool buttonPressed = false;

            buttonComponent.ButtonPressed.AddListener(() =>
            {
                buttonPressed = true;
            });

            // move the hand quickly from very far distance into the button and check if it was pressed
            var     inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();
            int     numSteps = 2;
            Vector3 p1       = new Vector3(0, 0, -20.0f);
            Vector3 p2       = new Vector3(0, 0, 0.02f);

            yield return(PlayModeTestUtilities.ShowHand(Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.MoveHandFromTo(p1, p2, numSteps, ArticulatedHandPose.GestureId.Open, Handedness.Right, inputSimulationService));

            yield return(PlayModeTestUtilities.HideHand(Handedness.Right, inputSimulationService));

            Assert.IsTrue(buttonPressed, "Button did not get pressed when hand moved to press it.");

            Object.Destroy(testButton);

            yield return(null);
        }
 private void Start()
 {
     manager.Subscribe(this);
     press = GetComponent <PressableButton> ();
 }
예제 #16
0
 private void Start()
 {
     press = GetComponent <PressableButton>();
 }
예제 #17
0
        public IEnumerator ReleaseButton([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            TestUtilities.PlayspaceToOriginLookingForward();

            PressableButton buttonComponent = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(buttonComponent);

            bool buttonPressed = false;

            buttonComponent.ButtonPressed.AddListener(() =>
            {
                buttonPressed = true;
            });

            bool buttonReleased = false;

            buttonComponent.ButtonReleased.AddListener(() =>
            {
                buttonReleased = true;
            });

            Vector3  startHand          = new Vector3(0, 0, -0.0081f);
            Vector3  inButtonOnPress    = new Vector3(0, 0, 0.002f);     // past press plane of mrtk pressablebutton prefab
            Vector3  rightOfButtonPress = new Vector3(0.02f, 0, 0.002f); // right of press plane, outside button
            Vector3  inButtonOnRelease  = new Vector3(0, 0, -0.0015f);   // release plane of mrtk pressablebutton prefab
            TestHand hand = new TestHand(Handedness.Right);

            // test scenarios in normal and low framerate
            int[] stepVariations = { 30, 2 };
            for (int i = 0; i < stepVariations.Length; ++i)
            {
                int numSteps = stepVariations[i];

                // test release
                yield return(hand.Show(startHand));

                yield return(hand.MoveTo(inButtonOnPress, numSteps));

                yield return(hand.MoveTo(inButtonOnRelease, numSteps));

                yield return(hand.Hide());

                Assert.IsTrue(buttonPressed, $"A{i} - Button did not get pressed when hand moved to press it.");
                Assert.IsTrue(buttonReleased, $"A{i} - Button did not get released.");

                buttonPressed  = false;
                buttonReleased = false;

                Assert.IsTrue(buttonComponent.ReleaseOnTouchEnd == true, "default behavior of button should be release on touch end");

                // test release on moving outside of button
                yield return(hand.Show(startHand));

                yield return(hand.MoveTo(inButtonOnPress, numSteps));

                yield return(hand.MoveTo(rightOfButtonPress, numSteps));

                yield return(hand.Hide());

                Assert.IsTrue(buttonPressed, $"B{i} - Button did not get pressed when hand moved to press it.");
                Assert.IsTrue(buttonReleased, $"B{i} - Button did not get released when hand exited the button.");

                buttonPressed  = false;
                buttonReleased = false;

                buttonComponent.ReleaseOnTouchEnd = false;

                // test no release on moving outside of button when releaseOnTouchEnd is disabled
                yield return(hand.Show(startHand));

                yield return(hand.MoveTo(inButtonOnPress, numSteps));

                yield return(hand.MoveTo(rightOfButtonPress, numSteps));

                yield return(hand.Hide());

                Assert.IsTrue(buttonPressed, $"C{i} - Button did not get pressed when hand moved to press it.");
                Assert.IsFalse(buttonReleased, $"C{i} - Button did got released on exit even though releaseOnTouchEnd wasn't set");

                buttonPressed  = false;
                buttonReleased = false;

                buttonComponent.ReleaseOnTouchEnd = true;
            }

            Object.Destroy(testButton);

            yield return(null);
        }
예제 #18
0
        public IEnumerator SwitchWorldToLocalDistanceMode([ValueSource(nameof(PressableButtonsTestPrefabPaths))] string prefabFilename)
        {
            // instantiate scene and button
            GameObject testButton = InstantiateDefaultPressableButton(prefabFilename);

            yield return(null);

            PressableButton button = testButton.GetComponent <PressableButton>();

            Assert.IsNotNull(button);

            // check default value -> default must be using local space in order for the button to scale and function correctly
            Assert.IsTrue(button.DistanceSpaceMode == PressableButton.SpaceMode.Local);

            // add scale to our button so we can compare world to local distances
            testButton.transform.localScale = new Vector3(1.0f, 1.0f, 2.0f);
            button.StartPushDistance        = 0.00003f;

            // get the buttons default values for the push planes
            float startPushDistanceLocal = button.StartPushDistance;
            float maxPushDistanceLocal   = button.MaxPushDistance;
            float pressDistanceLocal     = button.PressDistance;
            float releaseDistanceLocal   = pressDistanceLocal - button.ReleaseDistanceDelta;

            // get world space positions for local distances
            Vector3 startPushDistanceWorldLocal = button.GetWorldPositionAlongPushDirection(startPushDistanceLocal);
            Vector3 maxPushDistanceWorldLocal   = button.GetWorldPositionAlongPushDirection(maxPushDistanceLocal);
            Vector3 pressDistanceWorldLocal     = button.GetWorldPositionAlongPushDirection(pressDistanceLocal);
            Vector3 releaseDistanceWorldLocal   = button.GetWorldPositionAlongPushDirection(releaseDistanceLocal);

            // switch to world space
            button.DistanceSpaceMode = PressableButton.SpaceMode.World;

            float startPushDistance = button.StartPushDistance;
            float maxPushDistance   = button.MaxPushDistance;
            float pressDistance     = button.PressDistance;
            float releaseDistance   = pressDistance - button.ReleaseDistanceDelta;

            // check if distances have changed
            Assert.IsFalse(startPushDistance == startPushDistanceLocal, "Switching from world to local space distances didn't adjust the plane coords");
            Assert.IsFalse(maxPushDistance == maxPushDistanceLocal, "Switching from world to local space distances didn't adjust the plane coords");
            Assert.IsFalse(pressDistance == pressDistanceLocal, "Switching from world to local space distances didn't adjust the plane coords");
            Assert.IsFalse(releaseDistance == releaseDistanceLocal, "Switching from world to local space distances didn't adjust the plane coords");

            // get world space positions for local distances
            Vector3 startPushDistanceWorld = button.GetWorldPositionAlongPushDirection(startPushDistance);
            Vector3 maxPushDistanceWorld   = button.GetWorldPositionAlongPushDirection(maxPushDistance);
            Vector3 pressDistanceWorld     = button.GetWorldPositionAlongPushDirection(pressDistance);
            Vector3 releaseDistanceWorld   = button.GetWorldPositionAlongPushDirection(releaseDistance);

            // compare world space distances -> local and world space mode should return us the same world space positions
            Assert.IsTrue(startPushDistanceWorld == startPushDistanceWorldLocal, "World and Local World positions don't match after switching pressable button distance mode");
            Assert.IsTrue(maxPushDistanceWorld == maxPushDistanceWorldLocal, "World and Local World positions don't match after switching pressable button distance mode");
            Assert.IsTrue(pressDistanceWorld == pressDistanceWorldLocal, "World and Local World positions don't match after switching pressable button distance mode");
            Assert.IsTrue(releaseDistanceWorld == releaseDistanceWorldLocal, "World and Local World positions don't match after switching pressable button distance mode");

            // switch back to local space
            button.DistanceSpaceMode = PressableButton.SpaceMode.Local;

            // distances must match up with original values
            Assert.IsTrue(startPushDistanceLocal == button.StartPushDistance, "Conversion from local to world distances didn't return the correct world distances");
            Assert.IsTrue(maxPushDistanceLocal == button.MaxPushDistance, "Conversion from local to world distances didn't return the correct world distances");
            Assert.IsTrue(pressDistanceLocal == button.PressDistance, "Conversion from local to world distances didn't return the correct world distances");
            float newReleaseDistance = button.PressDistance - button.ReleaseDistanceDelta;

            Assert.IsTrue(releaseDistanceLocal == newReleaseDistance, "Conversion from local to world distances didn't return the correct world distances");

            Object.Destroy(testButton);
            // Wait for a frame to give Unity a change to actually destroy the object
            yield return(null);
        }
 /// <summary>Attaches this instance to the specified <see cref="PressableButton"/>, allowing events to be received from the button.</summary>
 public void Attach(PressableButton button) => button.parentComponent = this;
예제 #20
0
 private bool isASharedButton(PressableButton button)
 {
     return(button.name != "ButtonPin" && button.name != "ChangeMenuType");
 }
예제 #21
0
 private bool isASharedButton(PressableButton button)
 {
     return(button.name != Constants.BUTTON_PIN_NAME && button.name != Constants.CHANGE_MENU_BUTTON_NAME);
 }