Game.Prefabs.SpacePrefab
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: AreaPrefab
Summary:
SpacePrefab is a prefab-type MonoBehaviour used to define an "area" prefab for space-type areas in the game's ECS workflow. It registers which ECS component types should be present on entities that use this prefab (prefab components) and which component types should be present on the entity archetype created from this prefab (archetype components). The class is annotated with [ComponentMenu("Areas/", new Type[] { })], so it appears under the Areas menu in the Unity Component menu for authoring.
Fields
- This class declares no instance or static fields of its own. It only overrides methods inherited from AreaPrefab to modify component registration.
Properties
- This class declares no properties.
Constructors
public SpacePrefab()
This class does not declare an explicit constructor. The default parameterless constructor (inherited from System.Object/MonoBehaviour) is used.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the runtime (prefab) component types that should be present on entities instantiated from this prefab. Implementation details:- Calls
base.GetPrefabComponents(components)
to include any area-related components provided by AreaPrefab. - Adds
ComponentType.ReadWrite<SpaceData>()
— registers the SpaceData component for read/write access on prefab entities. -
Adds
ComponentType.ReadWrite<AreaGeometryData>()
— registers geometry-related data for the area on prefab entities. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the archetype component types that should be present on the entity archetype created for this prefab. Implementation details: - Calls
base.GetArchetypeComponents(components)
to include base area archetype components. - Adds
ComponentType.ReadWrite<Space>()
— includes the runtime Space tag/struct on the entity archetype. - Adds
ComponentType.ReadWrite<Geometry>()
— includes geometry component on the entity archetype.
Notes:
- ComponentType.ReadWrite
Usage Example
// A simple extension that adds an extra component to the prefab and archetype.
[ComponentMenu("Areas/", new Type[] { })]
public class CustomSpacePrefab : SpacePrefab
{
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
base.GetPrefabComponents(components);
// Add a custom data component to prefab instances
components.Add(ComponentType.ReadWrite<MyCustomAreaData>());
}
public override void GetArchetypeComponents(HashSet<ComponentType> components)
{
base.GetArchetypeComponents(components);
// Ensure the archetype contains an extra component type
components.Add(ComponentType.ReadWrite<MyCustomAreaTag>());
}
}
This shows how to extend SpacePrefab to register additional components for both the prefab instances and their archetypes.