Skip to content

Game.Prefabs.QuantityObject

Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Prefabs

Type: class QuantityObject

Base: ComponentBase

Summary:
Prefab component used to mark objects that provide one or more in-game resources or a map feature. At prefab initialization it collects configured ResourceInEditor entries, converts them to the runtime Resource flag(s) via EconomyUtils.GetResource, sets those flags together with the configured MapFeature into the QuantityObjectData component on the entity, and ensures the entity archetype contains a Quantity component. If no resource or map feature is present (and the prefab is not a placeholder), a warning is logged.


Fields

  • public ResourceInEditor[] m_Resources
    Holds the list of resources configured in the editor for this prefab. During Initialize these are converted (with EconomyUtils.GetResource) into Resource flags and stored into the QuantityObjectData component on the created entity.

  • public MapFeature m_MapFeature = MapFeature.None
    Optional map feature to assign to the prefab. This value is written into QuantityObjectData.m_MapFeature during Initialize.

Properties

  • None declared on this type. (The class relies on overridden methods from ComponentBase and writes component data directly in Initialize.)

Constructors

  • public QuantityObject()
    No explicit constructor is defined in the source; the class uses the default parameterless constructor provided by C#. Initialization of runtime data occurs in the overridden Initialize method rather than in a constructor.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the runtime component types required by this prefab to the prefab components set. Specifically, it adds a read-write QuantityObjectData component type so that entity instances will hold the data written in Initialize.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds the archetype components required for the entity created from this prefab. This method adds a read-write Quantity component so that the entity has the expected archetype for quantity/resource systems.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Primary initialization routine called when the prefab is instantiated. Behavior:

  • Calls base.Initialize(entityManager, entity).
  • Creates a QuantityObjectData struct and populates its m_Resources flag by iterating m_Resources and OR-ing the result of EconomyUtils.GetResource for each entry.
  • Sets componentData.m_MapFeature from m_MapFeature.
  • Writes the QuantityObjectData into the entity via entityManager.SetComponentData.
  • If resulting m_Resources == Resource.NoResource and m_MapFeature == MapFeature.None and the prefab is not a PlaceholderObject, logs a warning via ComponentBase.baseLog.WarnFormat indicating the prefab has no resource.

Usage Example

// Example: editor-configured prefab will have m_Resources and/or m_MapFeature set in the inspector.
// When the prefab system instantiates the prefab it calls Initialize which performs the conversion:

public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    QuantityObjectData componentData = default;
    if (m_Resources != null)
    {
        for (int i = 0; i < m_Resources.Length; i++)
        {
            // Convert editor resource to runtime Resource flag and accumulate with bitwise OR
            componentData.m_Resources |= EconomyUtils.GetResource(m_Resources[i]);
        }
    }
    componentData.m_MapFeature = m_MapFeature;
    entityManager.SetComponentData(entity, componentData);

    // Warn if nothing meaningful was configured
    if (componentData.m_Resources == Resource.NoResource && componentData.m_MapFeature == MapFeature.None &&
        !base.prefab.Has<PlaceholderObject>())
    {
        ComponentBase.baseLog.WarnFormat(base.prefab, "QuantityObject has no resource: {0}", base.prefab.name);
    }
}

Notes and tips: - ResourceInEditor entries typically map to a Resource enum bit flag via EconomyUtils.GetResource; multiple entries will be combined into a flags field. - Ensure prefabs that should provide nothing are marked as PlaceholderObject to avoid warnings. - The class expects QuantityObjectData and Quantity component types to exist in the ECS; the prefab wiring is done in GetPrefabComponents / GetArchetypeComponents.