InputEvent.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using UnityEngine;
  2. namespace FairyGUI
  3. {
  4. /// <summary>
  5. ///
  6. /// </summary>
  7. public class InputEvent
  8. {
  9. /// <summary>
  10. /// x position in stage coordinates.
  11. /// </summary>
  12. public float x { get; internal set; }
  13. /// <summary>
  14. /// y position in stage coordinates.
  15. /// </summary>
  16. public float y { get; internal set; }
  17. /// <summary>
  18. ///
  19. /// </summary>
  20. public KeyCode keyCode { get; internal set; }
  21. /// <summary>
  22. ///
  23. /// </summary>
  24. public char character { get; internal set; }
  25. /// <summary>
  26. ///
  27. /// </summary>
  28. public EventModifiers modifiers { get; internal set; }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. public float mouseWheelDelta { get; internal set; }
  33. /// <summary>
  34. ///
  35. /// </summary>
  36. public int touchId { get; internal set; }
  37. /// <summary>
  38. /// -1-none,0-left,1-right,2-middle
  39. /// </summary>
  40. public int button { get; internal set; }
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. /// <value></value>
  45. public int clickCount { get; internal set; }
  46. /// <summary>
  47. /// Duraion of holding the button. You can read this in touchEnd or click event.
  48. /// </summary>
  49. /// <value></value>
  50. public float holdTime { get; internal set; }
  51. public InputEvent()
  52. {
  53. touchId = -1;
  54. x = 0;
  55. y = 0;
  56. clickCount = 0;
  57. keyCode = KeyCode.None;
  58. character = '\0';
  59. modifiers = 0;
  60. mouseWheelDelta = 0;
  61. }
  62. /// <summary>
  63. ///
  64. /// </summary>
  65. public Vector2 position
  66. {
  67. get { return new Vector2(x, y); }
  68. }
  69. /// <summary>
  70. ///
  71. /// </summary>
  72. public bool isDoubleClick
  73. {
  74. get { return clickCount > 1 && button == 0; }
  75. }
  76. /// <summary>
  77. ///
  78. /// </summary>
  79. public bool ctrlOrCmd
  80. {
  81. get
  82. {
  83. return ctrl || command;
  84. }
  85. }
  86. /// <summary>
  87. ///
  88. /// </summary>
  89. public bool ctrl
  90. {
  91. get
  92. {
  93. return Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
  94. }
  95. }
  96. /// <summary>
  97. ///
  98. /// </summary>
  99. public bool shift
  100. {
  101. get
  102. {
  103. return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
  104. }
  105. }
  106. /// <summary>
  107. ///
  108. /// </summary>
  109. public bool alt
  110. {
  111. get
  112. {
  113. return Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
  114. }
  115. }
  116. /// <summary>
  117. ///
  118. /// </summary>
  119. public bool command
  120. {
  121. get
  122. {
  123. //In win, as long as the win key and other keys are pressed at the same time, the getKey will continue to return true. So it can only be shielded.
  124. if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
  125. return Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightCommand);
  126. else
  127. return false;
  128. }
  129. }
  130. }
  131. }