42 lines
1017 B
C#
42 lines
1017 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using System.Text.RegularExpressions;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class InputMessageHandler : MonoBehaviour
|
|
{
|
|
public static InputMessageHandler Instance;
|
|
|
|
[SerializeField] UI_IconsConfig _keyboardConfig = default;
|
|
[SerializeField] UI_IconsConfig _joystickConfig = default;
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
}
|
|
else
|
|
{
|
|
Destroy(this);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public string Interpolate(string input)
|
|
{
|
|
const string pattern = @"\[\[(\w+)\]\]";
|
|
UI_IconsConfig config = Player.Instance.GetInputHandler().UsingGamePad ? _joystickConfig : _keyboardConfig;
|
|
|
|
return Regex.Replace(input, pattern, match =>
|
|
{
|
|
string id = match.Groups[1].Value;
|
|
string result = config.Replace(id);
|
|
return result == null ? "?" : result;
|
|
});
|
|
}
|
|
}
|