public void Components_TrackedPoseDriver_EnablesAndDisablesDirectActions() { var positionInput = new InputActionProperty(new InputAction(binding: "<TestHMD>/vector3")); var rotationInput = new InputActionProperty(new InputAction(binding: "<TestHMD>/quaternion")); var go = new GameObject(); var component = go.AddComponent <TrackedPoseDriver>(); component.enabled = false; component.positionInput = positionInput; component.rotationInput = rotationInput; Assert.That(positionInput.action.enabled, Is.False); Assert.That(rotationInput.action.enabled, Is.False); component.enabled = true; Assert.That(positionInput.action.enabled, Is.True); Assert.That(rotationInput.action.enabled, Is.True); component.enabled = false; Assert.That(positionInput.action.enabled, Is.False); Assert.That(rotationInput.action.enabled, Is.False); }
public TouchResponder(int pointerId, InputActionProperty position, InputActionProperty phase) { actionCallback = null; m_ActionsHooked = false; state = new TouchModel(pointerId); m_Position = position; m_Phase = phase; }
public TrackedDeviceResponder(int pointerId, InputActionProperty position, InputActionProperty orientation, InputActionProperty select) { actionCallback = null; m_ActionsHooked = false; state = new TrackedDeviceModel(pointerId); m_Position = position; m_Orientation = orientation; m_Select = select; }
/// <summary> /// Disable the action held on to by the <paramref name="property"/> if it represents /// an <see cref="InputAction"/> directly, meaning not indirectly with an <see cref="InputActionReference"/> /// for an action externally defined in an <see cref="InputActionAsset"/>. /// </summary> /// <param name="property">The property to operate on.</param> /// <remarks> /// This can make it easier to allow the enabled state of the <see cref="InputAction"/> serialized with /// a <see cref="MonoBehaviour"/> to be owned by the behavior itself, but let a reference type be managed /// elsewhere. /// </remarks> public static void DisableDirectAction(this InputActionProperty property) { if (property.reference != null) { return; } property.action?.Disable(); }
private static void SwapAction(ref InputActionProperty property, InputActionProperty newValue, bool actionsHooked, Action <InputAction.CallbackContext> actionCallback) { if (property != null && actionsHooked) { property.action.performed -= actionCallback; property.action.cancelled -= actionCallback; } property = newValue; if (newValue != null && actionsHooked) { property.action.performed += actionCallback; property.action.cancelled += actionCallback; } }
private static void SwapAction(ref InputActionProperty oldProperty, InputActionProperty newProperty, bool actionsHooked, Action <InputAction.CallbackContext> actionCallback) { if (oldProperty != null) { if (actionsHooked) { oldProperty.action.performed -= actionCallback; } } oldProperty = newProperty; if (oldProperty != null) { if (actionsHooked) { oldProperty.action.performed += actionCallback; } } }
private void SwapProperty(ref InputActionProperty oldProperty, InputActionProperty newProperty) { if (oldProperty != null) { if (m_ActionsHooked) { oldProperty.action.performed -= m_ActionCallback; } } oldProperty = newProperty; if (oldProperty != null) { if (m_ActionsHooked) { oldProperty.action.performed += m_ActionCallback; } } }
/// <summary> /// Adds Tracked Device UI responses based the Actions provided. /// </summary> /// <param name="position">A <see cref="Vector3"/> unity world space position that represents the position in the world of the device.</param> /// <param name="orientation">A <see cref="Quaternion"/> rotation value representing the orientation of the device.</param> /// <param name="select">A <see cref="bool"/> selection value that represents whether the user wants to select objects or not.</param> /// <returns>The Pointer Id that represents UI events from this Touch action set.</returns> public int AddTrackedDevice(InputActionProperty position, InputActionProperty orientation, InputActionProperty select) { var id = m_RollingPointerId++; var newResponder = new TrackedDeviceResponder(id, position, orientation, select); var index = m_TrackedDevices.Count; newResponder.actionCallback = delegate(InputAction.CallbackContext context) { OnTrackedDeviceAction(index, context); }; m_TrackedDevices.Add(newResponder); if (m_ActionsHooked) { newResponder.HookActions(); } return(id); }
/// <summary> /// Adds Touch UI responses based the Actions provided. /// </summary> /// <param name="position">A <see cref="Vector2"/> screen space value that represents the position of the touch.</param> /// <param name="phase">A <see cref="PointerPhase"/> value that represents the current state of the touch event.</param> /// <returns>The Pointer Id that represents UI events from this Touch action set.</returns> public int AddTouch(InputActionProperty position, InputActionProperty phase) { var id = m_RollingPointerId++; var newResponder = new TouchResponder(id, position, phase); var index = m_Touches.Count; newResponder.actionCallback = delegate(InputAction.CallbackContext context) { OnTouchAction(index, context); }; m_Touches.Add(newResponder); if (m_ActionsHooked) { newResponder.HookActions(); } return(id); }
public void Components_TrackedPoseDriver_DoesNotEnableOrDisableReferenceActions() { var map = new InputActionMap("map"); map.AddAction("Position", binding: "<TestHMD>/vector3"); map.AddAction("Rotation", binding: "<TestHMD>/quaternion"); var asset = ScriptableObject.CreateInstance <InputActionAsset>(); asset.AddActionMap(map); var positionReference = ScriptableObject.CreateInstance <InputActionReference>(); var rotationReference = ScriptableObject.CreateInstance <InputActionReference>(); positionReference.Set(asset, "map", "Position"); rotationReference.Set(asset, "map", "Rotation"); var positionInput = new InputActionProperty(positionReference); var rotationInput = new InputActionProperty(rotationReference); var go = new GameObject(); var component = go.AddComponent <TrackedPoseDriver>(); component.enabled = false; component.positionInput = positionInput; component.rotationInput = rotationInput; Assert.That(positionInput.action.enabled, Is.False); Assert.That(rotationInput.action.enabled, Is.False); component.enabled = true; Assert.That(positionInput.action.enabled, Is.False); Assert.That(rotationInput.action.enabled, Is.False); component.enabled = false; Assert.That(positionInput.action.enabled, Is.False); Assert.That(rotationInput.action.enabled, Is.False); }
private float GetActionValue(InputActionProperty inputAction) { // Read the float value, this can be a more advanced function with generics return(inputAction.action.ReadValue <float>()); }