// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; namespace Microsoft.MixedReality.Toolkit.Input { /// /// Struct storing the states of buttons on the motion controller /// public struct SimulatedMotionControllerButtonState : IEquatable { /// /// Whether the motion controller is selecting (i.e. the trigger button is being pressed) /// public bool IsSelecting; /// /// Whether the motion controller is grabbing (i.e. the grab button is being pressed) /// public bool IsGrabbing; /// /// Whether the menu button on the motion controller is being pressed /// public bool IsPressingMenu; public override bool Equals(object obj) { if (obj is SimulatedMotionControllerButtonState state) { return Equals(state); } return false; } public bool Equals(SimulatedMotionControllerButtonState state) { return IsSelecting == state.IsSelecting && IsGrabbing == state.IsGrabbing && IsPressingMenu == state.IsPressingMenu; } public override int GetHashCode() { return (IsSelecting ? 1 : 0) * 100 + (IsGrabbing ? 1 : 0) * 10 + (IsPressingMenu ? 1 : 0); } public static bool operator ==(SimulatedMotionControllerButtonState lhs, SimulatedMotionControllerButtonState rhs) { return lhs.Equals(rhs); } public static bool operator !=(SimulatedMotionControllerButtonState lhs, SimulatedMotionControllerButtonState rhs) { return !(lhs.Equals(rhs)); } } }