EditorVirtualInput.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System.Runtime.CompilerServices;
  4. namespace bs
  5. {
  6. /** @addtogroup Input-Editor
  7. * @{
  8. */
  9. /// <summary>
  10. /// Handles virtual input that allows you to receive virtual input events that hide the actual physical input, allowing
  11. /// you to easily change the input keys while being transparent to the external code.
  12. /// </summary>
  13. /// <summary>
  14. /// Companion class to <see cref="VirtualInput"/> for use in editor only. Supplies events that trigger regardless
  15. /// whether game is playing or not (unlike <see cref="VirtualInput"/>) which makes them usable for editor only scripts.
  16. /// Pollable input and other functionality should still be accessed on <see cref="VirtualInput"/>.
  17. /// </summary>
  18. public static class EditorVirtualInput
  19. {
  20. public delegate void OnButtonEventDelegate(VirtualButton btn, int deviceIdx);
  21. /// <summary>
  22. /// Triggered when a physical button combination corresponding to a virtual button is pressed.
  23. /// </summary>
  24. public static event OnButtonEventDelegate OnButtonDown;
  25. /// <summary>
  26. /// Triggered when a physical button combination corresponding to a virtual button is released.
  27. /// </summary>
  28. public static event OnButtonEventDelegate OnButtonUp;
  29. /// <summary>
  30. /// Triggered every frame while a physical button combination corresponding to a virtual button is being held down.
  31. /// </summary>
  32. public static event OnButtonEventDelegate OnButtonHeld;
  33. /// <summary>
  34. /// Triggered by the runtime when the virtual button is pressed.
  35. /// </summary>
  36. /// <param name="button">Virtual button that was pressed.</param>
  37. /// <param name="deviceIdx">Index of the device the button was pressed on.</param>
  38. private static void Internal_TriggerButtonDown(VirtualButton button, int deviceIdx)
  39. {
  40. if (OnButtonDown != null)
  41. OnButtonDown(button, deviceIdx);
  42. }
  43. /// <summary>
  44. /// Triggered by the runtime when the virtual button is released.
  45. /// </summary>
  46. /// <param name="button">Virtual button that was released.</param>
  47. /// <param name="deviceIdx">Index of the device the button was released on.</param>
  48. private static void Internal_TriggerButtonUp(VirtualButton button, int deviceIdx)
  49. {
  50. if (OnButtonUp != null)
  51. OnButtonUp(button, deviceIdx);
  52. }
  53. /// <summary>
  54. /// Triggered by the runtime every frame while a virtual button is being held down.
  55. /// </summary>
  56. /// <param name="button">Virtual button that is being held down.</param>
  57. /// <param name="deviceIdx">Index of the device the button is being held down on.</param>
  58. private static void Internal_TriggerButtonHeld(VirtualButton button, int deviceIdx)
  59. {
  60. if (OnButtonHeld != null)
  61. OnButtonHeld(button, deviceIdx);
  62. }
  63. };
  64. /** @} */
  65. }