-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticleSystem.cpp
76 lines (67 loc) · 2.3 KB
/
ParticleSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "pch.h"
#include "ParticleSystem.h"
#include "VisPredComponents.h"
#include "EventManager.h"
ParticleSystem::ParticleSystem(std::shared_ptr<SceneManager> scenemanager):System(scenemanager)
{
EventManager::GetInstance().Subscribe("OnFollowParticle", CreateSubscriber(&ParticleSystem::OnFollowParticle));
}
void ParticleSystem::OnFollowParticle(std::any data)
{
// data에서 엔티티 ID를 추출하고 해당 엔티티를 가져옴
auto entityID = std::any_cast<uint32_t>(data);
auto entity = GetSceneManager()->GetEntity(entityID);
if (!entity || !entity->HasComponent<ParticleOwnerComponent>())
return;
// ParticleOwnerComponent를 가져오고 관련 파티클이 있는지 확인
auto smokecomp = entity->GetComponent<ParticleOwnerComponent>();
if (smokecomp->ParticleName.empty())
return;
COMPLOOP(ParticleComponent, particle)
{
auto name = particle.GetComponent<IDComponent>()->Name;
if (name != smokecomp->ParticleName)
continue;
if (particle.IsPlaying)
{
if (particle.HasComponent<FollowComponent>())
{
auto followComp = particle.GetComponent<FollowComponent>();
if (followComp->FollowingEntityID == entityID)
{
particle.Restart = true;
break;
}
}
continue;
}
// 파티클을 시작하고 엔티티를 따라가도록 설정
particle.Restart = true;
particle.IsPlaying = true;
if (particle.HasComponent<FollowComponent>())
{
auto followComp = particle.GetComponent<FollowComponent>();
followComp->FollowingEntityID = entityID;
followComp->Isfollowing = true;
}
break;
}
}
void ParticleSystem::FixedUpdate(float deltaTime)
{
COMPLOOP(FollowComponent, comp)
{
if (!comp.Isfollowing)
continue;
auto entity =GetSceneManager()->GetEntity(comp.FollowingEntityID);
if (!entity)
{
comp.Isfollowing = false;
continue;
}
auto transform = entity->GetComponent<TransformComponent>();
auto followtrans = comp.GetComponent<TransformComponent>();
followtrans->SetWorldLocation(transform->World_Location);
followtrans->SetWorldRotation(transform->World_Rotation);
}
}