ezEngine  Milestone 9
PrefabResource.h
1 #pragma once
2 
3 #include <Core/ResourceManager/Resource.h>
4 #include <Core/WorldSerializer/WorldReader.h>
5 #include <Foundation/Containers/ArrayMap.h>
6 #include <Foundation/Reflection/PropertyPath.h>
7 #include <GameEngine/GameEngineDLL.h>
8 
10 
11 struct EZ_GAMEENGINE_DLL ezPrefabResourceDescriptor
12 {
13 };
14 
15 struct EZ_GAMEENGINE_DLL ezExposedPrefabParameterDesc
16 {
17  ezHashedString m_sExposeName;
18  ezUInt32 m_uiWorldReaderChildObject : 1; // 0 -> use root object array, 1 -> use child object array
19  ezUInt32 m_uiWorldReaderObjectIndex : 31;
20  ezUInt32 m_uiComponentTypeHash = 0; // ezRTTI type name hash to identify which component is meant, 0 -> affects game object
21  ezHashedString m_sProperty; // which property to override
22  ezPropertyPath m_CachedPropertyPath; // cached ezPropertyPath to apply a value to the specified property
23 
24  void Save(ezStreamWriter& stream) const;
25  void Load(ezStreamReader& stream);
26 };
27 
28 class EZ_GAMEENGINE_DLL ezPrefabResource : public ezResource
29 {
30  EZ_ADD_DYNAMIC_REFLECTION(ezPrefabResource, ezResource);
31  EZ_RESOURCE_DECLARE_COMMON_CODE(ezPrefabResource);
32  EZ_RESOURCE_DECLARE_CREATEABLE(ezPrefabResource, ezPrefabResourceDescriptor);
33 
34 public:
36 
38  void InstantiatePrefab(ezWorld& world, const ezTransform& rootTransform, ezGameObjectHandle hParent,
39  ezHybridArray<ezGameObject*, 8>* out_CreatedRootObjects, const ezUInt16* pOverrideTeamID,
40  const ezArrayMap<ezHashedString, ezVariant>* pExposedParamValues);
41 
42  void ApplyExposedParameterValues(const ezArrayMap<ezHashedString, ezVariant>* pExposedParamValues,
43  const ezHybridArray<ezGameObject*, 8>& createdChildObjects,
44  const ezHybridArray<ezGameObject*, 8>& createdRootObjects) const;
45 
46 private:
47  virtual ezResourceLoadDesc UnloadData(Unload WhatToUnload) override;
48  virtual ezResourceLoadDesc UpdateContent(ezStreamReader* Stream) override;
49  virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
50 
51 private:
52  ezUInt32 FindFirstParamWithName(ezUInt32 uiNameHash) const;
53 
54  ezWorldReader m_WorldReader;
56 };
57 
Reads a world description from a stream. Allows to instantiate that world multiple times in different...
Definition: WorldReader.h:12
Definition: PrefabResource.h:11
Interface for binary in (read) streams.
Definition: Stream.h:14
Definition: HybridArray.h:79
Interface for binary out (write) streams.
Definition: Stream.h:86
Definition: PrefabResource.h:28
The base class for all resources.
Definition: Resource.h:9
Definition: PrefabResource.h:15
Describes in which loading state a resource currently is, and how many different quality levels there...
Definition: Declarations.h:96
Stores a path from an object of a given type to a property inside of it. Once initialized to a specif...
Definition: PropertyPath.h:23
A world encapsulates a scene graph of game objects and various component managers and their component...
Definition: World.h:18
This class is optimized to take nearly no memory (sizeof(void*)) and to allow very fast checks whethe...
Definition: HashedString.h:24
A handle to a game object.
Definition: Declarations.h:66
Definition: Resource.h:33