InputTools.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using UnityEngine;
  3. namespace ICODES.STUDIO.WWebView
  4. {
  5. public static class InputTools
  6. {
  7. public static bool GetMouseState(ref int state, ref int key)
  8. {
  9. if (InputTools.DidMouseMove())
  10. {
  11. state = 0;
  12. return true;
  13. }
  14. for (key = 0; key < 3; key++)
  15. {
  16. if (InputTools.DidMouseClick(ref state, ref key))
  17. {
  18. return true;
  19. }
  20. }
  21. if (InputTools.DidMouseWheel(ref key))
  22. {
  23. state = 3;
  24. return true;
  25. }
  26. return false;
  27. }
  28. public static bool DidMouseClick(ref int state, ref int key)
  29. {
  30. if (Input.GetMouseButtonDown(key))
  31. {
  32. state = 1;
  33. return true;
  34. }
  35. if (Input.GetMouseButtonUp(key))
  36. {
  37. state = 2;
  38. return true;
  39. }
  40. return false;
  41. }
  42. public static bool DidMouseMove()
  43. {
  44. return Input.GetAxis("Mouse X") != 0f || Input.GetAxis("Mouse Y") != 0f;
  45. }
  46. public static bool DidMouseWheel(ref int key)
  47. {
  48. if (Input.GetAxis("Mouse ScrollWheel") > 0f)
  49. {
  50. key = 1;
  51. return true;
  52. }
  53. if (Input.GetAxis("Mouse ScrollWheel") < 0f)
  54. {
  55. key = -1;
  56. return true;
  57. }
  58. return false;
  59. }
  60. private enum Event
  61. {
  62. MouseMove,
  63. MouseDown,
  64. MouseUp,
  65. MouseWheel
  66. }
  67. }
  68. }