2
0

EditorVirtualInput.cs 3.2 KB

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