Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
PrefabService Class Reference

Global service for managing prefab factories and component creation. More...

#include <prefab_service.h>

Inheritance diagram for PrefabService:
[legend]

Public Member Functions

 PrefabService ()=default
 
 PrefabService (const PrefabService &)=delete
 
PrefabServiceoperator= (const PrefabService &)=delete
 
 PrefabService (PrefabService &&)=delete
 
PrefabServiceoperator= (PrefabService &&)=delete
 
void register_prefab (const std::string &prefab_type_id, const PrefabFactory &factory)
 Register a prefab factory for a given type ID.
 
void unregister_prefab (const std::string &prefab_type_id)
 Unregister a previously registered prefab factory.
 
bool has_prefab (const std::string &prefab_type_id) const
 Check if a prefab type is registered.
 
std::reference_wrapper< GameObjectinstantiate (const std::string &prefab_type_id, Scene &scene, const std::string &name)
 Instantiate a GameObject from a registered prefab.
 
std::vector< std::string > get_registered_prefabs () const
 Get all registered prefab type IDs.
 
void clear_all ()
 Clear all registered prefabs.
 
- Public Member Functions inherited from IEngineService
virtual ~IEngineService ()=default
 

Detailed Description

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:

Constructor & Destructor Documentation

◆ PrefabService() [1/3]

PrefabService::PrefabService ( )
default

◆ PrefabService() [2/3]

PrefabService::PrefabService ( const PrefabService )
delete

◆ PrefabService() [3/3]

PrefabService::PrefabService ( PrefabService &&  )
delete

Member Function Documentation

◆ 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_idIdentifier 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_idType ID of the prefab to instantiate
sceneScene to add the object to
nameName to assign to the created GameObject
Returns
Reference to the created GameObject
Exceptions
std::runtime_errorif prefab_type_id is not registered

◆ operator=() [1/2]

PrefabService & PrefabService::operator= ( const PrefabService )
delete

◆ operator=() [2/2]

PrefabService & PrefabService::operator= ( PrefabService &&  )
delete

◆ 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_idUnique identifier for this prefab type
factoryFactory 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_idIdentifier of the prefab to unregister

The documentation for this class was generated from the following file: