AlicizaX/Client/Assets/InputGlyph/InputGlyphDatabase.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2025-12-05 19:04:53 +08:00
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
2025-12-05 20:57:29 +08:00
using UnityEngine.InputSystem;
2025-12-05 19:04:53 +08:00
namespace AlicizaX.InputGlyph
2025-12-05 19:04:53 +08:00
{
[Serializable]
public class GlyphEntry
{
public Sprite Sprite;
2025-12-05 20:57:29 +08:00
public InputAction action;
2025-12-05 19:04:53 +08:00
}
[Serializable]
public class DeviceGlyphTable
{
public InputDeviceWatcher.InputDeviceCategory deviceType;
public TMP_SpriteAsset tmpAsset;
public List<GlyphEntry> entries = new List<GlyphEntry>();
}
[CreateAssetMenu(fileName = "InputGlyphDatabase", menuName = "InputGlyphs/InputGlyphDatabase", order = 400)]
public class InputGlyphDatabase : ScriptableObject
{
public List<DeviceGlyphTable> tables = new List<DeviceGlyphTable>();
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];
2025-12-05 19:04:53 +08:00
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;
2025-12-05 19:04:53 +08:00
var matchPath = $"{e.action.controls[0].device.displayName}/{e.action.controls[0].displayName}";
if (string.Equals(matchPath, controlPath, StringComparison.OrdinalIgnoreCase)) return e;
2025-12-05 19:04:53 +08:00
}
}
2025-12-05 19:04:53 +08:00
return null;
}
}
}