-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntityReference.cpp
More file actions
92 lines (72 loc) · 2.32 KB
/
EntityReference.cpp
File metadata and controls
92 lines (72 loc) · 2.32 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
#include "EntityReference.h"
#include "EntityManager.h"
#include <Urho3D/Core/Context.h>
#include <Urho3D/Scene/Scene.h>
#include <Urho3D/SystemUI/Widgets.h>
namespace Urho3D
{
namespace
{
const auto nullEntity = static_cast<unsigned>(entt::entity{entt::null});
}
EntityReference::EntityReference(Context* context)
: TrackedComponent<TrackedComponentBase, EntityManager>(context)
{
}
EntityReference::~EntityReference()
{
}
void EntityReference::RegisterObject(Context* context)
{
context->RegisterFactory<EntityReference>(Category_Plugin_EntityManager);
URHO3D_ACCESSOR_ATTRIBUTE("Entity", GetEntityAttr, SetEntityAttr, unsigned, nullEntity, AM_DEFAULT | AM_NOEDIT);
// Artificial attribute used to support per-entity manipulation.
URHO3D_ACCESSOR_ATTRIBUTE("Data", GetDataAttr, SetDataAttr, ByteVector, Variant::emptyBuffer, AM_TEMPORARY | AM_NOEDIT);
// Artificial attribute that is used to attach custom inspector UI.
URHO3D_ACCESSOR_ATTRIBUTE("Placeholder", GetPlaceholderAttr, SetPlaceholderAttr, bool, false, AM_EDIT)
.SetScopeHint(AttributeScopeHint::Serializable);
}
void EntityReference::ApplyAttributes()
{
EntityManager* manager = GetRegistry();
if (manager)
manager->Synchronize();
}
bool EntityReference::RenderInspector()
{
EntityManager* manager = GetRegistry();
if (manager && entity_ != entt::null)
return manager->RenderEntityInspector(entity_);
return false;
}
void EntityReference::SetPlaceholderAttr(bool placeholder)
{
EntityManager* manager = GetRegistry();
if (manager)
manager->CommitActions();
}
void EntityReference::SetDataAttr(const ByteVector& data)
{
EntityManager* manager = GetRegistry();
if (manager && entity_ != entt::null)
manager->QueueDecodeEntity(this, data);
}
ByteVector EntityReference::GetDataAttr() const
{
EntityManager* manager = GetRegistry();
if (manager && entity_ != entt::null)
return manager->EncodeEntity(entity_);
return {};
}
void EntityReference::OnMarkedDirty(Node* node)
{
EntityManager* manager = GetRegistry();
if (manager && entity_ != entt::null)
{
auto& registry = manager->Registry();
if (!registry.valid(entity_))
return;
registry.emplace_or_replace<EntityTransformDirty>(entity_);
}
}
} // namespace Urho3D