-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAnimationState.cpp
More file actions
100 lines (87 loc) · 2.24 KB
/
Copy pathAnimationState.cpp
File metadata and controls
100 lines (87 loc) · 2.24 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "AnimationState.h"
#include "AniBehavior.h"
#include "AnimationBehviourFatory.h"
#include "AnimationController.h"
#include "Animator.h"
#include "ConditionParameter.h"
#include "ManagedAniBehavior.h"
AnimationState::AnimationState()
{
}
AnimationState::~AnimationState()
{
behaviour.reset();
}
AnimationState::AnimationState(AnimationController* Owner, std::string name) : m_ownerController(Owner), m_name(name)
{
}
std::vector<AniTransition*> AnimationState::FindTransitions(const std::string& toStateName)
{
std::vector<AniTransition*> aniTransitions;
for (auto& sharedtrans : Transitions)
{
auto trans = sharedtrans.get();
if (trans->GetNextState() == toStateName)
aniTransitions.push_back(trans);
}
return aniTransitions;
}
void AnimationState::SetBehaviour(std::string name, bool isReload)
{
if (isReload)
{
behaviour = nullptr;
}
else
{
behaviourName = name;
behaviour.reset();
behaviour = nullptr;
}
if (behaviourName.empty())
{
return;
}
// C++ 핫리로드 은퇴(9-4) — 애니메이션 상태 스크립트는 C#(ManagedAniBehavior)만 지원한다.
if (ClrHost::Get().HasAniBehaviour(behaviourName))
{
auto managed = std::make_shared<ManagedAniBehavior>(behaviourName);
if (managed->HasInstance())
{
behaviour = managed;
}
}
if(behaviour == nullptr) return;
behaviour->m_ownerController = this->m_ownerController;
}
void AnimationState::UpdateAnimationSpeed()
{
ConditionParameter* parameter = m_ownerController->GetOwner()->FindParameter(animationSpeedParameterName);
if (parameter)
{
multiplerAnimationSpeed = parameter->fValue;
}
}
nlohmann::json AnimationState::Serialize()
{
nlohmann::json j;
j["state_name"] = m_name;
j["behaviourName"] = behaviourName;
j["animationIndex"] = AnimationIndex;
j["animationSpeed"] = animationSpeed;
j["multiplerAnimationSpeed"] = multiplerAnimationSpeed;
j["animationSpeedParameterName"] = animationSpeedParameterName;
j["useMultipler"] = (int)useMultipler;
j["m_isAny"] = m_isAny;
nlohmann::json transitionsJson = nlohmann::json::array();
for (auto& trans : Transitions)
{
transitionsJson.push_back(trans->Serialize());
}
j["transitions"] = transitionsJson;
return j;
}
AnimationState AnimationState::Deserialize()
{
return AnimationState();
}