Skip to content

Game.Prefabs.ResourceConnection

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

Type: class

Base: ComponentBase

Summary:
Component to attach to a prefab that indicates it produces/consumes a particular in-game resource and optionally links a notification prefab to be used for connection warnings. When the prefab is instantiated this component ensures the entity receives a ResourceConnectionData component with the resolved resource and an optional notification entity reference. It also declares the required ECS component types for prefab/archetype creation.


Fields

  • public ResourceInEditor m_Resource
    Holds the editor reference to which resource this prefab uses (producer/consumer). At LateInitialize this is resolved to the runtime resource definition via EconomyUtils.GetResource and written into ResourceConnectionData.

  • public NotificationIconPrefab m_ConnectionWarningNotification
    Optional reference to a notification prefab used to show connection warnings. If set, GetDependencies will add the notification prefab to the dependency list and LateInitialize will resolve it to an Entity via the PrefabSystem.

Properties

  • None.
    This component exposes only public fields for configuration in the prefab; no runtime properties are declared on this MonoBehaviour.

Constructors

  • No explicit constructors defined.
    The class relies on the default parameterless constructor provided by the runtime/MonoBehaviour system.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds any referenced prefabs that this component depends on. Specifically, if m_ConnectionWarningNotification is set it is added to the provided prefabs list so it will be included/loaded with the prefab graph.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Declares the ECS component types that should be present on entities created from this prefab. Adds read/write access to ResourceConnectionData, i.e. ComponentType.ReadWrite().

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds additional ECS component types depending on what other component types are present on the archetype being built:

  • If the archetype contains Node, Edge, or Game.Objects.Object components then Game.Net.ResourceConnection is added (ReadWrite). This ensures the proper net/object-specific component is included for entities that represent nodes, edges, or game objects.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Finalizes runtime component data when the prefab entity is created. Behavior:

  • Resolves the configured m_Resource to a runtime resource object via EconomyUtils.GetResource and writes that into a new ResourceConnectionData instance.
  • If m_ConnectionWarningNotification is set, obtains the corresponding notification entity from the PrefabSystem and stores it in ResourceConnectionData.m_ConnectionWarningNotification.
  • Writes the ResourceConnectionData into the entity using entityManager.SetComponentData(entity, componentData).
  • Note: This method uses entityManager.World.GetOrCreateSystemManaged() to resolve referenced prefabs.

Usage Example

// Example: reading the ResourceConnectionData on an entity (e.g. inside a system)
public void ReadResourceConnection(EntityManager em, Entity e)
{
    if (em.HasComponent<ResourceConnectionData>(e))
    {
        var data = em.GetComponentData<ResourceConnectionData>(e);
        var runtimeResource = data.m_Resource; // resolved resource from EconomyUtils.GetResource
        var warningEntity = data.m_ConnectionWarningNotification; // may be Entity.Null if not set

        // Use runtimeResource and optionally spawn/show warning using warningEntity...
    }
}

Notes and implementation tips: - Ensure the PrefabSystem is available in the world when LateInitialize runs; the component accesses it to resolve notification prefabs to entities. - The component only sets up the ResourceConnectionData; other systems are expected to process ResourceConnectionData/Game.Net.ResourceConnection to implement actual resource flow, UI warnings, etc. - GetArchetypeComponents uses the presence of Node/Edge/Game.Objects.Object component types to decide where to add Game.Net.ResourceConnection — this matches different kinds of prefab ownership (net nodes, edges, or general objects).