Game.Prefabs.ResourceConsumerData
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
ResourceConsumerData is a small ECS component used to mark an entity that consumes a resource and to store a reference to a notification prefab Entity that should be spawned/used when the resource is unavailable. It's a plain data container (IComponentData) and also implements IQueryTypeParameter so it can participate in entity queries where this component is part of the query signature.
Fields
public Unity.Entities.Entity m_NoResourceNotificationPrefab
Holds an Entity reference to a prefab used for notifying (or spawning) when the consumer has no resource. Use Entity.Null to indicate there is no notification prefab. This is a lightweight reference only — instantiation or spawning must be handled by systems that read this component.
Properties
- This struct defines no properties.
Constructors
public ResourceConsumerData()
Default value-type constructor. You can initialize it inline when adding the component, for example: new ResourceConsumerData { m_NoResourceNotificationPrefab = prefabEntity }
Methods
- This struct defines no methods. It is intended to be pure data (IComponentData) and manipulated by ECS systems.
Usage Example
// Add the component to an entity with a reference to a prefab entity
Entity prefabEntity = ...; // obtain or create the notification prefab entity
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity consumer = em.CreateEntity();
em.AddComponentData(consumer, new Game.Prefabs.ResourceConsumerData {
m_NoResourceNotificationPrefab = prefabEntity
});
// In a SystemBase or JobComponentSystem, read the component and act:
public partial class ResourceConsumerSystem : SystemBase
{
protected override void OnUpdate()
{
EntityManager em = EntityManager;
Entities.WithoutBurst().ForEach((Entity e, ref Game.Prefabs.ResourceConsumerData rcd) =>
{
if (/* check resource missing condition for this consumer */ false)
{
if (rcd.m_NoResourceNotificationPrefab != Entity.Null)
{
// instantiate or spawn notification prefab as appropriate
Entity instance = em.Instantiate(rcd.m_NoResourceNotificationPrefab);
// set instance position / initialize as needed
}
}
}).Run();
}
}
Notes and tips: - The Entity stored is a direct reference to an entity (often a prefab) and is not serialized as a GameObject reference. Ensure the referenced entity exists in the same EntityManager/world or is instantiated appropriately. - Use Entity.Null to indicate "no prefab". - Because this is a plain component, systems should perform any instantiation/spawning and any resource-availability checks; this struct only conveys which notification prefab to use.