85 lines
3.1 KiB
C#
85 lines
3.1 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using TMPro;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace InputGlyphsFramework
|
||
|
|
{
|
||
|
|
[Serializable]
|
||
|
|
public class GlyphEntry
|
||
|
|
{
|
||
|
|
public Sprite Sprite;
|
||
|
|
public string controlPath;
|
||
|
|
}
|
||
|
|
|
||
|
|
[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 string uiGenericKeyName = "UI_KEY_GENERIC";
|
||
|
|
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|