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 "Particles/BsParticleSystem.h"
7#include "Scene/BsComponent.h"
8
9namespace bs
10{
11 /** @addtogroup Components-Core
12 * @{
13 */
14
15 /**
16 * @copydoc ParticleSystem
17 *
18 * @note Wraps ParticleSystem as a Component.
19 */
20 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Particles,n:ParticleSystem) CParticleSystem : public Component
21 {
22 public:
23 CParticleSystem(const HSceneObject& parent);
24 virtual ~CParticleSystem() = default;
25
26 /** @copydoc ParticleSystem::setSettings */
27 BS_SCRIPT_EXPORT(pr:setter,n:Settings,passByCopy,inline)
28 void setSettings(const ParticleSystemSettings& settings);
29
30 /** @copydoc ParticleSystem::getSettings */
31 BS_SCRIPT_EXPORT(pr:getter,n:Settings,passByCopy)
32 const ParticleSystemSettings& getSettings() const { return mSettings; }
33
34 /** @copydoc ParticleSystem::setGpuSimulationSettings */
35 BS_SCRIPT_EXPORT(pr:setter,n:GpuSimulationSettings,passByCopy)
36 void setGpuSimulationSettings(const ParticleGpuSimulationSettings& settings);
37
38 /** @copydoc ParticleSystem::getGpuSimulationSettings */
39 BS_SCRIPT_EXPORT(pr:getter,n:GpuSimulationSettings,passByCopy)
40 const ParticleGpuSimulationSettings& getGpuSimulationSettings() const { return mGpuSimulationSettings; }
41
42 /** @copydoc ParticleSystem::setEmitters */
43 BS_SCRIPT_EXPORT(pr:setter,n:Emitters)
44 void setEmitters(const Vector<SPtr<ParticleEmitter>>& emitters);
45
46 /** @copydoc ParticleSystem::getEmitters */
47 BS_SCRIPT_EXPORT(pr:getter,n:Emitters)
48 const Vector<SPtr<ParticleEmitter>>& getEmitters() const { return mEmitters; }
49
50 /** @copydoc ParticleSystem::setEvolvers */
51 BS_SCRIPT_EXPORT(pr:setter,n:Evolvers)
52 void setEvolvers(const Vector<SPtr<ParticleEvolver>>& evolvers);
53
54 /** @copydoc ParticleSystem::getEvolvers */
55 BS_SCRIPT_EXPORT(pr:getter,n:Evolvers)
56 const Vector<SPtr<ParticleEvolver>>& getEvolvers() const { return mEvolvers; }
57
58 /** @copydoc ParticleSystem::setLayer() */
59 BS_SCRIPT_EXPORT(pr:setter,n:Layer,layerMask)
60 void setLayer(UINT64 layer);
61
62 /** @copydoc ParticleSystem::getLayer() */
63 BS_SCRIPT_EXPORT(pr:getter,n:Layer,layerMask)
64 UINT64 getLayer() const { return mLayer; }
65
66 /** @name Internal
67 * @{
68 */
69
70 /**
71 * Enables or disabled preview mode. Preview mode allows the particle system to play while the game is not running,
72 * primarily for preview purposes in the editor. Returns true if the preview mode was enabled, false if it was
73 * disabled or enabling preview failed.
74 */
75 BS_SCRIPT_EXPORT(n:TogglePreviewMode,v:internal)
76 bool _togglePreviewMode(bool enabled);
77
78 /** Returns the ParticleSystem implementation wrapped by this component. */
79 ParticleSystem* _getInternal() const { return mInternal.get(); }
80
81 /** @} */
82
83 /************************************************************************/
84 /* COMPONENT OVERRIDES */
85 /************************************************************************/
86 protected:
87 friend class SceneObject;
88
89 /** @copydoc Component::onDestroyed() */
90 void onDestroyed() override;
91
92 /** @copydoc Component::onDisabled() */
93 void onDisabled() override;
94
95 /** @copydoc Component::onEnabled() */
96 void onEnabled() override;
97
98 protected:
99 using Component::destroyInternal;
100
101 /** Creates the internal representation of the ParticleSystem and restores the values saved by the Component. */
102 void restoreInternal();
103
104 /** Destroys the internal ParticleSystem representation. */
105 void destroyInternal();
106
107 SPtr<ParticleSystem> mInternal;
108
109 ParticleSystemSettings mSettings;
110 ParticleGpuSimulationSettings mGpuSimulationSettings;
111 Vector<SPtr<ParticleEmitter>> mEmitters;
112 Vector<SPtr<ParticleEvolver>> mEvolvers;
113 UINT64 mLayer = 1;
114
115 bool mPreviewMode = false;
116
117 /************************************************************************/
118 /* RTTI */
119 /************************************************************************/
120 public:
121 friend class CParticleSystemRTTI;
122 static RTTITypeBase* getRTTIStatic();
123 RTTITypeBase* getRTTI() const override;
124
125 protected:
126 CParticleSystem(); // Serialization only
127 };
128
129 /** @} */
130}