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#include "Components/BsCDecal.h"
4#include "Private/RTTI/BsCDecalRTTI.h"
5#include "Scene/BsSceneManager.h"
6
7namespace bs
8{
9 CDecal::CDecal()
10 {
11 setFlag(ComponentFlag::AlwaysRun, true);
12 setName("Decal");
13 }
14
15 CDecal::CDecal(const HSceneObject& parent)
16 : Component(parent)
17 {
18 setFlag(ComponentFlag::AlwaysRun, true);
19 setName("Decal");
20 }
21
22 CDecal::~CDecal()
23 {
24 mInternal->destroy();
25 }
26
27 void CDecal::onInitialized()
28 {
29 // If mInternal already exists this means this object was deserialized,
30 // so all we need to do is initialize it.
31 if (mInternal != nullptr)
32 mInternal->initialize();
33 else
34 mInternal = Decal::create(HMaterial());
35
36 gSceneManager()._bindActor(mInternal, sceneObject());
37 }
38
39 void CDecal::onDestroyed()
40 {
41 gSceneManager()._unbindActor(mInternal);
42 }
43
44 RTTITypeBase* CDecal::getRTTIStatic()
45 {
46 return CDecalRTTI::instance();
47 }
48
49 RTTITypeBase* CDecal::getRTTI() const
50 {
51 return CDecal::getRTTIStatic();
52 }
53}
54