Game.Prefabs.AssetPackItem
Assembly:
Assembly-CSharp
Namespace:
Game.Prefabs
Type:
class
Base:
ComponentBase
Summary:
Component that can be attached to prefab assets to reference one or more AssetPackPrefab instances. At runtime this component ensures the entity for the prefab contains a DynamicBuffer
Fields
public AssetPackPrefab[] m_Packs
Array of AssetPackPrefab references assigned on the prefab. Marked with [NotNull] in the source, this array is iterated during GetDependencies and LateInitialize. Null or empty values are handled (ignored) during initialization.
Properties
- (none)
This class does not declare any C# properties.
Constructors
public AssetPackItem()
Default constructor (implicit). No special constructor logic in source.
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs)
Adds any non-null entries from m_Packs to the provided prefabs list. Calls base.GetDependencies(prefabs) first. If m_Packs is null the method returns early. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Declares that prefabs using this component require a read/write AssetPackElement component by adding ComponentType.ReadWrite() to the provided set. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
No-op in this implementation (no extra archetype components are added here). -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Runtime initialization that populates the DynamicBufferon the given entity: - Calls base.LateInitialize(entityManager, entity).
- Obtains the DynamicBuffer
and clears it. - If m_Packs is null or empty, returns early.
- Gets the PrefabSystem from the entity manager's World (PrefabSystem existingSystemManaged = entityManager.World.GetExistingSystemManaged
). - For each non-null AssetPackPrefab in m_Packs, retrieves its entity via existingSystemManaged.GetEntity(assetPackPrefab) and appends an AssetPackElement with m_Pack set to that entity to the buffer.
Usage Example
// Editor / prefab-setup example: attach the component and assign packs
AssetPackItem item = prefab.AddComponent<AssetPackItem>();
item.m_Packs = new AssetPackPrefab[] { myAssetPackPrefab1, myAssetPackPrefab2 };
// Runtime: reading the populated buffer after LateInitialize has run
DynamicBuffer<AssetPackElement> buffer = entityManager.GetBuffer<AssetPackElement>(entity);
foreach (var elem in buffer)
{
Entity packEntity = elem.m_Pack;
// use packEntity (e.g., query its components or pass to systems)
}
Additional notes: - The class is decorated with a ComponentMenu attribute that places it under "Asset Packs/" in the component menu and lists several prefab types for which it is relevant (ZonePrefab, ObjectPrefab, NetPrefab, AreaPrefab, RoutePrefab, NetLanePrefab). - The component ensures prefab dependency tracking for any referenced AssetPackPrefab instances so they will be loaded with the prefab.