123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using CIS;
- using Core;
- using UnityEngine;
- public class InputMgr : SingletonMonoBehaviourClass<InputMgr>
- {
- public bool IsChannelOpen(IInputEventHandler handler)
- {
- return this.channel.ContainsKey(handler) && (bool)this.channel[handler];
- }
- public void RegisterInputEventHandler(IInputEventHandler handler)
- {
- this.handlers.Add(handler);
- if (!this.channel.ContainsKey(handler))
- {
- this.channel[handler] = true;
- }
- }
- public void UnRegisterInputEvent(IInputEventHandler handler)
- {
- for (int i = 0; i < this.handlers.Count; i++)
- {
- if (this.handlers[i] == handler)
- {
- this.handlers.RemoveAt(i);
- break;
- }
- }
- if (!this.channel.ContainsKey(handler))
- {
- this.channel.Remove(handler);
- }
- }
- public void EnableInput(bool enable)
- {
- this.enableInput = enable;
- }
- public void EnableInput(IInputEventHandler handler, bool enable)
- {
- this.channel[handler] = enable;
- }
- private void Start()
- {
- }
- private void Update()
- {
- if (UnityEngine.Input.GetKeyDown(KeyCode.N))
- {
- IDictionaryEnumerator enumerator = this.channel.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj = enumerator.Current;
- DictionaryEntry dictionaryEntry = (DictionaryEntry)obj;
- UnityEngine.Debug.Log(string.Concat(new object[]
- {
- "key : ",
- dictionaryEntry.Key,
- " value: ",
- dictionaryEntry.Value
- }));
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- }
- if (Core.Input.Shi.Left.OnPressed)
- {
- foreach (IInputEventHandler inputEventHandler in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler])
- {
- inputEventHandler.KeyDown(KeyCode.A);
- }
- }
- }
- if (Core.Input.Shi.Left.OnReleased)
- {
- foreach (IInputEventHandler inputEventHandler2 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler2])
- {
- inputEventHandler2.KeyUp(KeyCode.A);
- }
- }
- }
- if (Core.Input.Shi.Right.OnPressed)
- {
- foreach (IInputEventHandler inputEventHandler3 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler3])
- {
- inputEventHandler3.KeyDown(KeyCode.D);
- }
- }
- }
- if (Core.Input.Shi.Right.OnReleased)
- {
- foreach (IInputEventHandler inputEventHandler4 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler4])
- {
- inputEventHandler4.KeyUp(KeyCode.D);
- }
- }
- }
- if (Core.Input.Shi.Up.OnPressed)
- {
- foreach (IInputEventHandler inputEventHandler5 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler5])
- {
- inputEventHandler5.KeyDown(KeyCode.W);
- }
- }
- }
- if (Core.Input.Shi.Up.OnReleased)
- {
- foreach (IInputEventHandler inputEventHandler6 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler6])
- {
- inputEventHandler6.KeyUp(KeyCode.W);
- }
- }
- }
- if (Core.Input.Shi.Down.OnPressed)
- {
- foreach (IInputEventHandler inputEventHandler7 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler7])
- {
- inputEventHandler7.KeyDown(KeyCode.S);
- }
- }
- }
- if (Core.Input.Shi.Down.OnReleased)
- {
- foreach (IInputEventHandler inputEventHandler8 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler8])
- {
- inputEventHandler8.KeyUp(KeyCode.S);
- }
- }
- }
- if (Core.Input.Shi.Jump.OnPressed)
- {
- foreach (IInputEventHandler inputEventHandler9 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler9])
- {
- inputEventHandler9.KeyDown(KeyCode.J);
- }
- }
- }
- if (Core.Input.Shi.Jump.OnReleased)
- {
- foreach (IInputEventHandler inputEventHandler10 in this.handlers)
- {
- if ((bool)this.channel[inputEventHandler10])
- {
- inputEventHandler10.KeyUp(KeyCode.J);
- }
- }
- }
- }
- private List<IInputEventHandler> handlers = new List<IInputEventHandler>();
- private Hashtable channel = new Hashtable();
- private bool enableInput = true;
- }
|