Skip to content

Game.Prefabs.ElectricityOutsideConnection

Assembly: Assembly-CSharp (typical for Cities: Skylines 2 mod assemblies)
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Prefab component used by the game to represent an electricity outside-connection object. This class is a lightweight prefab descriptor that participates in entity archetype composition. It is annotated with a ComponentMenu attribute to place it under the "Objects/" menu and to indicate it is related to StaticObjectPrefab and MarkerObjectPrefab. The prefab does not add any runtime prefab-only components itself, but it contributes two runtime components to the entity archetype: Game.Objects.ElectricityOutsideConnection and Game.Objects.OutsideConnection. The Initialize method currently only delegates to the base implementation and can be extended to perform prefab-specific initialization on the created entity.


Fields

  • None
    This class declares no instance or static fields.

Properties

  • None
    No properties are declared on this class.

Constructors

  • public ElectricityOutsideConnection()
    Implicit default constructor. The source file does not declare any custom constructors; the compiler-provided parameterless constructor will be used.

Methods

  • public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    This override is intentionally empty in the current implementation. Use this method to add components that should be present on the prefab GameObject / prefab-level representation (if your modming needs require prefab-only components).

  • public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
    Adds the entity-components that should be part of the entity archetype created from this prefab. Current implementation adds:

  • ComponentType.ReadWrite<Game.Objects.ElectricityOutsideConnection>()
  • ComponentType.ReadWrite<Game.Objects.OutsideConnection>() These make the runtime entity carry the data and behavior associated with an electricity outside connection.

  • public override void Initialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
    Calls base.Initialize(entityManager, entity). Override this method to perform any additional per-entity initialization (setting component values, adding buffers, enabling child objects, etc.). As implemented, it defers to the base class only.

Usage Example

// Example: creating an entity from this prefab at runtime
using System;
using System.Linq;
using System.Collections.Generic;
using Unity.Entities;
using Game.Prefabs;

// Create the prefab descriptor and collect archetype component types
var prefab = new ElectricityOutsideConnection();
var componentTypes = new HashSet<ComponentType>();
prefab.GetArchetypeComponents(componentTypes);

// Create an archetype and then an entity from it
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var archetype = entityManager.CreateArchetype(componentTypes.ToArray());
var entity = entityManager.CreateEntity(archetype);

// Perform prefab initialization on the new entity
prefab.Initialize(entityManager, entity);

// After this point the entity will have the Game.Objects.ElectricityOutsideConnection
// and Game.Objects.OutsideConnection components and is ready for further setup.

Additional notes: - The class is intended as a bridge between prefab authoring and ECS archetypes. If you need to attach additional data components or configure initial values, add them in GetArchetypeComponents and set values in Initialize. - The ComponentMenu attribute places this prefab entry under "Objects/" and documents its relation to StaticObjectPrefab and MarkerObjectPrefab in editor tooling.