docs.unity3d.com
    目次を表示する/隠す

    Class ButtonWithOneModifier

    A button with an additional modifier. The button only triggers when the modifier is pressed.

    Inheritance
    Object
    InputBindingComposite
    InputBindingComposite<Single>
    ButtonWithOneModifier
    Inherited Members
    InputBindingComposite<Single>.valueType
    InputBindingComposite<Single>.valueSizeInBytes
    InputBindingComposite<Single>.ReadValue(InputBindingCompositeContext, Void*, Int32)
    InputBindingComposite<Single>.ReadValueAsObject(InputBindingCompositeContext)
    InputBindingComposite.GetExpectedControlLayoutName(String, String)
    Namespace: UnityEngine.InputSystem.Composites
    Syntax
    [DisplayStringFormat("{modifier}+{button}")]
    public class ButtonWithOneModifier : InputBindingComposite<float>
    Remarks

    This composite can be used to require another button to be held while pressing the button that triggers the action. This is most commonly used on keyboards to require one of the modifier keys (shift, ctrl, or alt) to be held in combination with another key, e.g. "CTRL+1".

    // Create a button action that triggers when CTRL+1
    // is pressed on the keyboard.
    var action = new InputAction(type: InputActionType.Button);
    action.AddCompositeBinding("ButtonWithOneModifier")
        .With("Modifier", "<Keyboard>/leftCtrl")
        .With("Modifier", "<Keyboard>/rightControl")
        .With("Button", "<Keyboard>/1")

    Note that this is not restricted to the keyboard and will preserve the full value of the button.

    // Create a button action that requires the A button on the
    // gamepad to be held and will then trigger from the gamepad's
    // left trigger button.
    var action = new InputAction(type: InputActionType.Button);
    action.AddCompositeBinding("ButtonWithOneModifier")
        .With("Modifier", "<Gamepad>/buttonSouth")
        .With("Button", "<Gamepad>/leftTrigger");

    Fields

    button

    Binding for the button that is gated by the modifier. The composite will assume the value of this button while the modifier is pressed.

    Declaration
    public int button
    Field Value
    Type Description
    Int32

    Part index to use with ReadValue<TValue>(Int32).

    Remarks

    This property is automatically assigned by the input system.

    modifier

    Binding for the button that acts as a modifier, e.g. <Keyboard/leftCtrl.

    Declaration
    public int modifier
    Field Value
    Type Description
    Int32

    Part index to use with ReadValue<TValue>(Int32).

    Remarks

    This property is automatically assigned by the input system.

    overrideModifiersNeedToBePressedFirst

    If set to true, modifier can be pressed after button and the composite will still trigger. Default is false.

    Declaration
    public bool overrideModifiersNeedToBePressedFirst
    Field Value
    Type Description
    Boolean
    Remarks

    By default, modifier is required to be in pressed state before or at the same time that button goes into pressed state for the composite as a whole to trigger. This means that binding to, for example, Shift+B, the shift key has to be pressed before pressing the B key. This is the behavior usually expected with keyboard shortcuts.

    This parameter can be used to bypass this behavior and allow any timing between modifier and button. The only requirement is for them both to concurrently be in pressed state.

    Methods

    EvaluateMagnitude(ref InputBindingCompositeContext)

    Same as ReadValue(ref InputBindingCompositeContext) in this case.

    Declaration
    public override float EvaluateMagnitude(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context

    Evaluation context passed in from the input system.

    Returns
    Type Description
    Single

    A >0 value if the composite is currently actuated.

    Overrides
    InputBindingComposite.EvaluateMagnitude(ref InputBindingCompositeContext)

    FinishSetup(ref InputBindingCompositeContext)

    Declaration
    protected override void FinishSetup(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context
    Overrides
    InputBindingComposite.FinishSetup(ref InputBindingCompositeContext)

    ReadValue(ref InputBindingCompositeContext)

    Return the value of the button part if modifier is pressed. Otherwise return 0.

    Declaration
    public override float ReadValue(ref InputBindingCompositeContext context)
    Parameters
    Type Name Description
    InputBindingCompositeContext context

    Evaluation context passed in from the input system.

    Returns
    Type Description
    Single

    The current value of the composite.

    Overrides
    UnityEngine.InputSystem.InputBindingComposite<System.Single>.ReadValue(UnityEngine.InputSystem.InputBindingCompositeContext)

    See Also

    ButtonWithTwoModifiers
    トップに戻る
    Copyright © 2023 Unity Technologies — 商標と利用規約
    • 法律関連
    • プライバシーポリシー
    • クッキー
    • 私の個人情報を販売または共有しない
    • Your Privacy Choices (Cookie Settings)