Skip to content

Game.Prefabs.CompanyPrefab

Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs

Type: class

Base: ArchetypePrefab

Summary:
Prefab class that defines a company archetype used by the game to spawn commercial or industrial companies. The prefab exposes a Zone type (Commercial or Industrial) and a profitability value. At runtime this prefab contributes the appropriate ECS component types to prefabs and archetypes depending on the configured zone (e.g., CommercialCompanyData / CommercialCompany for commercial zone, IndustrialCompanyData / IndustrialCompany for industrial zone), and always adds common company-related components such as CompanyData, CompanyBrandElement, CompanyNotifications, etc. The class is annotated with a ComponentMenu attribute so it appears under the Companies menu in the editor.


Fields

  • public AreaType zone
    Used to select the area/industry type for the company prefab. When zone == AreaType.Commercial the prefab will include commercial-specific components (CommercialCompanyData / CommercialCompany). When zone == AreaType.Industrial the prefab will include industrial-specific components (IndustrialCompanyData / IndustrialCompany). This determines which specialized company behavior and data components are added to created entities.

  • public float profitability
    A float value representing the company's profitability modifier or default profitability. The shown class does not internally use this field beyond holding the value; other systems or runtime logic are expected to read this value to influence company economic behavior.

Properties

  • None declared on this class. All configuration is done via public fields.

Constructors

  • public CompanyPrefab()
    No explicit constructor is defined in the source. The default constructor provided by the runtime is used. Any initialization should be done in editor-assigned fields or by systems that instantiate/configure the prefab.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Populates the provided set with component types that should be attached to the prefab instance. Calls the base implementation then:
  • If zone == AreaType.Commercial, adds ComponentType.ReadWrite()
  • Else if zone == AreaType.Industrial, adds ComponentType.ReadWrite()
  • Always adds ComponentType.ReadWrite() and ComponentType.ReadWrite() This method controls which component types are present on the prefab asset itself (typically for editor/runtime conversion).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Populates the provided set with component types that should be present on the runtime entity archetype created from this prefab. Calls the base implementation then adds core company components:

  • CompanyData, UpdateFrame, Resources, PropertySeeker, TripNeeded, CompanyNotifications, GuestVehicle (all ReadWrite)
  • If zone == AreaType.Commercial, adds CommercialCompany()
  • Else if zone == AreaType.Industrial, adds IndustrialCompany() This determines the ECS archetype used for instantiated company entities and ensures the entity has the necessary data/behavior components.

Usage Example

// Example: simple prefab configuration (set in editor or by code)
//
// This demonstrates assigning the zone and profitability on a subclass or instance.
// In practice this prefab would be created/edited in the editor and used by conversion systems.

[ComponentMenu("Companies/Custom", new Type[] { })]
public class MyCompanyPrefab : CompanyPrefab
{
    public MyCompanyPrefab()
    {
        // Configure as a commercial company with a profitability modifier
        zone = AreaType.Commercial;
        profitability = 1.1f;
    }

    // Optionally override to customize added components further:
    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        base.GetPrefabComponents(components);
        // add or remove component types if needed
    }
}