| | 1 | | using DCL.Controllers; |
| | 2 | | using DCL.ECSRuntime; |
| | 3 | | using DCL.Models; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.ECSComponents |
| | 7 | | { |
| | 8 | | public class ECSTransformHandler : IECSComponentHandler<ECSTransform> |
| | 9 | | { |
| 8 | 10 | | public ECSTransformHandler() |
| | 11 | | { |
| 8 | 12 | | ECSTransformUtils.orphanEntities = new KeyValueSet<IDCLEntity, ECSTransformUtils.OrphanEntity>(10); |
| 8 | 13 | | } |
| | 14 | |
|
| 0 | 15 | | public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { } |
| | 16 | |
|
| | 17 | | public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity) |
| | 18 | | { |
| 1 | 19 | | if (entity.parentId != (long)SpecialEntityId.SCENE_ROOT_ENTITY) |
| | 20 | | { |
| 0 | 21 | | entity.parentId = (long)SpecialEntityId.SCENE_ROOT_ENTITY; |
| 0 | 22 | | ECSTransformUtils.SetParent(scene, entity, (long)SpecialEntityId.SCENE_ROOT_ENTITY); |
| | 23 | | } |
| 1 | 24 | | ECSTransformUtils.orphanEntities.Remove(entity); |
| 1 | 25 | | } |
| | 26 | |
|
| | 27 | | public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, ECSTransform model) |
| | 28 | | { |
| 10 | 29 | | Transform transform = entity.gameObject.transform; |
| 10 | 30 | | transform.localPosition = model.position; |
| 10 | 31 | | transform.localRotation = model.rotation; |
| 10 | 32 | | transform.localScale = model.scale; |
| | 33 | |
|
| 10 | 34 | | if (entity.parentId != model.parentId) |
| | 35 | | { |
| 6 | 36 | | entity.parentId = model.parentId; |
| 6 | 37 | | ECSTransformUtils.orphanEntities.Remove(entity); |
| | 38 | |
|
| | 39 | | // if `parentId` does not exist yet, we added to `orphanEntities` so system `ECSTransformParentingSystem |
| | 40 | | // can retry parenting later |
| 6 | 41 | | long parentId = model.parentId != entity.entityId? model.parentId : (long)SpecialEntityId.SCENE_ROOT_ENT |
| 6 | 42 | | if (!ECSTransformUtils.SetParent(scene, entity, parentId)) |
| | 43 | | { |
| 3 | 44 | | ECSTransformUtils.orphanEntities[entity] = new ECSTransformUtils.OrphanEntity(scene, entity, parentI |
| | 45 | | } |
| | 46 | | } |
| 10 | 47 | | } |
| | 48 | | } |
| | 49 | | } |