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 InputGlyphsFramework
|
|
|
|
|
{
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class GlyphEntry
|
|
|
|
|
{
|
|
|
|
|
public Sprite Sprite;
|
|
|
|
|
public string controlPath;
|
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];
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|