Game.Prefabs.TreeObject
Assembly: Game
Namespace: Game.Prefabs
Type: public class
Base: ComponentBase
Summary:
Represents a tree prefab component used by the game's prefab system. Exposes a configurable m_WoodAmount (default 3000f) and declares the runtime component and archetype component types required for tree instances. During initialization, it writes the tree's wood amount into the entity's TreeData component and, when appropriate, sets the PlaceableObjectData.sub-replacement type to SubReplacementType.Tree (unless the object is placed on a road node or road edge).
Fields
public float m_WoodAmount = 3000f;
Default amount of wood the tree provides (floating point). This value is written into the entity's TreeData.m_WoodAmount during LateInitialize.
Properties
- None declared on this class.
The class exposes behavior through overrides (GetPrefabComponents, GetArchetypeComponents, LateInitialize) rather than properties.
Constructors
public TreeObject()
Implicit default constructor. No custom construction logic is defined in the source; initialization of runtime component data is performed in LateInitialize.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds component types required on the prefab's entity data for this prefab. Specifically adds:- PlantData (ReadWrite)
- TreeData (ReadWrite)
-
GrowthScaleData (ReadWrite)
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds component types required in the archetype for instantiated entities of this prefab. Specifically adds: - Plant (ReadWrite)
- Tree (ReadWrite)
- Color (ReadWrite)
-
UpdateFrame (ReadWrite)
-
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called after the entity is created. Behavior: - Calls base.LateInitialize(entityManager, entity).
- Creates a TreeData instance and sets its m_WoodAmount from this.m_WoodAmount, then writes it to the entity with entityManager.SetComponentData(entity, componentData).
- Attempts to get PlaceableObjectData from the entity. If present and the PlaceableObjectData flags do not include RoadNode or RoadEdge placement flags, sets component.m_SubReplacementType = SubReplacementType.Tree and writes the modified PlaceableObjectData back to the entity (entityManager.SetComponentData). This ensures that the prefab registers as a tree-type sub-replacement when not placed on roads.
Notes / Implementation details:
- The method uses entityManager.TryGetComponent
Usage Example
// Example: Subclassing TreeObject to change default wood amount
public class BigTreeObject : TreeObject
{
public BigTreeObject()
{
m_WoodAmount = 10000f; // override default amount
}
// LateInitialize doesn't need to be overridden because base.LateInitialize
// will copy m_WoodAmount into the entity's TreeData.
}
More advanced example (reading TreeData from an entity after initialization):
// In a system or MonoBehaviour with access to an EntityManager:
TreeData treeData = entityManager.GetComponentData<TreeData>(treeEntity);
float wood = treeData.m_WoodAmount;