Optimize GC for input config.

This commit is contained in:
2023-05-07 13:38:41 +08:00
parent beab3d7f8b
commit d030c48b4d

View File

@@ -1,6 +1,7 @@
using Cryville.Common;
using Cryville.Common.Unity;
using Cryville.Input;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -73,15 +74,22 @@ namespace Cryville.Crtr.Config {
_entries[e.Name].OnProxyChanged(e);
}
void Start() {
_d_HandleInputEvent = HandleInputEvent;
}
readonly List<InputSource?> _recvsrcs = new List<InputSource?>();
void Update() {
if (m_inputDialog.activeSelf) {
_consumer.EnumerateEvents(ev => {
AddSourceItem(ev.Identifier.Source);
});
_consumer.EnumerateEvents(_d_HandleInputEvent);
}
}
Action<InputEvent> _d_HandleInputEvent;
void HandleInputEvent(InputEvent ev) {
AddSourceItem(ev.Identifier.Source);
}
void AddSourceItem(InputSource? src) {
if (_recvsrcs.Contains(src)) return;
_recvsrcs.Add(src);