using System; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.InputSystem; namespace AlicizaX.InputGlyph { [Serializable] public class GlyphEntry { public Sprite Sprite; public InputAction action; } [Serializable] public class DeviceGlyphTable { public InputDeviceWatcher.InputDeviceCategory deviceType; public TMP_SpriteAsset tmpAsset; public List entries = new List(); } [CreateAssetMenu(fileName = "InputGlyphDatabase", menuName = "InputGlyphs/InputGlyphDatabase", order = 400)] public class InputGlyphDatabase : ScriptableObject { public List tables = new List(); public DeviceGlyphTable GetTable(InputDeviceWatcher.InputDeviceCategory device) { if (tables == null) return null; for (int i = 0; i < tables.Count; ++i) if (tables[i].deviceType == device) return tables[i]; return null; } public GlyphEntry FindEntryByControlPath(string controlPath, InputDeviceWatcher.InputDeviceCategory device) { if (string.IsNullOrEmpty(controlPath)) return null; var t = GetTable(device); if (t != null) { for (int i = 0; i < t.entries.Count; ++i) { var e = t.entries[i]; if (e.action.controls.Count <= 0) continue; var matchPath = $"{e.action.controls[0].device.displayName}/{e.action.controls[0].displayName}"; if (string.Equals(matchPath, controlPath, StringComparison.OrdinalIgnoreCase)) return e; } } return null; } } }