From 78493238e399054da8d37720839ee943837e9447 Mon Sep 17 00:00:00 2001 From: Drahsid Date: Mon, 22 Feb 2021 12:19:26 -0500 Subject: [PATCH] Added the ability to retrieve a mouse button by it's MouseButton enumeration, akin to the functionality that Gamepad has. --- .../InputSystem/Devices/Mouse.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/Mouse.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/Mouse.cs index bdd1556cda..ff57574814 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/Mouse.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/Mouse.cs @@ -1,3 +1,4 @@ +using System.ComponentModel; using System.Runtime.InteropServices; using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.Layouts; @@ -223,6 +224,30 @@ public class Mouse : Pointer, IInputStateCallbackReceiver /// Control representing the mouse click count. public IntegerControl clickCount { get; protected set; } + /// + /// Retrieve a mouse button by its enumeration + /// constant. + /// + /// Button to retrieve. + /// is not a valid mouse + /// button value. + 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)); + } + } + } + /// /// The mouse that was added or updated last or null if there is no mouse /// connected to the system.