Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StdAfx.h"
- #include "ParticleEmitter.h"
- #include "Game/GameFactory.h"
- #include "FlowNodes/Helpers/FlowGameEntityNode.h"
- #include <Cry3DEngine/I3DEngine.h>
- #include <CryParticleSystem/IParticlesPfx2.h>
- class CParticleEmitterRegistrator
- : public IEntityRegistrator
- {
- virtual void Register() override
- {
- CParticleEmitter::Register();
- }
- };
- CParticleEmitterRegistrator g_particleEmitterRegistrator;
- CParticleEmitter::CParticleEmitter()
- : m_particleSlot(-1)
- {
- }
- void CParticleEmitter::Register()
- {
- auto properties = new SNativeEntityPropertyInfo[eNumProperties];
- memset(properties, 0, sizeof(SNativeEntityPropertyInfo) * eNumProperties);
- RegisterEntityProperty<bool>(properties, eProperty_Active, "Active", "1", "", 0, 1);
- RegisterEntityPropertyObject(properties, eProperty_EffectName, "ParticleEffect", "", "");
- // Finally, register the entity class so that instances can be created later on either via Launcher or Editor
- CGameFactory::RegisterNativeEntity<CParticleEmitter>("ParticleEmitter", "UserStuff", "Particles.bmp", 0u, properties, eNumProperties);
- // Create flownode
- CGameEntityNodeFactory &nodeFactory = CGameFactory::RegisterEntityFlowNode("ParticleEmitter");
- // Define input ports, and the callback function for when they are triggered
- std::vector<SInputPortConfig> inputs;
- inputs.push_back(InputPortConfig_Void("TurnOn", "Turns on"));
- inputs.push_back(InputPortConfig_Void("TurnOff", "Turns off"));
- nodeFactory.AddInputs(inputs, OnFlowgraphActivation);
- // Mark the factory as complete, indicating that there will be no additional ports
- nodeFactory.Close();
- }
- void CParticleEmitter::PostInit(IGameObject *pGameObject)
- {
- Reset();
- }
- void CParticleEmitter::Reset()
- {
- IEntity& entity = *GetEntity();
- // Check if we have to unload first
- if (m_particleSlot != -1)
- {
- entity.FreeSlot(m_particleSlot);
- m_particleSlot = -1;
- }
- // Check if the light is active
- if (!GetPropertyBool(eProperty_Active))
- return;
- const char *effect = GetPropertyValue(eProperty_EffectName);
- if (strlen(effect) > 0)
- {
- if (IParticleEffect* pEffect = gEnv->pParticleManager->FindEffect(effect, "ParticleEmitter"))
- {
- m_particleSlot = entity.LoadParticleEmitter(0, pEffect);
- }
- }
- }
- void CParticleEmitter::ProcessEvent(SEntityEvent& event)
- {
- if (gEnv->IsDedicated())
- return;
- switch (event.event)
- {
- // Physicalize on level start for Launcher
- case ENTITY_EVENT_START_LEVEL:
- // Editor specific, physicalize on reset, property change or transform change
- case ENTITY_EVENT_RESET:
- case ENTITY_EVENT_EDITOR_PROPERTY_CHANGED:
- case ENTITY_EVENT_XFORM_FINISHED_EDITOR:
- Reset();
- break;
- }
- }
- void CParticleEmitter::OnFlowgraphActivation(EntityId entityId, IFlowNode::SActivationInfo *pActInfo, const class CFlowGameEntityNode *pNode)
- {
- if (auto *pExtension = static_cast<CParticleEmitter *>(QueryExtension(entityId)))
- {
- if (IsPortActive(pActInfo, eInputPort_TurnOn))
- {
- pExtension->SetPropertyBool(eProperty_Active, true);
- }
- else if (IsPortActive(pActInfo, eInputPort_TurnOff))
- {
- pExtension->SetPropertyBool(eProperty_Active, false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement