Plasma Engine  2.0
Loading...
Searching...
No Matches
PrefabReferenceComponent.h
1#pragma once
2
3#include <Core/Prefabs/PrefabResource.h>
4#include <Core/World/Component.h>
5#include <Core/World/World.h>
6#include <Foundation/Containers/ArrayMap.h>
7#include <Foundation/Types/RangeView.h>
8
10
11class PL_CORE_DLL plPrefabReferenceComponentManager : public plComponentManager<plPrefabReferenceComponent, plBlockStorageType::Compact>
12{
13public:
16
17 virtual void Initialize() override;
18
19 void Update(const plWorldModule::UpdateContext& context);
20 void AddToUpdateList(plPrefabReferenceComponent* pComponent);
21
22private:
23 void ResourceEventHandler(const plResourceEvent& e);
24
25 plDeque<plComponentHandle> m_ComponentsToUpdate;
26};
27
36class PL_CORE_DLL plPrefabReferenceComponent : public plComponent
37{
39
41 // plComponent
42
43public:
44 virtual void SerializeComponent(plWorldWriter& inout_stream) const override;
45 virtual void DeserializeComponent(plWorldReader& inout_stream) override;
46
47protected:
48 virtual void OnActivated() override;
49 virtual void OnDeactivated() override;
50
51 virtual void Deinitialize() override;
52 virtual void OnSimulationStarted() override;
53
54
56 // plPrefabReferenceComponent
57
58public:
61
62 void SetPrefabFile(const char* szFile); // [ property ]
63 const char* GetPrefabFile() const; // [ property ]
64
65 void SetPrefab(const plPrefabResourceHandle& hPrefab); // [ property ]
66 PL_ALWAYS_INLINE const plPrefabResourceHandle& GetPrefab() const { return m_hPrefab; } // [ property ]
67
68 const plRangeView<const char*, plUInt32> GetParameters() const; // [ property ] (exposed parameter)
69 void SetParameter(const char* szKey, const plVariant& value); // [ property ] (exposed parameter)
70 void RemoveParameter(const char* szKey); // [ property ] (exposed parameter)
71 bool GetParameter(const char* szKey, plVariant& out_value) const; // [ property ] (exposed parameter)
72
73 static void SerializePrefabParameters(const plWorld& world, plWorldWriter& inout_stream, plArrayMap<plHashedString, plVariant> parameters);
74 static void DeserializePrefabParameters(plArrayMap<plHashedString, plVariant>& out_parameters, plWorldReader& inout_stream);
75
76private:
77 void InstantiatePrefab();
78 void ClearPreviousInstances();
79
80 plPrefabResourceHandle m_hPrefab;
82 bool m_bInUpdateList = false;
83};
See plArrayMapBase for details.
Definition ArrayMap.h:149
Base class of all component types.
Definition Component.h:25
Definition ComponentManager.h:88
Definition Deque.h:270
The central component to instantiate prefabs.
Definition PrefabReferenceComponent.h:37
Definition PrefabReferenceComponent.h:12
This class uses delegates to define a range of values that can be enumerated using a forward iterator...
Definition RangeView.h:24
plVariant is a class that can store different types of variables, which is useful in situations where...
Definition Variant.h:44
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition World.h:22
virtual void OnSimulationStarted()
This method is called at the start of the next world update when the world is simulated....
Definition WorldModule.h:105
virtual void Initialize()
This method is called after the constructor. A derived type can override this method to do initializa...
Definition WorldModule.h:98
virtual void Deinitialize()
This method is called before the destructor. A derived type can override this method to do deinitiali...
Definition WorldModule.h:101
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition WorldReader.h:47
Stores an entire plWorld in a stream.
Definition WorldWriter.h:13
These events may be sent by a specific plResource or by the plResourceManager.
Definition Declarations.h:22
Definition WorldModule.h:33