Game.Prefabs.ZonePrefabs
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType (struct)
Summary:
A lightweight wrapper around a NativeArray
Fields
private Unity.Collections.NativeArray<Unity.Entities.Entity> m_ZonePrefabs
Holds the array of prefab Entity values, indexed by zone type index. The NativeArray is provided from outside (usually created elsewhere) and must be disposed by the caller; the struct does not perform disposal.
Properties
public Unity.Entities.Entity this[Game.Zones.ZoneType type] { get; }
Indexer that returns the prefab Entity for the given ZoneType. It uses the ZoneType.m_Index integer to index into the native array. Consumer code must ensure that type.m_Index is within the bounds of the underlying NativeArray to avoid out-of-range access.
Constructors
public ZonePrefabs(Unity.Collections.NativeArray<Unity.Entities.Entity> zonePrefabs)
Constructs a ZonePrefabs wrapper around the provided NativeArray. The NativeArray reference is copied (struct semantics), so the caller remains responsible for the array's allocation and disposal. No copying of elements occurs.
Methods
- (none)
This struct provides only the indexer and the constructor; there are no additional instance methods.
Usage Example
using Unity.Collections;
using Unity.Entities;
using Game.Zones;
using Game.Prefabs;
// Example: create and use ZonePrefabs
int zoneCount = 5;
var nativePrefabs = new NativeArray<Entity>(zoneCount, Allocator.Persistent);
// Populate nativePrefabs with Entities (obtained elsewhere)
for (int i = 0; i < zoneCount; i++)
{
nativePrefabs[i] = /* some Entity prefab */;
}
var zonePrefabs = new ZonePrefabs(nativePrefabs);
// Access a prefab by ZoneType (assuming you have a ZoneType instance)
ZoneType someZoneType = /* obtain ZoneType */;
Entity prefab = zonePrefabs[someZoneType];
// When done, dispose the NativeArray (zonePrefabs does not dispose it)
nativePrefabs.Dispose();
Notes: - ZonePrefabs is a struct, so copies of it will copy the NativeArray reference (not the array contents). - Be careful when passing this into jobs — ensure the NativeArray allocation and access rules for jobs are followed (correct Allocator, proper NativeArray safety handles, etc.).