12 Managed foundComponent;
17 foundComponent = entity.FindComponent(componentType);
19 return foundComponent;
25 SlotManagerComponent slotManager = SlotManagerComponent.Cast(entity.FindComponent(SlotManagerComponent));
28 array<EntitySlotInfo> slotInfos = {};
29 slotManager.GetSlotInfos(slotInfos);
34 slotEntity = slotInfo.GetAttachedEntity();
38 foundComponent = slotEntity.FindComponent(componentType);
40 return foundComponent;
48 IEntity child = entity.GetChildren();
52 foundComponent = child.FindComponent(componentType);
54 return foundComponent;
56 child = child.GetSibling();
65 parent = entity.GetParent();
69 foundComponent = parent.FindComponent(componentType);
71 return foundComponent;
79 parent = entity.GetParent();
85 return foundComponent;
94 rootParent = entity.GetRootParent();
98 foundComponent = rootParent.FindComponent(componentType);
100 return foundComponent;
108 rootParent = entity.GetRootParent();
114 return foundComponent;
122 parent = entity.GetParent();
127 IEntity child = parent.GetChildren();
134 child = child.GetSibling();
138 foundComponent = child.FindComponent(componentType);
140 return foundComponent;
142 child = child.GetSibling();
157 static int GetChildrenCount(IEntity parent,
bool recursive =
false)
163 IEntity child = parent.GetChildren();
168 num += GetChildrenCount(child);
169 child = child.GetSibling();
179 static void DeleteEntityAndChildren(IEntity entity)
182 RplComponent.DeleteRplEntity(entity,
false);
189 static vector GetEntitySize(notnull IEntity entity)
191 vector entMins, entMaxs;
192 entity.GetBounds(entMins, entMaxs);
194 return entMaxs - entMins;
201 static vector GetEntityCenterWorld(notnull IEntity entity)
203 vector entMins, entMaxs;
204 entity.GetBounds(entMins, entMaxs);
205 return entity.CoordToParent((entMaxs + entMins) * 0.5);
211 static float GetEntityRadius(notnull IEntity entity)
213 return GetEntitySize(entity).Length() * 0.5;
220 static void GetHierarchyEntityList(notnull IEntity entity, notnull inout array<IEntity> output)
222 IEntity child = entity.GetChildren();
225 GetHierarchyEntityList(child, output);
226 output.Insert(child);
227 child = child.GetSibling();
239 static void SnapToGround(notnull IEntity entity, array<IEntity> excludeArray =
null,
float maxLength = 10, vector startOffset =
"0 0 0",
bool onlyStatic =
false)
241 vector origin = entity.GetOrigin();
244 TraceParam param =
new TraceParam();
245 param.Start = origin + startOffset;
246 param.End = origin - vector.Up * maxLength;
247 param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
251 excludeArray.Insert(entity);
252 param.ExcludeArray = excludeArray;
256 param.Exclude = entity;
259 param.LayerMask = EPhysicsLayerPresets.Projectile;
260 BaseWorld world = entity.GetWorld();
264 traceDistance = world.TraceMove(param, OnlyStaticCallback);
266 traceDistance = world.TraceMove(param,
null);
268 if (
float.AlmostEqual(traceDistance, 1.0))
271 entity.SetOrigin(traceDistance * (param.End - param.Start) + param.Start);
277 static void OrientUpToVector(vector newUp, inout vector mat[4])
279 vector origin = mat[3];
280 vector perpend = newUp.Perpend();
281 Math3D.DirectionAndUpMatrix(perpend, newUp, mat);
284 Math3D.AnglesToMatrix(Vector(-perpend.VectorToAngles()[0], 0, 0), basis);
285 Math3D.MatrixMultiply3(mat, basis, mat);
292 protected static bool OnlyStaticCallback(notnull IEntity entity)
294 Physics physics = entity.GetPhysics();
295 if (physics && physics.IsDynamic())
305 static IEntity GetMainParent(IEntity entity,
bool self =
false)
310 IEntity parent = entity.GetRootParent();
311 if (parent != entity)
324 static IEntity GetPlayer()
334 static bool IsPlayer(IEntity entity)
336 return entity && entity ==
EntityUtils.GetPlayer();
344 static bool IsAPlayer(IEntity entity)
353 static void SetHierarchyTransform(notnull IEntity entity, vector newTransform[4])
355 vector oldTransform[4];
356 entity.GetTransform(oldTransform);
357 entity.SetTransform(newTransform);
359 IEntity child = entity.GetChildren();
362 SetHierarchyChildTransform(child, oldTransform, newTransform,
true);
363 child = child.GetSibling();
374 protected static void SetHierarchyChildTransform(notnull IEntity entity, vector oldTransform[4], vector newTransform[4],
bool recursive =
true)
376 Physics entPhys = entity.GetPhysics();
379 if (entPhys.IsDynamic())
382 entity.GetTransform(mat);
385 Math3D.MatrixInvMultiply4(oldTransform, mat, diffMat);
386 Math3D.MatrixMultiply4(newTransform, diffMat, mat);
388 entity.SetTransform(mat);
392 IEntity child = entity.GetChildren();
395 SetHierarchyChildTransform(child, oldTransform, newTransform, recursive);
396 child = child.GetSibling();
401 class SCR_EntityHelperT<Class T>
409 IEntity child = parent.GetChildren();
413 return T.Cast(child);
415 child = child.GetSibling();