Skip to content

Added the ability to retrieve a mouse button by it's MouseButton enum #1273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Packages/com.unity.inputsystem/InputSystem/Devices/Mouse.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.ComponentModel;
using System.Runtime.InteropServices;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.Layouts;
Expand Down Expand Up @@ -223,6 +224,30 @@ public class Mouse : Pointer, IInputStateCallbackReceiver
/// <value>Control representing the mouse click count.</value>
public IntegerControl clickCount { get; protected set; }

/// <summary>
/// Retrieve a mouse button by its <see cref="MouseButton"/> enumeration
/// constant.
/// </summary>
/// <param name="button">Button to retrieve.</param>
/// <exception cref="InvalidEnumArgumentException"><paramref name="button"/> is not a valid mouse
/// button value.</exception>
public ButtonControl this[MouseButton button]
{
get
{
switch (button)
{
case MouseButton.Left: return leftButton;
case MouseButton.Right: return rightButton;
case MouseButton.Middle: return middleButton;
case MouseButton.Forward: return forwardButton;
case MouseButton.Back: return backButton;
default:
throw new InvalidEnumArgumentException(nameof(button), (int)button, typeof(MouseButton));
}
}
}

/// <summary>
/// The mouse that was added or updated last or null if there is no mouse
/// connected to the system.
Expand Down