Game.Prefabs.Localization
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: public class
Base: ComponentBase
Summary:
Localization is a component used on prefab definitions to hold a localization identifier string. The component is annotated with a Unity ComponentMenu attribute ("Localization/") so it can be created/assigned from the Unity inspector. The class provides hooks (GetPrefabComponents, GetArchetypeComponents) that are invoked when building ECS prefab entities and archetypes; these methods should contribute the component types that the prefab/archetype requires.
Fields
public string m_LocalizationID
Holds the identifier/key used by the game's localization system for the prefab. This is a simple serializable field intended to be set in the inspector or via prefab data. Default is null/empty if not assigned.
Properties
- (none)
This class exposes no properties; it uses a public field for the localization ID.
Constructors
public Localization()
Default parameterless constructor generated by the compiler. No custom initialization logic is present in the source.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Called when collecting component types required by a prefab. The method in the provided source is empty (no component types are added). In a functional mod, this override should add the appropriate ComponentType for this component (for example, a read/write component type for the Localization component) and any dependent components the prefab needs.
Suggested implementation:
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
// Ensure the ECS prefab includes this component type so instances get the Localization component.
components.Add(ComponentType.ReadWrite<Localization>());
// Add other required component types here (e.g., a reference to a localization table component).
}
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Called when building archetypes that represent entities of this prefab type. Like GetPrefabComponents, the provided method body is empty. You should add the same component types you require on instances created from this archetype.
Suggested implementation:
public override void GetArchetypeComponents(HashSet<ComponentType> components)
{
components.Add(ComponentType.ReadWrite<Localization>());
}
Both methods serve to inform the ECS conversion/build pipeline which component types must be present on the resulting entity prefabs/archetypes. Leaving them empty means the conversion pipeline will not automatically add a corresponding ECS component for this MonoBehaviour-like component—implement them to ensure runtime entities include the Localization component.
Usage Example
// Example of a concrete implementation that registers the Localization component type
// so converted prefab entities/archetypes include it.
public class Localization : ComponentBase
{
public string m_LocalizationID;
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
components.Add(ComponentType.ReadWrite<Localization>());
}
public override void GetArchetypeComponents(HashSet<ComponentType> components)
{
components.Add(ComponentType.ReadWrite<Localization>());
}
}
Notes: - The class is marked with [ComponentMenu("Localization/", new Type[] { })], which places it under the "Localization/" menu in Unity's "Add Component" UI. - If your runtime ECS expects the localization data as a different component type (for example, a POD IComponentData struct used by systems), adapt the methods to add that ECS component type instead of the MonoBehaviour-derived type.