using System; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.InputSystem; namespace InputGlyphsFramework { [Serializable] public class GlyphEntry { public Sprite Sprite; public string controlPath; 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 != null && !string.IsNullOrEmpty(e.controlPath) && string.Equals(e.controlPath, controlPath, StringComparison.OrdinalIgnoreCase)) return e; } } var kb = GetTable(InputDeviceWatcher.InputDeviceCategory.Keyboard); if (kb != null) { for (int i = 0; i < kb.entries.Count; ++i) { var e = kb.entries[i]; if (e != null && !string.IsNullOrEmpty(e.controlPath) && string.Equals(e.controlPath, controlPath, StringComparison.OrdinalIgnoreCase)) return e; } } return null; } public GlyphEntry FindEntryBySpriteName(string spriteName, InputDeviceWatcher.InputDeviceCategory device) { if (string.IsNullOrEmpty(spriteName)) 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 != null && e.Sprite != null && string.Equals(e.Sprite.name, spriteName, StringComparison.OrdinalIgnoreCase)) return e; } } var kb = GetTable(InputDeviceWatcher.InputDeviceCategory.Keyboard); if (kb != null) { for (int i = 0; i < kb.entries.Count; ++i) { var e = kb.entries[i]; if (e != null && e.Sprite != null && string.Equals(e.Sprite.name, spriteName, StringComparison.OrdinalIgnoreCase)) return e; } } return null; } } }