| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Models; |
| | 4 | |
|
| | 5 | | namespace DCL.Controllers |
| | 6 | | { |
| | 7 | | public static class SceneUtils |
| | 8 | | { |
| | 9 | | public static IDCLEntity DuplicateEntity(ParcelScene scene, IDCLEntity entity) |
| | 10 | | { |
| 3 | 11 | | if (!scene.entities.ContainsKey(entity.entityId)) |
| 0 | 12 | | return null; |
| | 13 | |
|
| 3 | 14 | | IDCLEntity newEntity = scene.CreateEntity(System.Guid.NewGuid().ToString()); |
| | 15 | |
|
| 3 | 16 | | if (entity.children.Count > 0) |
| | 17 | | { |
| 0 | 18 | | using (var iterator = entity.children.GetEnumerator()) |
| | 19 | | { |
| 0 | 20 | | while (iterator.MoveNext()) |
| | 21 | | { |
| 0 | 22 | | IDCLEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value); |
| 0 | 23 | | childDuplicate.SetParent(newEntity); |
| | 24 | | } |
| 0 | 25 | | } |
| | 26 | | } |
| | 27 | |
|
| 3 | 28 | | if (entity.parent != null) |
| 0 | 29 | | scene.SetEntityParent(newEntity.entityId, entity.parent.entityId); |
| | 30 | |
|
| 3 | 31 | | DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.positi |
| 3 | 32 | | DCLTransform.model.rotation = entity.gameObject.transform.rotation; |
| 3 | 33 | | DCLTransform.model.scale = entity.gameObject.transform.lossyScale; |
| | 34 | |
|
| 8 | 35 | | foreach (KeyValuePair<CLASS_ID_COMPONENT, IEntityComponent> component in entity.components) |
| | 36 | | { |
| 1 | 37 | | scene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, component.Key, component.Value.GetModel |
| | 38 | | } |
| | 39 | |
|
| 6 | 40 | | foreach (KeyValuePair<System.Type, ISharedComponent> component in entity.sharedComponents) |
| | 41 | | { |
| 0 | 42 | | ISharedComponent sharedComponent = scene.SharedComponentCreate(System.Guid.NewGuid().ToString(), compone |
| 0 | 43 | | sharedComponent.UpdateFromModel(component.Value.GetModel()); |
| 0 | 44 | | scene.SharedComponentAttach(newEntity.entityId, sharedComponent.id); |
| | 45 | | } |
| | 46 | |
|
| 3 | 47 | | return newEntity; |
| | 48 | | } |
| | 49 | | } |
| | 50 | | } |