Skip to content

Game.Prefabs.RandomGenderedLocalization

Assembly:
Assembly-CSharp (game assembly)

Namespace:
Game.Prefabs

Type:
class

Base:
RandomLocalization

Summary:
RandomGenderedLocalization is a component used for localization variants that depend on gender. It extends RandomLocalization by adding separate localization ID fields for male and female variations and ensures the number of variations for the base/localization ID, male ID and female ID match (or it will take the minimum and log a warning). It uses Unity.Mathematics for numeric operations and relies on RandomLocalization utility methods to query variation counts.


Fields

  • public string m_MaleID
    Identifier (localization key) for the male variant set. Used to query how many male variations exist and to pick the correct localized string for male instances.

  • public string m_FemaleID
    Identifier (localization key) for the female variant set. Used to query how many female variations exist and to pick the correct localized string for female instances.

(Notes: RandomGenderedLocalization also uses inherited fields from RandomLocalization/ComponentBase such as m_LocalizationID and base.prefab when querying localization counts. It logs via ComponentBase.baseLog when variation counts differ.)

Properties

  • No new public properties are declared by this class.
    (Behavior relies on inherited members and RandomLocalization's/public API; the class does not introduce extra properties.)

Constructors

  • public RandomGenderedLocalization()
    Default constructor. The class does not define any special construction logic beyond the base class initialization.

Methods

  • protected override int GetLocalizationCount() : System.Int32
    Override of RandomLocalization.GetLocalizationCount. This method:
  • Calls the base implementation to get the count of variations for the primary localization ID (base.m_LocalizationID).
  • Calls RandomLocalization.GetLocalizationIndexCount(base.prefab, m_MaleID) to get the male variation count.
  • Calls RandomLocalization.GetLocalizationIndexCount(base.prefab, m_FemaleID) to get the female variation count.
  • Computes the minimum of the three counts using math.min so the returned count is the largest common number of variants available across the three IDs.
  • If any of the counts differ (so the minimum is smaller than one or more counts), it logs a warning using ComponentBase.baseLog.WarnFormat indicating that all gendered localization IDs should have the same variation count, printing each ID and its count.

Behavioral notes: - Returning the minimum ensures that indexing into variations (by a random index or deterministic variant index) will be safe for all three IDs. - The warning helps authors detect mismatched variant sets in prefabs/localization data.

Usage Example

// Example: initialize or assign gendered localization IDs in a derived component or prefab setup
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Assign the localization keys that hold male/female variants
    m_MaleID = "BUILDING_NAME_MALE";
    m_FemaleID = "BUILDING_NAME_FEMALE";
    // The class will automatically ensure the usable variation count is the minimum of:
    // base.m_LocalizationID, m_MaleID and m_FemaleID and will warn if they differ.
}