39 lines
1.0 KiB
C#
39 lines
1.0 KiB
C#
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();
|
||
}
|
||
}
|