Game.Prefabs.UpgradeUtils
Assembly: Game
Namespace: Game.Prefabs
Type: public static class
Base: None (static utility class)
Summary:
Utility helpers to aggregate/merge upgrade data for prefabs and entities. UpgradeUtils provides multiple overloads named CombineStats and TryGetCombinedComponent/TryCombineData to collect base prefab component data and apply any installed upgrades (InstalledUpgrade buffer) by calling Combine on ICombineData
Fields
- This class has no fields.
{{ Utility class — no instance/private fields are declared. }}
Properties
- This class exposes no properties.
{{ Static utility class; all functionality is provided via static methods. }}
Constructors
- No public constructors (static class).
{{ Being a static class there are no constructors to instantiate; methods are called statically. }}
Methods
-
public static void CombineStats<T>(ref T result, BufferAccessor<InstalledUpgrade> accessor, int i, ref ComponentLookup<PrefabRef> prefabs, ref ComponentLookup<T> combineDatas) where T : unmanaged, IComponentData, ICombineData<T>
{{ If the accessor has any entries, this overload will look up the InstalledUpgrade at index i and call the other CombineStats overload that accepts an InstalledUpgrade. Use this in chunk-based code where you have a BufferAccessor and the entity index. It relies on prefabs to resolve the PrefabRef for the installed upgrade. }} -
public static bool CombineStats<T>(ref T data, DynamicBuffer<InstalledUpgrade> upgrades, ref ComponentLookup<PrefabRef> prefabs, ref ComponentLookup<T> combineDatas) where T : unmanaged, IComponentData, ICombineData<T>
{{ Iterates the DynamicBuffer of InstalledUpgrade, checks each upgrade for active status with BuildingUtils.CheckOption, resolves the upgrade's prefab via prefabs lookup, retrieves the T component data from the prefab (via combineDatas.TryGetComponent) and calls data.Combine(componentData) for each applicable upgrade. Returns true if any upgrade data was combined. Use this inside Systems where you have ComponentLookup access. }} -
public static bool CombineStats<T>(EntityManager entityManager, ref T data, DynamicBuffer<InstalledUpgrade> upgrades) where T : unmanaged, IComponentData, ICombineData<T>
{{ Similar to the previous overload but uses EntityManager directly to resolve PrefabRef and the component T on the prefab entity. Iterates upgrades, skips inactive ones, and combines found prefab component data into data. Returns true if any combine occurred. Useful in contexts where you have an EntityManager instead of ComponentLookup/BufferLookup. }} -
public static void CombineStats<T>(NativeList<T> result, DynamicBuffer<InstalledUpgrade> upgrades, ref ComponentLookup<PrefabRef> prefabs, ref BufferLookup<T> combineDatas) where T : unmanaged, IBufferElementData, ICombineBuffer<T>
{{ For buffer-based combine types: iterates installed upgrades, skips inactive ones, resolves the prefab entity and calls CombineStats(NativeList, Entity, ref BufferLookup ) for each. This accumulates buffer elements from prefab upgrade components into the provided NativeList. }} -
public static void CombineStats<T>(NativeList<T> result, Entity prefab, ref BufferLookup<T> combineDatas) where T : unmanaged, IBufferElementData, ICombineBuffer<T>
{{ Tries to get the buffer of T from the prefab entity via BufferLookup. If present, delegates to CombineStats(NativeList, DynamicBuffer ) to merge buffer contents into result. }} -
public static void CombineStats<T>(NativeList<T> result, DynamicBuffer<T> combineData) where T : unmanaged, IBufferElementData, ICombineBuffer<T>
{{ Iterates the DynamicBufferand calls combineData[i].Combine(result) for each element to accumulate buffer-based combine data into the NativeList. }} -
public static void CombineStats<T>(NativeList<T> result, T combineData) where T : unmanaged, IBufferElementData, ICombineBuffer<T>
{{ Calls combineData.Combine(result) to add a single buffer-element combine entry into the result list. }} -
public static bool TryGetCombinedComponent<T>(EntityManager entityManager, Entity entity, Entity prefab, out T data) where T : unmanaged, IComponentData, ICombineData<T>
{{ Attempts to get base component T from the provided prefab entity via entityManager.TryGetComponent. Then calls TryCombineData(entityManager, entity, ref data) to apply any installed upgrades from the entity, returning true if either the base prefab component existed or any upgrades were combined. Outputs data containing the combined result (prefab base + upgrades). }} -
public static bool TryCombineData<T>(EntityManager entityManager, Entity entity, ref T data) where T : unmanaged, IComponentData, ICombineData<T>
{{ If the entity has a DynamicBuffer, iterates the buffer and calls CombineStats(EntityManager, ref T, DynamicBuffer ) to apply upgrades. Returns true if any upgrade combined, otherwise false. }} -
public static bool TryGetCombinedComponent<T>(Entity entity, out T data, ref ComponentLookup<PrefabRef> prefabRefLookup, ref ComponentLookup<T> combineDataLookup, ref BufferLookup<InstalledUpgrade> installedUpgradeLookup) where T : unmanaged, IComponentData, ICombineData<T>
{{ System-friendly overload used inside SystemBase: resolves the entity's PrefabRef and the component T on the prefab (via ComponentLookup). If the entity has an InstalledUpgrade buffer (via BufferLookup), it will apply upgrades by calling CombineStats on that buffer and the lookups. Returns true if either the prefab provided component data or any upgrades were applied. On success, data contains the combined result. }}
Usage Example
// Example usage inside a SystemBase (T must implement ICombineData<T>)
protected override void OnUpdate()
{
var prefabRefLookup = GetComponentLookup<PrefabRef>(isReadOnly: true);
var componentLookup = GetComponentLookup<MyStatComponent>(isReadOnly: true);
var installedUpgradeLookup = GetBufferLookup<InstalledUpgrade>(isReadOnly: true);
Entities
.WithReadOnly(prefabRefLookup)
.WithReadOnly(componentLookup)
.WithReadOnly(installedUpgradeLookup)
.ForEach((Entity entity) =>
{
// MyStatComponent must implement ICombineData<MyStatComponent>
if (UpgradeUtils.TryGetCombinedComponent(entity, out MyStatComponent combined,
ref prefabRefLookup, ref componentLookup, ref installedUpgradeLookup))
{
// `combined` now contains the prefab base stats plus any installed upgrades applied
// Use `combined` for calculations/rendering/etc.
}
})
.WithoutBurst()
.Run();
{{ Notes:
- ICombineData