Implement input proxy. Change input callback delegate to event. Prevents repeated (de)activation.

This commit is contained in:
2022-11-06 00:50:09 +08:00
parent 7f02b75b29
commit 8f98cb63cb
7 changed files with 119 additions and 111 deletions

View File

@@ -17,12 +17,11 @@ namespace Cryville.Common.Unity.Input {
readonly Dictionary<InputIdentifier, InputVector> _vectors = new Dictionary<InputIdentifier, InputVector>();
readonly List<InputEvent> _events = new List<InputEvent>();
public InputManager() {
var cb = new InputEventDelegate(Callback);
foreach (var t in HandlerRegistries) {
try {
if (!typeof(InputHandler).IsAssignableFrom(t)) continue;
var h = (InputHandler)ReflectionHelper.InvokeEmptyConstructor(t);
h.Callback = Callback;
h.OnInput += OnInput;
_handlers.Add(h);
_timeOrigins.Add(h, 0);
Logger.Log("main", 1, "Input", "Initialized {0}", ReflectionHelper.GetSimpleName(t));
@@ -46,7 +45,7 @@ namespace Cryville.Common.Unity.Input {
public void Deactivate() {
foreach (var h in _handlers) h.Deactivate();
}
void Callback(InputIdentifier id, InputVector vec) {
void OnInput(InputIdentifier id, InputVector vec) {
lock (_lock) {
double timeOrigin = _timeOrigins[id.Source.Handler];
vec.Time += timeOrigin;