Game.Prefabs.SpawnableArea
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component used to mark a prefab area as containing spawnable placeholder area prefabs. Holds references to one or more AreaPrefab placeholders and a probability value (0–100) that can be used by spawning systems to determine whether to spawn from this area. Also declares required ECS components used when converting this prefab for runtime use.
Fields
-
public AreaPrefab[] m_Placeholders
Holds the list of AreaPrefab references that may be spawned from this area. Populated in the inspector. The component's GetDependencies method will add each referenced AreaPrefab to the dependency list so they get included/processed together. -
public int m_Probability
Annotated with [Range(0f, 100f)]. Represents the probability (percentage) of selecting/using this area when a spawner evaluates candidates. Default value in code is 100.
Properties
- (none)
This component exposes no C# properties beyond the public fields shown above.
Constructors
public SpawnableArea()
No explicit constructor is defined in the script — the default parameterless constructor provided by the runtime is used. The component is intended to be configured via the Unity inspector.
Methods
public override void GetDependencies(List<PrefabBase> prefabs)
Adds referenced placeholder prefabs to the provided dependency list. Implementation:- Calls base.GetDependencies(prefabs).
-
Iterates over m_Placeholders and adds each AreaPrefab to the prefabs list. This ensures placeholder prefabs are included when building/converting prefab dependencies.
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds required ECS component types for this prefab conversion. Implementation: -
Adds ComponentType.ReadWrite
() to the components set, indicating runtime entities derived from this prefab require a SpawnableObjectData component. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Empty override. No additional archetype-level components are added by this component.
Usage Example
// Example: manually collecting dependencies from a SpawnableArea instance
var spawnableArea = someGameObject.GetComponent<Game.Prefabs.SpawnableArea>();
var deps = new List<PrefabBase>();
spawnableArea.GetDependencies(deps);
// Example: what GetPrefabComponents adds
var components = new HashSet<Unity.Entities.ComponentType>();
spawnableArea.GetPrefabComponents(components);
// components will contain ComponentType.ReadWrite<SpawnableObjectData>()
Additional notes: - The component has a [ComponentMenu("Areas/", typeof(AreaPrefab))] attribute so it appears under Areas/ in the component menu and hints at its relationship to AreaPrefab. - m_Probability is intended as a percentage; how it's interpreted (e.g., relative weighting vs. absolute chance) depends on the spawning system that consumes this component.