Exemplo n.º 1
0
    public static string ConvertEntityToJSON(DecentralandEntity entity)
    {
        EntityData builderInWorldEntityData = new EntityData();

        builderInWorldEntityData.entityId = entity.entityId;


        foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> keyValuePair in entity.components)
        {
            if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
            {
                EntityData.TransformComponent entityComponentModel = new EntityData.TransformComponent();

                entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, entity.scene);
                entityComponentModel.rotation = entity.gameObject.transform.localRotation.eulerAngles;
                entityComponentModel.scale    = entity.gameObject.transform.localScale;

                builderInWorldEntityData.transformComponent = entityComponentModel;
            }
            else
            {
                ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
                entityComponentModel.componentId = (int)keyValuePair.Key;
                entityComponentModel.data        = keyValuePair.Value.GetModel();

                builderInWorldEntityData.components.Add(entityComponentModel);
            }
        }

        foreach (KeyValuePair <Type, BaseDisposable> keyValuePair in entity.GetSharedComponents())
        {
            if (keyValuePair.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
            {
                EntityData.NFTComponent nFTComponent = new EntityData.NFTComponent();
                NFTShape.Model          model        = (NFTShape.Model)keyValuePair.Value.GetModel();

                nFTComponent.id      = keyValuePair.Value.id;
                nFTComponent.color   = new ColorRepresentation(model.color);
                nFTComponent.assetId = model.assetId;
                nFTComponent.src     = model.src;
                nFTComponent.style   = model.style;

                builderInWorldEntityData.nftComponent = nFTComponent;
            }
            else
            {
                ProtocolV2.GenericComponent entityComponentModel = new ProtocolV2.GenericComponent();
                entityComponentModel.componentId = keyValuePair.Value.GetClassId();
                entityComponentModel.data        = keyValuePair.Value.GetModel();
                entityComponentModel.classId     = keyValuePair.Value.id;

                builderInWorldEntityData.sharedComponents.Add(entityComponentModel);
            }
        }


        return(JsonConvert.SerializeObject(builderInWorldEntityData));
    }
Exemplo n.º 2
0
    public void AddEntityOnKernel(DecentralandEntity entity, ParcelScene scene)
    {
        List <ComponentPayload> list = new List <ComponentPayload>();

        foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> keyValuePair in entity.components)
        {
            ComponentPayload componentPayLoad = new ComponentPayload();
            componentPayLoad.componentId = Convert.ToInt32(keyValuePair.Key);

            if (keyValuePair.Key == CLASS_ID_COMPONENT.TRANSFORM)
            {
                TransformComponent entityComponentModel = new TransformComponent();

                entityComponentModel.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position, scene);
                entityComponentModel.rotation = new QuaternionRepresentation(entity.gameObject.transform.rotation);
                entityComponentModel.scale    = entity.gameObject.transform.localScale;

                componentPayLoad.data = entityComponentModel;
            }
            else
            {
                componentPayLoad.data = keyValuePair.Value.GetModel();
            }

            list.Add(componentPayLoad);
        }

        foreach (KeyValuePair <Type, BaseDisposable> keyValuePairBaseDisposable in entity.GetSharedComponents())
        {
            ComponentPayload componentPayLoad = new ComponentPayload();

            componentPayLoad.componentId = keyValuePairBaseDisposable.Value.GetClassId();

            if (keyValuePairBaseDisposable.Value.GetClassId() == (int)CLASS_ID.NFT_SHAPE)
            {
                NFTComponent   nftComponent = new NFTComponent();
                NFTShape.Model model        = (NFTShape.Model)keyValuePairBaseDisposable.Value.GetModel();

                nftComponent.color   = new ColorRepresentation(model.color);
                nftComponent.assetId = model.assetId;
                nftComponent.src     = model.src;
                nftComponent.style   = model.style;

                componentPayLoad.data = nftComponent;
            }
            else
            {
                componentPayLoad.data = keyValuePairBaseDisposable.Value.GetModel();
            }


            list.Add(componentPayLoad);
        }

        SendNewEntityToKernel(scene.sceneData.id, entity.entityId, list.ToArray());
    }
Exemplo n.º 3
0
        public DecentralandEntity DuplicateEntity(DecentralandEntity entity)
        {
            if (!entities.ContainsKey(entity.entityId))
            {
                return(null);
            }

            DecentralandEntity newEntity = CreateEntity(System.Guid.NewGuid().ToString());

            if (entity.children.Count > 0)
            {
                using (var iterator = entity.children.GetEnumerator())
                {
                    while (iterator.MoveNext())
                    {
                        DecentralandEntity childDuplicate = DuplicateEntity(iterator.Current.Value);
                        childDuplicate.SetParent(newEntity);
                    }
                }
            }

            if (entity.parent != null)
            {
                SetEntityParent(newEntity.entityId, entity.parent.entityId);
            }

            DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position);
            DCLTransform.model.rotation = entity.gameObject.transform.rotation;
            DCLTransform.model.scale    = entity.gameObject.transform.lossyScale;

            foreach (KeyValuePair <CLASS_ID_COMPONENT, BaseComponent> component in entity.components)
            {
                EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, component.Key, DCLTransform.model);
            }

            foreach (KeyValuePair <System.Type, BaseDisposable> component in entity.GetSharedComponents())
            {
                BaseDisposable baseDisposable = SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId());
                string         jsonModel      = Newtonsoft.Json.JsonConvert.SerializeObject(component.Value.GetModel());
                baseDisposable.UpdateFromJSON(jsonModel);
                SharedComponentAttach(newEntity.entityId, baseDisposable.id);
            }

            //NOTE: (Adrian) Evaluate if all created components should be handle as equals instead of different
            foreach (KeyValuePair <string, UUIDComponent> component in entity.uuidComponents)
            {
                EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.UUID_CALLBACK, component.Value.model);
            }

            return(newEntity);
        }
Exemplo n.º 4
0
        public static DecentralandEntity DuplicateEntity(ParcelScene scene, DecentralandEntity entity)
        {
            if (!scene.entities.ContainsKey(entity.entityId))
            {
                return(null);
            }

            DecentralandEntity newEntity = scene.CreateEntity(System.Guid.NewGuid().ToString());

            if (entity.children.Count > 0)
            {
                using (var iterator = entity.children.GetEnumerator())
                {
                    while (iterator.MoveNext())
                    {
                        DecentralandEntity childDuplicate = DuplicateEntity(scene, iterator.Current.Value);
                        childDuplicate.SetParent(newEntity);
                    }
                }
            }

            if (entity.parent != null)
            {
                scene.SetEntityParent(newEntity.entityId, entity.parent.entityId);
            }

            DCLTransform.model.position = WorldStateUtils.ConvertUnityToScenePosition(entity.gameObject.transform.position);
            DCLTransform.model.rotation = entity.gameObject.transform.rotation;
            DCLTransform.model.scale    = entity.gameObject.transform.lossyScale;

            foreach (KeyValuePair <CLASS_ID_COMPONENT, IEntityComponent> component in entity.components)
            {
                scene.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, component.Key, component.Value.GetModel());
            }

            foreach (KeyValuePair <System.Type, ISharedComponent> component in entity.GetSharedComponents())
            {
                ISharedComponent sharedComponent = scene.SharedComponentCreate(System.Guid.NewGuid().ToString(), component.Value.GetClassId());
                sharedComponent.UpdateFromModel(component.Value.GetModel());
                scene.SharedComponentAttach(newEntity.entityId, sharedComponent.id);
            }

            return(newEntity);
        }