Ejemplo n.º 1
0
    public IDCLEntity CreateEntityFromJSON(string entityJson)
    {
        EntityData data = BuilderInWorldUtils.ConvertJSONToEntityData(entityJson);

        IDCLEntity newEntity = sceneToEdit.CreateEntity(data.entityId);


        if (data.transformComponent != null)
        {
            DCLTransform.model.position = data.transformComponent.position;
            DCLTransform.model.rotation = Quaternion.Euler(data.transformComponent.rotation);
            DCLTransform.model.scale    = data.transformComponent.scale;
            sceneToEdit.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model);
        }

        foreach (ProtocolV2.GenericComponent component in data.components)
        {
            sceneToEdit.EntityComponentCreateOrUpdateWithModel(newEntity.entityId, (CLASS_ID_COMPONENT)component.componentId, component.data);
        }


        foreach (ProtocolV2.GenericComponent component in data.sharedComponents)
        {
            sceneToEdit.SharedComponentAttach(newEntity.entityId, component.classId);
        }


        if (data.nftComponent != null)
        {
            NFTShape nftShape = (NFTShape)sceneToEdit.SharedComponentCreate(data.nftComponent.id, Convert.ToInt32(CLASS_ID.NFT_SHAPE));
            nftShape.model         = new NFTShape.Model();
            nftShape.model.color   = data.nftComponent.color.ToColor();
            nftShape.model.src     = data.nftComponent.src;
            nftShape.model.assetId = data.nftComponent.assetId;

            sceneToEdit.SharedComponentAttach(newEntity.entityId, nftShape.id);
        }

        SetupEntityToEdit(newEntity, true);
        EntityListChanged();

        return(newEntity);
    }