Game.Prefabs.ResourcePrefabs
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType
Summary:
Lightweight wrapper that maps a Resource enum value to its corresponding prefab Entity using an underlying NativeArray
Fields
-
private Unity.Collections.NativeArray<Unity.Entities.Entity> m_ResourcePrefabs
Holds the array of prefab Entities for resources. This NativeArray is not created or disposed by ResourcePrefabs — it must be created (and later disposed) by the caller. Accessing Length/indices when the NativeArray is uninitialized will throw, so callers should ensure the array is IsCreated before constructing/using this struct. -
private Unity.Jobs.JobHandle <producerHandle>k__BackingField
N/A for this type. (The source file does not declare such a field; this line is present in the template and left intentionally blank.)
Properties
public Unity.Entities.Entity this[Resource resource] { get; }
Indexer that returns the prefab Entity for the given Resource. Internally it calls EconomyUtils.GetResourceIndex(resource) to get an integer index. If the returned index is within the bounds of m_ResourcePrefabs, the corresponding Entity is returned; otherwise Entity.Null is returned. Note that if m_ResourcePrefabs is not created, accessing Length will throw an exception — ensure the NativeArray was properly constructed before use.
Constructors
public ResourcePrefabs(Unity.Collections.NativeArray<Unity.Entities.Entity> resourcePrefabs)
Initializes the wrapper with the provided NativeArray. This stores the reference only; it does not copy elements or take ownership of the array. The caller remains responsible for the array's lifetime (creation/disposal).
Methods
- None beyond the indexer. There are no lifecycle or helper methods declared on this struct.
Usage Example
// Example: obtain a NativeArray<Entity> from whatever system creates resource prefabs,
// then wrap it in ResourcePrefabs for convenient indexed access.
NativeArray<Entity> resourceArray = /* created elsewhere and filled with prefab entities */;
var resourcePrefabs = new ResourcePrefabs(resourceArray);
// Access the prefab for a specific resource:
Entity woodPrefab = resourcePrefabs[Resource.Wood];
if (woodPrefab != Entity.Null)
{
// Use the prefab (instantiate, query, etc.)
}
// Important notes:
// - Ensure resourceArray.IsCreated == true before passing it to the constructor.
// - This struct does not own or dispose the NativeArray; dispose it when appropriate.
// - Copying the struct copies the NativeArray handle (shallow copy). Do not assume deep copy.