Skip to content

Game.Prefabs.PowerLinePrefab

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: NetGeometryPrefab

Summary:
PowerLinePrefab is a prefab class used for power line network geometry. It exposes tuning fields for pylon spacing and sag and participates in the ECS setup by adding the runtime components required for power line entities (PowerLineData, LocalConnectData, DefaultNetLane). It also ensures color components (EdgeColor or NodeColor) are present on the archetype depending on whether Edge or Node components are used.


Fields

  • public float m_MaxPylonDistance
    Maximum allowed distance between pylons (default: 120f). Controls spacing logic for pylon placement along the power line.

  • public float m_Hanging
    A float controlling the hanging/sag of the power line. Used for visual/geometry calculation of the wire sag.

Properties

  • None.
    This type exposes public fields rather than properties for configuration.

Constructors

  • public PowerLinePrefab()
    Default constructor. No custom initialization logic is defined in this class; Unity/engine will instantiate and initialize the prefab object.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that belong to the prefab instances. Implementation:
  • Calls base.GetPrefabComponents(components).
  • Adds ComponentType.ReadWrite(), ComponentType.ReadWrite(), and ComponentType.ReadWrite() to the provided set. These ensure runtime entities created from this prefab have the expected data components for power line behavior.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adjusts the archetype components for entities created from this prefab. Implementation:

  • Calls base.GetArchetypeComponents(components).
  • If the archetype already contains ComponentType.ReadWrite(), adds ComponentType.ReadWrite().
  • Else if it contains ComponentType.ReadWrite(), adds ComponentType.ReadWrite().
  • This ensures color components appropriate to whether the prefab is represented as edges or nodes are present on the archetype.

Usage Example

// Example: customizing a power line prefab in a mod script by subclassing
using System.Collections.Generic;
using Game.Prefabs;
using Unity.Entities;
using UnityEngine;

public class CustomPowerLinePrefab : PowerLinePrefab
{
    void Reset()
    {
        // Tweak defaults shown in Inspector when creating the prefab
        m_MaxPylonDistance = 200f;
        m_Hanging = 2.5f;
    }

    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        base.GetPrefabComponents(components);
        // Optionally add additional components required by your mod:
        // components.Add(ComponentType.ReadWrite<MyCustomComponent>());
    }
}

Notes: - The class is annotated with Unity's ComponentMenu attribute so it appears in the editor menu for net prefabs. - Component types are added via ComponentType.ReadWrite(), which is the pattern used by the game's ECS to declare which components a prefab / archetype will contain.