InputMgr.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using CIS;
  5. using Core;
  6. using UnityEngine;
  7. public class InputMgr : SingletonMonoBehaviourClass<InputMgr>
  8. {
  9. public bool IsChannelOpen(IInputEventHandler handler)
  10. {
  11. return this.channel.ContainsKey(handler) && (bool)this.channel[handler];
  12. }
  13. public void RegisterInputEventHandler(IInputEventHandler handler)
  14. {
  15. this.handlers.Add(handler);
  16. if (!this.channel.ContainsKey(handler))
  17. {
  18. this.channel[handler] = true;
  19. }
  20. }
  21. public void UnRegisterInputEvent(IInputEventHandler handler)
  22. {
  23. for (int i = 0; i < this.handlers.Count; i++)
  24. {
  25. if (this.handlers[i] == handler)
  26. {
  27. this.handlers.RemoveAt(i);
  28. break;
  29. }
  30. }
  31. if (!this.channel.ContainsKey(handler))
  32. {
  33. this.channel.Remove(handler);
  34. }
  35. }
  36. public void EnableInput(bool enable)
  37. {
  38. this.enableInput = enable;
  39. }
  40. public void EnableInput(IInputEventHandler handler, bool enable)
  41. {
  42. this.channel[handler] = enable;
  43. }
  44. private void Start()
  45. {
  46. }
  47. private void Update()
  48. {
  49. if (UnityEngine.Input.GetKeyDown(KeyCode.N))
  50. {
  51. IDictionaryEnumerator enumerator = this.channel.GetEnumerator();
  52. try
  53. {
  54. while (enumerator.MoveNext())
  55. {
  56. object obj = enumerator.Current;
  57. DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
  58. UnityEngine.Debug.Log(string.Concat(new object[]
  59. {
  60. "key : ",
  61. dictionaryEntry.Key,
  62. " value: ",
  63. dictionaryEntry.Value
  64. }));
  65. }
  66. }
  67. finally
  68. {
  69. IDisposable disposable;
  70. if ((disposable = (enumerator as IDisposable)) != null)
  71. {
  72. disposable.Dispose();
  73. }
  74. }
  75. }
  76. if (Core.Input.Shi.Left.OnPressed)
  77. {
  78. foreach (IInputEventHandler inputEventHandler in this.handlers)
  79. {
  80. if ((bool)this.channel[inputEventHandler])
  81. {
  82. inputEventHandler.KeyDown(KeyCode.A);
  83. }
  84. }
  85. }
  86. if (Core.Input.Shi.Left.OnReleased)
  87. {
  88. foreach (IInputEventHandler inputEventHandler2 in this.handlers)
  89. {
  90. if ((bool)this.channel[inputEventHandler2])
  91. {
  92. inputEventHandler2.KeyUp(KeyCode.A);
  93. }
  94. }
  95. }
  96. if (Core.Input.Shi.Right.OnPressed)
  97. {
  98. foreach (IInputEventHandler inputEventHandler3 in this.handlers)
  99. {
  100. if ((bool)this.channel[inputEventHandler3])
  101. {
  102. inputEventHandler3.KeyDown(KeyCode.D);
  103. }
  104. }
  105. }
  106. if (Core.Input.Shi.Right.OnReleased)
  107. {
  108. foreach (IInputEventHandler inputEventHandler4 in this.handlers)
  109. {
  110. if ((bool)this.channel[inputEventHandler4])
  111. {
  112. inputEventHandler4.KeyUp(KeyCode.D);
  113. }
  114. }
  115. }
  116. if (Core.Input.Shi.Up.OnPressed)
  117. {
  118. foreach (IInputEventHandler inputEventHandler5 in this.handlers)
  119. {
  120. if ((bool)this.channel[inputEventHandler5])
  121. {
  122. inputEventHandler5.KeyDown(KeyCode.W);
  123. }
  124. }
  125. }
  126. if (Core.Input.Shi.Up.OnReleased)
  127. {
  128. foreach (IInputEventHandler inputEventHandler6 in this.handlers)
  129. {
  130. if ((bool)this.channel[inputEventHandler6])
  131. {
  132. inputEventHandler6.KeyUp(KeyCode.W);
  133. }
  134. }
  135. }
  136. if (Core.Input.Shi.Down.OnPressed)
  137. {
  138. foreach (IInputEventHandler inputEventHandler7 in this.handlers)
  139. {
  140. if ((bool)this.channel[inputEventHandler7])
  141. {
  142. inputEventHandler7.KeyDown(KeyCode.S);
  143. }
  144. }
  145. }
  146. if (Core.Input.Shi.Down.OnReleased)
  147. {
  148. foreach (IInputEventHandler inputEventHandler8 in this.handlers)
  149. {
  150. if ((bool)this.channel[inputEventHandler8])
  151. {
  152. inputEventHandler8.KeyUp(KeyCode.S);
  153. }
  154. }
  155. }
  156. if (Core.Input.Shi.Jump.OnPressed)
  157. {
  158. foreach (IInputEventHandler inputEventHandler9 in this.handlers)
  159. {
  160. if ((bool)this.channel[inputEventHandler9])
  161. {
  162. inputEventHandler9.KeyDown(KeyCode.J);
  163. }
  164. }
  165. }
  166. if (Core.Input.Shi.Jump.OnReleased)
  167. {
  168. foreach (IInputEventHandler inputEventHandler10 in this.handlers)
  169. {
  170. if ((bool)this.channel[inputEventHandler10])
  171. {
  172. inputEventHandler10.KeyUp(KeyCode.J);
  173. }
  174. }
  175. }
  176. }
  177. private List<IInputEventHandler> handlers = new List<IInputEventHandler>();
  178. private Hashtable channel = new Hashtable();
  179. private bool enableInput = true;
  180. }