Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiple WithCancelingThrough() for PerformInteractiveRebinding()

Discussion in 'Input System' started by HugeWill, Jan 17, 2022.

  1. HugeWill

    HugeWill

    Joined:
    Nov 4, 2016
    Posts:
    27
    Is it possible to have multiple input bindings for cancelling a rebind?

    I want to be able to cancel on both Escape for the keyboard and Start for the gamepad.
     
  2. No, it is not possible as of v1.8 or earlier.

    Code (CSharp):
    1.             /// <summary>
    2.             /// Set the control path that is matched against actuated controls.
    3.             /// </summary>
    4.             /// <param name="binding">A control path (see <see cref="InputControlPath"/>) such as <c>"&lt;Keyboard&gt;/escape"</c>.</param>
    5.             /// <returns>The same RebindingOperation instance.</returns>
    6.             /// <remarks>
    7.             /// Note that every rebind operation has only one such path. Calling this method repeatedly will overwrite
    8.             /// the path set from prior calls.
    9.             ///
    10.             /// <code>
    11.             /// var rebind = new RebindingOperation();
    12.             ///
    13.             /// // Cancel from keyboard escape key.
    14.             /// rebind
    15.             ///     .WithCancelingThrough("&lt;Keyboard&gt;/escape");
    16.             ///
    17.             /// // Cancel from any control with "Cancel" usage.
    18.             /// // NOTE: This can be dangerous. The control that the wants to bind to may have the "Cancel"
    19.             /// //       usage assigned to it, thus making it impossible for the user to bind to the control.
    20.             /// rebind
    21.             ///     .WithCancelingThrough("*/{Cancel}");
    22.             /// </code>
    23.             /// </remarks>
    24.             public RebindingOperation WithCancelingThrough(string binding)
    25.             {
    26.                 ThrowIfRebindInProgress();
    27.                 m_CancelBinding = binding;
    28.                 return this;
    29.             }
    30.  
    31.             public RebindingOperation WithCancelingThrough(InputControl control)
    32.             {
    33.                 ThrowIfRebindInProgress();
    34.                 if (control == null)
    35.                     throw new ArgumentNullException(nameof(control));
    36.                 return WithCancelingThrough(control.path);
    37.             }
    But it is a package, you can always fork it and change it for your own needs if you really want it.