Game.UI.InGame.ResourceSection
Assembly:
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
ResourceSection is an in-game UI info section that displays the amount of resource (currently only wood) available from a selected tree entity. It determines visibility based on whether the selected entity is a Tree and whether the prefab's TreeData defines a positive wood amount. OnProcess reads entity/prefab components (Tree, Plant, TreeData, optionally Damaged), calculates the wood amount using ObjectUtils.CalculateWoodAmount, rounds it, and exposes it for serialization via OnWriteProperties.
Fields
None
This class declares no explicit private fields. It uses auto-properties and a nested enum (ResourceKey). Compiler-generated backing fields exist for the auto-properties but are not declared in source.
Nested Types
private enum ResourceKey
Wood
Enum used to identify the resource type shown by this section (currently only Wood).
Properties
-
protected override string group { get; }
Returns the UI group name: "ResourceSection". Used by the UI system to group/identify this section. -
private float resourceAmount { get; set; }
Stores the rounded amount of resource (wood) calculated in OnProcess. Reset to 0 in Reset(). -
private ResourceKey resourceKey { get; set; }
Stores which resource is represented (ResourceKey.Wood). Written to JSON in OnWriteProperties. -
protected override bool displayForDestroyedObjects { get; }
Overrides base behavior to return true — the section can be displayed for destroyed objects.
Constructors
[Preserve] public ResourceSection()
Default constructor. Marked with [Preserve] to prevent stripping; no custom initialization logic in source.
Methods
-
protected override void Reset()
Resets the section state between uses. Implementation sets resourceAmount = 0f. -
[Preserve] protected override void OnUpdate()
Updates visibility (base.visible) for the section. The section becomes visible when: - the selected entity has a Tree component, and
-
the selected prefab has TreeData with m_WoodAmount > 0f. This method uses EntityManager.HasComponent
(selectedEntity) and EntityManager.TryGetComponent (selectedPrefab, out var component). -
protected override void OnProcess()
Reads runtime component data required to compute the resource amount: - Tree component data from the selected entity
- Plant component data from the selected entity
- TreeData from the selected prefab
-
optionally Damaged component from the selected entity (if present) It calculates the wood amount with ObjectUtils.CalculateWoodAmount(tree, plant, damaged, treeData), rounds the result via math.round, assigns it to resourceAmount, and sets resourceKey = ResourceKey.Wood.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the section properties into JSON. Writes two properties: - "resourceAmount" — numeric value of resourceAmount
- "resourceKey" — string name of the resourceKey enum (Enum.GetName(typeof(ResourceKey), resourceKey))
Usage Example
[Preserve]
protected override void OnUpdate()
{
// Make the section visible only for trees that actually provide wood
base.visible = base.EntityManager.HasComponent<Tree>(selectedEntity)
&& base.EntityManager.TryGetComponent<TreeData>(selectedPrefab, out var prefabData)
&& prefabData.m_WoodAmount > 0f;
}
protected override void OnProcess()
{
// Read components and compute the rounded wood amount to display
var treeData = base.EntityManager.GetComponentData<Tree>(selectedEntity);
var plantData = base.EntityManager.GetComponentData<Plant>(selectedEntity);
var prefabTreeData = base.EntityManager.GetComponentData<TreeData>(selectedPrefab);
base.EntityManager.TryGetComponent<Damaged>(selectedEntity, out var damaged);
resourceAmount = math.round(ObjectUtils.CalculateWoodAmount(treeData, plantData, damaged, prefabTreeData));
resourceKey = ResourceKey.Wood;
}
public override void OnWriteProperties(IJsonWriter writer)
{
writer.PropertyName("resourceAmount");
writer.Write(resourceAmount);
writer.PropertyName("resourceKey");
writer.Write(Enum.GetName(typeof(ResourceKey), resourceKey));
}
Example JSON output produced by OnWriteProperties:
{
"resourceAmount": 12.0,
"resourceKey": "Wood"
}
Notes: - This section depends on types/components: Tree, Plant, TreeData, Damaged, ObjectUtils, IJsonWriter, and the EntityManager provided by the base InfoSectionBase. - The class is marked [CompilerGenerated] in source; methods and the constructor are preserved with [Preserve] to avoid stripping.