namespace Sasalka; public class AttachmentSlotResolver { private readonly Func _attachmentGetter; private readonly Dictionary _slotCache = new(); public AttachmentSlotResolver( Func 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(); } }