27 void Tick(
float ts) {}
29 template<
typename T,
typename ...TArgs>
30 T& AddComponent(TArgs&&... Args)
32 T& Component = Scene->Registry.emplace<T>(Handle, std::forward<TArgs>(Args)...);
33 Scene->OnComponentAdded<T>(*
this, Component);
38 template<
typename... T>
41 return Scene->Registry.all_of<T...>(Handle);
44 template<
typename... T>
45 bool HasComponent()
const
47 return Scene->Registry.all_of<T...>(Handle);
50 template<
typename... T>
53 return Scene->Registry.any_of<T...>(Handle);
56 template<
typename... T>
59 return Scene->Registry.any_of<T...>(Handle);
65 LK_CORE_ASSERT(HasComponent<T>(),
"Entity '{}' does not have that component", Handle);
66 return Scene->Registry.get<T>(Handle);
70 const T& GetComponent()
const
72 LK_CORE_ASSERT(HasComponent<T>(),
"Entity '{}' does not have that component", Handle);
73 return Scene->Registry.get<T>(Handle);
77 void RemoveComponent()
79 LK_CORE_ASSERT(HasComponent<T>(),
"Entity does not have that component");
80 Scene->Registry.remove<T>(Handle);
84 void RemoveComponentIfExists()
86 if (Scene->Registry.all_of<T>(Handle))
88 Scene->Registry.remove<T>(Handle);
92 template<
typename T,
typename... ARGS>
93 void AddExistingComponent(T, ARGS&&... args)
95 Scene->Registry.emplace<T>(Handle, std::forward<ARGS>(args)...);
98 FORCEINLINE
const std::string& Name()
const {
return GetComponent<LTagComponent>().Tag; }
99 FORCEINLINE
LTagComponent& Tag() {
return GetComponent<LTagComponent>(); }
100 FORCEINLINE
LTransformComponent& Transform() {
return GetComponent<LTransformComponent>(); }
101 FORCEINLINE
LMeshComponent& GetMesh() {
return GetComponent<LMeshComponent>(); }
103 operator uint32_t()
const {
return static_cast<uint32_t
>(Handle); }
104 operator entt::entity()
const {
return Handle; }
105 operator LUUID()
const {
return GetUUID(); }
107 operator bool()
const;
109 bool operator==(
const LEntity& Other)
const
111 return ((Handle == Other.Handle) && (Scene == Other.Scene));
114 bool operator!=(
const LEntity& Other)
const {
return !(*
this == Other); }
118 FORCEINLINE
LUUID GetUUID()
const
120 return GetComponent<LIDComponent>().ID;
123 FORCEINLINE
void SetParent(
LEntity InParent)
125 LEntity CurrentParent = GetParent();
126 if (CurrentParent == InParent)
134 CurrentParent.RemoveChild(*
this);
138 SetParentUUID(InParent.GetUUID());
142 std::vector<LUUID>& Children = InParent.GetChildren();
143 const LUUID uuid = GetUUID();
145 if (std::find(Children.begin(), Children.end(), uuid) == Children.end())
147 Children.emplace_back(GetUUID());
152 LUUID GetSceneUUID()
const;
154 FORCEINLINE
void SetParentUUID(
LUUID parent)
156 GetComponent<LRelationshipComponent>().ParentHandle = parent;
159 FORCEINLINE
LUUID GetParentUUID()
const
161 return GetComponent<LRelationshipComponent>().ParentHandle;
164 FORCEINLINE std::vector<LUUID>& GetChildren()
166 return GetComponent<LRelationshipComponent>().Children;
169 const std::vector<LUUID>& GetChildren()
const {
return GetComponent<LRelationshipComponent>().Children; }
171 bool RemoveChild(
LEntity Child)
173 const LUUID ChildID = Child.GetUUID();
174 std::vector<LUUID>& Children = GetChildren();
177 auto Iter = std::find(Children.begin(), Children.end(), ChildID);
178 if (Iter != Children.end())
180 Children.erase(Iter);
187 bool IsAncestorOf(
LEntity InEntity);
189 FORCEINLINE
bool IsDescendantOf(
LEntity Entity)
const
191 return Entity.IsAncestorOf(*
this);
195 entt::entity Handle{ entt::null };
199 friend class LEditorLayer;
201 friend class LSceneManagerPanel;