1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6#include "Reflection/BsRTTIType.h"
7#include "Scene/BsPrefab.h"
8#include "Scene/BsSceneObject.h"
9#include "Utility/BsUtility.h"
10
11namespace bs
12{
13 /** @cond RTTI */
14 /** @addtogroup RTTI-Impl-Core
15 * @{
16 */
17
18 class BS_CORE_EXPORT PrefabRTTI : public RTTIType < Prefab, Resource, PrefabRTTI >
19 {
20 private:
21 BS_BEGIN_RTTI_MEMBERS
22 BS_RTTI_MEMBER_PLAIN(mHash, 1)
23 //BS_RTTI_MEMBER_PLAIN(mNextLinkId, 2)
24 BS_RTTI_MEMBER_PLAIN(mUUID, 3)
25 BS_RTTI_MEMBER_PLAIN(mIsScene, 4)
26 BS_END_RTTI_MEMBERS
27
28 SPtr<SceneObject> getSceneObject(Prefab* obj) { return obj->mRoot.getInternalPtr(); }
29 void setSceneObject(Prefab* obj, SPtr<SceneObject> value) { obj->mRoot = value->getHandle(); }
30
31 public:
32 PrefabRTTI()
33 {
34 addReflectablePtrField("mRoot", 0, &PrefabRTTI::getSceneObject, &PrefabRTTI::setSceneObject);
35 }
36
37 void onDeserializationStarted(IReflectable* ptr, SerializationContext* context) override
38 {
39 BS_ASSERT(context != nullptr && rtti_is_of_type<CoreSerializationContext>(context));
40 auto coreContext = static_cast<CoreSerializationContext*>(context);
41
42 // Make sure external IDs are broken because we do some ID matching when dealing with prefabs and keeping
43 // the invalid external references could cause it to match invalid objects in case they end up having the
44 // same ID.
45 BS_ASSERT(!coreContext->goState);
46 coreContext->goState = bs_shared_ptr_new<GameObjectDeserializationState>(GODM_BreakExternal | GODM_UseNewIds);
47 }
48
49 const String& getRTTIName() override
50 {
51 static String name = "Prefab";
52 return name;
53 }
54
55 UINT32 getRTTIId() override
56 {
57 return TID_Prefab;
58 }
59
60 SPtr<IReflectable> newRTTIObject() override
61 {
62 return Prefab::createEmpty();
63 }
64 };
65
66 /** @} */
67 /** @endcond */
68}
69