EditorVirtualInput.cs 2.9 KB

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