Skip to content

Game.UI.InGame.CompanyUIUtils

Assembly:
Assembly-CSharp

Namespace:
Game.UI.InGame

Type:
public static class CompanyUIUtils

Base:
System.Object

Summary:
Utility helpers for UI code to determine whether a building/entity has an associated company (renter company) and to convert a numeric profit value into the game's CompanyProfitabilityKey ranking. Provides both a classic EntityManager-based overload and an ECS-friendly overload that uses BufferLookup/ComponentLookup, so it can be used from different execution contexts (main thread or jobs/Systems). Useful when drawing or interacting with company-related UI for buildings that host commercial or industrial properties.


Fields

This static class defines no instance or static fields.

  • None
    This class contains only stateless helper methods; there are no stored fields.

Properties

This class declares no properties.

  • None
    All functionality is exposed through static methods.

Constructors

  • N/A
    This is a static utility class; it cannot be instantiated and has no constructors.

Methods

  • public static bool HasCompany(EntityManager entityManager, Entity entity, Entity prefab, out Entity company)
    Checks whether a given building entity has a renter that is a company, using the provided EntityManager. Returns true if the prefab has commercial or industrial properties (so it can host a company) and out-parameters the first company Entity found in the building's Renter buffer; otherwise returns false and sets company to Entity.Null.

Parameters: - entityManager: The EntityManager to query components and buffers. - entity: The building instance entity to check for Renter buffer. - prefab: The building prefab entity to check BuildingPropertyData for commercial/industrial properties. - company (out): When true, contains the company Entity found (first matching renter that has CompanyData).

Remarks: - First ensures the prefab has BuildingPropertyData and that it contains at least one commercial or industrial property. - Reads the DynamicBuffer from the entity (if present) and iterates renters to find one that has a CompanyData component. - Returns true if the prefab is a commercial/industrial building regardless of whether a company was found; caller should check the out company == Entity.Null to know if a company was present.

  • public static bool HasCompany(Entity entity, Entity prefab, ref BufferLookup<Renter> renterFromEntity, ref ComponentLookup<BuildingPropertyData> buildingPropertyDataFromEntity, ref ComponentLookup<CompanyData> companyDataFromEntity, out Entity company)
    ECS-system-friendly version that performs the same overall check but uses BufferLookup and ComponentLookup (useful inside ISystem/ISystem-like contexts or jobs where you have cached lookups). Returns true if the prefab contains commercial/industrial properties and sets the out company to the first renter entity that has CompanyData.

Parameters: - entity: The building instance entity to check for Renter buffer. - prefab: The building prefab entity to check BuildingPropertyData for commercial/industrial properties. - renterFromEntity: BufferLookup used to check and read the Renter buffer from the entity. - buildingPropertyDataFromEntity: ComponentLookup used to read the prefab's property data. - companyDataFromEntity: ComponentLookup used to test whether a renter entity is a company. - company (out): When true, contains the first company Entity found; otherwise Entity.Null.

Remarks: - Mirrors the EntityManager-based overload but is designed for use in systems that hold BufferLookup/ComponentLookup references.

  • public static CompanyProfitabilityKey GetProfitabilityKey(int profit)
    Maps a numeric profit value to the CompanyProfitabilityKey enum used by UI to indicate company financial state.

Mapping logic: - profit > 128 => CompanyProfitabilityKey.Profitable - profit > 32 => CompanyProfitabilityKey.GettingBy - profit > -64 => CompanyProfitabilityKey.BreakingEven - profit > -182 => CompanyProfitabilityKey.LosingMoney - otherwise => CompanyProfitabilityKey.Bankrupt

Remarks: - Thresholds are hard-coded in this helper; adjust only if you want different UI buckets for profitability.

Usage Example

// Using EntityManager-based overload (typical in legacy/main-thread code)
Entity company;
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity buildingEntity = /* some building entity */;
Entity buildingPrefab = /* building prefab entity */;

if (CompanyUIUtils.HasCompany(em, buildingEntity, buildingPrefab, out company))
{
    if (company != Entity.Null)
    {
        // building has a company renter; show company UI
    }
    else
    {
        // building supports companies (commercial/industrial) but none present
    }
}

// Using BufferLookup/ComponentLookup overload (inside a System where you have lookups)
BufferLookup<Renter> renterFromEntity = /* obtained in OnCreate/OnUpdate */;
ComponentLookup<BuildingPropertyData> buildingPropertyDataFromEntity = /* obtained */;
ComponentLookup<CompanyData> companyDataFromEntity = /* obtained */;

if (CompanyUIUtils.HasCompany(buildingEntity, buildingPrefab, ref renterFromEntity, ref buildingPropertyDataFromEntity, ref companyDataFromEntity, out company))
{
    // same semantics as above
}

// Converting profit to UI key
int monthlyProfit = 45;
CompanyProfitabilityKey key = CompanyUIUtils.GetProfitabilityKey(monthlyProfit);
// key == CompanyProfitabilityKey.GettingBy

Notes and tips: - The HasCompany methods first check the prefab's BuildingPropertyData for commercial/industrial properties. They return true for buildings that can host companies even if no company is currently present; always check the out company value. - Prefer the BufferLookup/ComponentLookup overload inside ECS Systems for better performance and safety; use the EntityManager overload in code paths where you have the EntityManager directly (editor tools, legacy code, or UI callbacks running on main thread). - The profit thresholds are tuned to the game's UI categories — change with care if you want different thresholds.