sasalka/Code/Inventory/AttachmentSlotResolver.cs
2025-06-26 23:24:52 +03:00

39 lines
1.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace Sasalka;
public class AttachmentSlotResolver
{
private readonly Func<string, GameObject> _attachmentGetter;
private readonly Dictionary<Inventar.InventorySlot, GameObject> _slotCache = new();
public AttachmentSlotResolver( Func<string, GameObject> attachmentGetter )
{
_attachmentGetter = attachmentGetter;
}
public GameObject GetSlotObject( Inventar.InventorySlot slot )
{
// Проверяем кэш
if (_slotCache.TryGetValue(slot, out var cachedObject))
{
return cachedObject;
}
// Получаем объект и кэшируем его
var slotObject = slot switch
{
Inventar.InventorySlot.LeftHand => _attachmentGetter.Invoke( "hold_L" ),
Inventar.InventorySlot.RightHand => _attachmentGetter.Invoke( "hold_R" ),
Inventar.InventorySlot.Body => _attachmentGetter.Invoke( "forward_reference_modelspace" ),
_ => _attachmentGetter.Invoke( "forward_reference_modelspace" )
};
_slotCache[slot] = slotObject;
return slotObject;
}
public void ClearCache()
{
_slotCache.Clear();
}
}