| | 1 | | using DCL.ECS7.InternalComponents; |
| | 2 | | using DCL.Models; |
| | 3 | | using System; |
| | 4 | |
|
| | 5 | | public static class ECSTransformParentingSystem |
| | 6 | | { |
| | 7 | | public static Action CreateSystem(IInternalECSComponent<InternalSceneBoundsCheck> internalSceneBoundsCheckComponent) |
| | 8 | | { |
| 11 | 9 | | return () => Update(internalSceneBoundsCheckComponent); |
| | 10 | | } |
| | 11 | |
|
| | 12 | | private static void Update(IInternalECSComponent<InternalSceneBoundsCheck> sbcInternalComponent) |
| | 13 | | { |
| 6 | 14 | | if (ECSTransformUtils.orphanEntities == null || ECSTransformUtils.orphanEntities.Count == 0) |
| | 15 | | { |
| 0 | 16 | | return; |
| | 17 | | } |
| | 18 | |
|
| 6 | 19 | | int count = ECSTransformUtils.orphanEntities.Count; |
| | 20 | |
|
| 24 | 21 | | for (int i = count - 1; i >= 0; i--) |
| | 22 | | { |
| 6 | 23 | | var data = ECSTransformUtils.orphanEntities.Pairs[i].value; |
| | 24 | |
|
| 6 | 25 | | if (ECSTransformUtils.TrySetParent(data.scene, data.entity, data.parentId, out IDCLEntity parent)) |
| | 26 | | { |
| 5 | 27 | | if (data.entity.parentId != SpecialEntityId.SCENE_ROOT_ENTITY) |
| 3 | 28 | | parent.childrenId.Add(data.entity.entityId); |
| | 29 | |
|
| 5 | 30 | | ECSTransformUtils.orphanEntities.RemoveAt(i); |
| | 31 | |
|
| 5 | 32 | | sbcInternalComponent.SetPosition(data.scene, data.entity, data.entity.gameObject.transform.position); |
| | 33 | | } |
| | 34 | | } |
| 6 | 35 | | } |
| | 36 | | } |