36 lines
920 B
C#
36 lines
920 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
|
|
[CreateAssetMenu(menuName = "Input/AliasConfig")]
|
|
public class AliasConfig : ScriptableObject
|
|
{
|
|
[Serializable]
|
|
public class AliasMapping
|
|
{
|
|
public string alias;
|
|
public InputActionReference actionReference;
|
|
}
|
|
|
|
public List<AliasMapping> mappings = new();
|
|
private Dictionary<string, InputAction> _actionMap;
|
|
|
|
public void Initialize()
|
|
{
|
|
_actionMap = new();
|
|
foreach (var mapping in mappings)
|
|
{
|
|
if (mapping.actionReference != null)
|
|
{
|
|
_actionMap[mapping.alias] = mapping.actionReference.action;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool TryGetAction(string alias, out InputAction action)
|
|
=> _actionMap.TryGetValue(alias, out action);
|
|
|
|
public IEnumerable<string> GetAllAliases() => _actionMap.Keys;
|
|
}
|