Game.Prefabs.Unlock
Assembly:
Assembly-CSharp (game assembly). If you compile this into a separate mod assembly, ensure the assembly references Unity.Entities.
Namespace:
Game.Prefabs
Type:
public struct Unlock : IComponentData, IQueryTypeParameter
Base:
IComponentData, IQueryTypeParameter
Summary:
A small ECS component that stores a reference to a prefab Entity. Used to mark or configure entities that "unlock" or expose another prefab (for example, an unlockable building, decoration, or other content). This is a plain, blittable data component suitable for use in Systems and queries. The stored Entity is typically an archetype/prefab Entity that can be instantiated via EntityManager.Instantiate when needed.
Fields
public Entity m_Prefab
Holds the prefab Entity reference. May be Entity.Null if no prefab is assigned. This is the value you would pass to EntityManager.Instantiate(...) to create an instance of the referenced prefab. As a raw Entity field it is blittable and can be read/written inside jobs and systems (subject to the usual ECS access rules).
Properties
- None (no properties are defined on this struct).
Constructors
public Unlock(Entity prefab)
Initializes the component with the provided prefab Entity. Equivalent to setting m_Prefab = prefab.
Methods
- None. This struct implements only data interfaces (IComponentData and the marker interface IQueryTypeParameter). IQueryTypeParameter is a marker used by the DOTS query/type parameter system and does not require additional method implementations.
Usage Example
// Inside a SystemBase or other mod code with an EntityManager reference:
// Assigning the Unlock component to an entity:
Entity prefabEntity = /* obtain or create your prefab entity */;
Entity targetEntity = /* entity that should carry the unlock info */;
var unlock = new Game.Prefabs.Unlock(prefabEntity);
EntityManager.AddComponentData(targetEntity, unlock);
// Later, instantiate the referenced prefab:
if (unlock.m_Prefab != Entity.Null)
{
Entity instance = EntityManager.Instantiate(unlock.m_Prefab);
// configure instance as needed...
}
// Using in a SystemBase ForEach:
protected override void OnUpdate()
{
var em = EntityManager;
Entities
.ForEach((ref Game.Prefabs.Unlock unlock) =>
{
if (unlock.m_Prefab != Entity.Null)
{
Entity created = em.Instantiate(unlock.m_Prefab);
// use created...
}
}).WithoutBurst().Run();
}