r2mods/ilspy_dump/ror2_csproj/RoR2/MemoizedGetComponent.cs

21 lines
422 B
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using UnityEngine;
namespace RoR2;
public struct MemoizedGetComponent<TComponent> where TComponent : Component
{
private GameObject cachedGameObject;
private TComponent cachedValue;
public TComponent Get(GameObject gameObject)
{
if (cachedGameObject != gameObject)
{
cachedGameObject = gameObject;
cachedValue = (gameObject ? gameObject.GetComponent<TComponent>() : null);
}
return cachedValue;
}
}