public IEnumerator TestCompressableButtonCube() { // Instantiate the CompressableCubeButton prefab CompressableButton compressableButton = InstantiateCompressablePrefab(compressableCubeButtonPrefabPath); InteractionState pressedNearState = compressableButton.GetState(pressedNearStateName); InteractionState touchState = compressableButton.GetState(touchStateName); var pressedNearEvents = compressableButton.GetStateEvents <PressedNearEvents>("PressedNear"); bool buttonPressed = false; bool buttonHold = false; bool buttonReleased = false; // Add PressedNear state event listeners pressedNearEvents.OnButtonPressed.AddListener(() => { buttonPressed = true; }); pressedNearEvents.OnButtonPressHold.AddListener(() => { buttonHold = true; }); pressedNearEvents.OnButtonPressReleased.AddListener(() => { buttonReleased = true; }); // Create a new hand and initialize it with an object in focus var leftHand = new TestHand(Handedness.Left); yield return(ShowHandWithObjectInFocus(leftHand)); // Move hand to press compressable button, which will set the PressedNear state to on yield return(MoveHandPressObject(leftHand)); // Make sure the event listeners were triggered and that the PressedNear and Touch state are on Assert.True(buttonPressed); Assert.True(buttonHold); Assert.AreEqual(pressedNearState.Value, 1); Assert.AreEqual(touchState.Value, 1); yield return(MoveHandOutOfFocus(leftHand)); yield return(PlayModeTestUtilities.WaitForInputSystemUpdate()); // Make sure button released event was triggered and states are set to off Assert.True(buttonReleased); Assert.AreEqual(pressedNearState.Value, 0); Assert.AreEqual(touchState.Value, 0); }
protected override void OnEnable() { base.OnEnable(); button = (CompressableButton)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>(); }