Global service for managing prefab factories and component creation.
More...
#include <prefab_service.h>
Global service for managing prefab factories and component creation.
This is a singleton that maintains a mapping of prefab type IDs to factory functions. When a network snapshot arrives with an object of an unknown type, the service can instantiate it with the correct components.
Usage:
◆ PrefabService() [1/3]
| PrefabService::PrefabService |
( |
| ) |
|
|
default |
◆ PrefabService() [2/3]
◆ PrefabService() [3/3]
◆ clear_all()
| void PrefabService::clear_all |
( |
| ) |
|
Clear all registered prefabs.
◆ get_registered_prefabs()
| std::vector< std::string > PrefabService::get_registered_prefabs |
( |
| ) |
const |
Get all registered prefab type IDs.
◆ has_prefab()
| bool PrefabService::has_prefab |
( |
const std::string & |
prefab_type_id | ) |
const |
Check if a prefab type is registered.
- Parameters
-
| prefab_type_id | Identifier to check |
- Returns
- True if registered, false otherwise
◆ instantiate()
| std::reference_wrapper< GameObject > PrefabService::instantiate |
( |
const std::string & |
prefab_type_id, |
|
|
Scene & |
scene, |
|
|
const std::string & |
name |
|
) |
| |
Instantiate a GameObject from a registered prefab.
- Parameters
-
| prefab_type_id | Type ID of the prefab to instantiate |
| scene | Scene to add the object to |
| name | Name to assign to the created GameObject |
- Returns
- Reference to the created GameObject
- Exceptions
-
| std::runtime_error | if prefab_type_id is not registered |
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ register_prefab()
| void PrefabService::register_prefab |
( |
const std::string & |
prefab_type_id, |
|
|
const PrefabFactory & |
factory |
|
) |
| |
Register a prefab factory for a given type ID.
- Parameters
-
| prefab_type_id | Unique identifier for this prefab type |
| factory | Factory function that creates the GameObject with components |
◆ unregister_prefab()
| void PrefabService::unregister_prefab |
( |
const std::string & |
prefab_type_id | ) |
|
Unregister a previously registered prefab factory.
- Parameters
-
| prefab_type_id | Identifier of the prefab to unregister |
The documentation for this class was generated from the following file: