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