Game.Prefabs.DevTreeNodePrefab
Assembly:
Assembly-CSharp (game assembly)
Namespace:
Game.Prefabs
Type:
public class DevTreeNodePrefab
Base:
PrefabBase
Attributes: [RequireComponent(typeof(ManualUnlockable))]
Summary:
Prefab component representing a development/technology tree node. Holds references to the service unlocked by the node, other prerequisite nodes, presentation data (icon path/prefab) and layout info (horizontal/vertical position). During prefab->ECS conversion it ensures the correct ECS components/buffers are declared and populates DevTreeNodeData and DevTreeNodeRequirement buffer entries. Nodes with zero cost get an auto-unlock marker component added.
Fields
-
public ServicePrefab m_Service
Reference to the Service prefab that this dev tree node unlocks. During LateInitialize this is converted to an Entity stored in DevTreeNodeData.m_Service. -
public DevTreeNodePrefab[] m_Requirements
Array of other DevTreeNodePrefab references that are prerequisites for this node. If any non-null entries exist, a DevTreeNodeRequirement buffer component is added and filled with the corresponding entities. -
public int m_Cost
Cost to unlock the dev node. If this equals 0, a DevTreeNodeAutoUnlock component is added so the node is unlocked automatically. -
public int m_HorizontalPosition
Intended horizontal position in the tech/dev tree UI (used by tools that read the prefab for layout). -
public float m_VerticalPosition
Intended vertical position in the tech/dev tree UI. -
public string m_IconPath
Path to an icon asset (string). Alternative to m_IconPrefab. -
public PrefabBase m_IconPrefab
Optional prefab used as icon representation.
Properties
- None declared on this class. (All data exposed as public fields.)
Constructors
public DevTreeNodePrefab()
Default MonoBehaviour/PrefabBase constructor provided by Unity. No custom constructor logic in this class.
Methods
public override void GetDependencies(List<PrefabBase> prefabs)
Adds referenced prefabs to the provided dependency list so the PrefabSystem knows to load them. Adds:- m_Service (if not null)
-
each non-null entry in m_Requirements
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Ensures the ECS components used by this prefab are declared: - Always adds DevTreeNodeData (read/write).
- Adds DevTreeNodeRequirement (read/write) if this node has any non-null requirements.
-
Adds DevTreeNodeAutoUnlock (read/write) if m_Cost == 0.
-
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called during prefab->ECS conversion. Implementation: - Resolves the ServicePrefab to an Entity (via PrefabSystem) and writes DevTreeNodeData { m_Cost = m_Cost, m_Service = serviceEntity } to the prefab entity.
-
If the entity has a DevTreeNodeRequirement buffer, fills it with entries for every non-null DevTreeNodePrefab in m_Requirements by resolving each prerequisite prefab to its Entity and adding DevTreeNodeRequirement { m_Node = requirementEntity }.
-
private bool HasRequirements()
Utility that returns true if m_Requirements contains any non-null entries; false otherwise. Used to decide whether to add/prepare the DevTreeNodeRequirement buffer/component.
Usage Example
// Typical runtime/modding usage: access the prefab component and inspect its data,
// or get the converted ECS entity and read the DevTreeNodeData component.
// Assume 'nodePrefab' is a DevTreeNodePrefab instance (from a prefab GameObject)
// and the PrefabSystem has already converted prefabs to entities.
DevTreeNodePrefab nodePrefab = /* get from GameObject or asset */;
PrefabSystem prefabSystem = World.DefaultGameObjectInjectionWorld
.GetExistingSystemManaged<PrefabSystem>();
Entity serviceEntity = prefabSystem.GetEntity(nodePrefab.m_Service);
// After conversion: get the prefab entity and read its DevTreeNodeData
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity nodeEntity = prefabSystem.GetEntity(nodePrefab);
if (em.HasComponent<DevTreeNodeData>(nodeEntity))
{
DevTreeNodeData data = em.GetComponentData<DevTreeNodeData>(nodeEntity);
Debug.Log($"Node cost: {data.m_Cost}, service entity: {data.m_Service}");
}
// Note: if nodePrefab.m_Cost == 0, the prefab will have DevTreeNodeAutoUnlock.
// If nodePrefab has non-null m_Requirements entries, the entity will have a
// DynamicBuffer<DevTreeNodeRequirement> populated with prerequisite node entities.