示例#1
0
    public void NftComponent()
    {
        CatalogItem catalogItem = DataStore.i.builderInWorld.catalogItemDict.GetValues()[0];



        DCLBuilderInWorldEntity biwEntity = Utils.GetOrCreateComponent <DCLBuilderInWorldEntity>(scene.entities[ENTITY_ID].gameObject);

        biwEntity.Init(scene.entities[ENTITY_ID], null);

        NFTShape nftShape = (NFTShape)scene.SharedComponentCreate(catalogItem.id, Convert.ToInt32(CLASS_ID.NFT_SHAPE));

        nftShape.model         = new NFTShape.Model();
        nftShape.model.color   = new Color(0.6404918f, 0.611472f, 0.8584906f);
        nftShape.model.src     = catalogItem.model;
        nftShape.model.assetId = catalogItem.id;

        scene.SharedComponentAttach(biwEntity.rootEntity.entityId, nftShape.id);

        Assert.IsTrue(biwEntity.IsEntityNFT());

        CatalogItem associatedCatalogItem = biwEntity.GetCatalogItemAssociated();

        Assert.IsTrue(associatedCatalogItem.IsNFT());
        Assert.AreEqual(associatedCatalogItem, catalogItem);
    }
示例#2
0
        public static void SharedComponentAttach(BaseDisposable component, DecentralandEntity entity)
        {
            ParcelScene scene = entity.scene as ParcelScene;

            scene.SharedComponentAttach(
                entity.entityId,
                component.id
                );
        }
    public DecentralandEntity CreateEntityFromJSON(string entityJson)
    {
        EntityData data = BuilderInWorldUtils.ConvertJSONToEntityData(entityJson);

        DecentralandEntity 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.EntityComponentCreateOrUpdateFromUnity(newEntity.entityId, CLASS_ID_COMPONENT.TRANSFORM, DCLTransform.model);
        }

        foreach (ProtocolV2.GenericComponent component in data.components)
        {
            sceneToEdit.EntityComponentCreateOrUpdateFromUnity(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);
    }
示例#4
0
    public void SetDescriptiveName(string newName)
    {
        if (rootEntity.TryGetSharedComponent(CLASS_ID.NAME, out BaseDisposable nameComponent))
        {
            ((DCLName)nameComponent).ForceSetNewName(newName);
        }
        else
        {
            ParcelScene scene = rootEntity.scene as ParcelScene;
            DCLName     name  = (DCLName)scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.NAME));
            name.ForceSetNewName(newName);
            scene.SharedComponentAttach(rootEntity.entityId, name.id);
        }

        onStatusUpdate?.Invoke(this);
    }
示例#5
0
        public static void InstantiateEntityWithMaterial(ParcelScene scene, string entityId, Vector3 position,
                                                         PBRMaterial.Model pbrMaterial, string materialComponentID = "a-material")
        {
            InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, position);

            scene.SharedComponentCreate(
                materialComponentID,
                (int)CLASS_ID.PBR_MATERIAL
                );

            scene.SharedComponentUpdate(
                materialComponentID,
                JsonUtility.ToJson(pbrMaterial));

            scene.SharedComponentAttach(
                entityId,
                materialComponentID
                );
        }
示例#6
0
        public static string CreateAndSetShape(ParcelScene scene, string entityId, CLASS_ID classId, string model)
        {
            string componentId = GetComponentUniqueId(scene, "shape", (int)classId, entityId);

            scene.SharedComponentCreate(
                componentId,
                (int)classId
                );

            scene.SharedComponentUpdate(
                componentId,
                model);

            scene.SharedComponentAttach(
                entityId,
                componentId
                );

            return(componentId);
        }
示例#7
0
    public void SetIsLockedValue(bool isLocked)
    {
        bool foundComponent = false;

        foreach (KeyValuePair <Type, BaseDisposable> keyValuePairBaseDisposable in rootEntity.GetSharedComponents())
        {
            if (keyValuePairBaseDisposable.Value.GetClassId() == (int)CLASS_ID.LOCKED_ON_EDIT)
            {
                ((DCLLockedOnEdit)keyValuePairBaseDisposable.Value).SetIsLocked(isLocked);
                foundComponent = true;
            }
        }

        if (!foundComponent)
        {
            ParcelScene     scene        = rootEntity.scene as ParcelScene;
            DCLLockedOnEdit entityLocked = (DCLLockedOnEdit)scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.LOCKED_ON_EDIT));
            entityLocked.SetIsLocked(isLocked);
            scene.SharedComponentAttach(rootEntity.entityId, entityLocked.id);
        }
    }
示例#8
0
        private void ProcessMessage(ParcelScene scene, string method, object msgPayload,
                                    out CustomYieldInstruction yieldInstruction)
        {
            yieldInstruction = null;
            IDelayedComponent delayedComponent = null;

            try
            {
                switch (method)
                {
                case MessagingTypes.ENTITY_CREATE:
                {
                    if (msgPayload is Protocol.CreateEntity payload)
                    {
                        scene.CreateEntity(payload.entityId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_REPARENT:
                {
                    if (msgPayload is Protocol.SetEntityParent payload)
                    {
                        scene.SetEntityParent(payload.entityId, payload.parentId);
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_CREATE_OR_UPDATE:
                {
                    if (msgPayload is Protocol.EntityComponentCreateOrUpdate payload)
                    {
                        delayedComponent = scene.EntityComponentCreateOrUpdate(payload.entityId,
                                                                               (CLASS_ID_COMPONENT)payload.classId, payload.json) as IDelayedComponent;
                    }

                    break;
                }

                case MessagingTypes.ENTITY_COMPONENT_DESTROY:
                {
                    if (msgPayload is Protocol.EntityComponentDestroy payload)
                    {
                        scene.EntityComponentRemove(payload.entityId, payload.name);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_ATTACH:
                {
                    if (msgPayload is Protocol.SharedComponentAttach payload)
                    {
                        scene.SharedComponentAttach(payload.entityId, payload.id);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_CREATE:
                {
                    if (msgPayload is Protocol.SharedComponentCreate payload)
                    {
                        scene.SharedComponentCreate(payload.id, payload.classId);
                    }

                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_DISPOSE:
                {
                    if (msgPayload is Protocol.SharedComponentDispose payload)
                    {
                        scene.SharedComponentDispose(payload.id);
                    }
                    break;
                }

                case MessagingTypes.SHARED_COMPONENT_UPDATE:
                {
                    if (msgPayload is Protocol.SharedComponentUpdate payload)
                    {
                        delayedComponent = scene.SharedComponentUpdate(payload.componentId, payload.json) as IDelayedComponent;
                    }

                    break;
                }

                case MessagingTypes.ENTITY_DESTROY:
                {
                    if (msgPayload is Protocol.RemoveEntity payload)
                    {
                        scene.RemoveEntity(payload.entityId);
                    }
                    break;
                }

                case MessagingTypes.INIT_DONE:
                {
                    scene.sceneLifecycleHandler.SetInitMessagesDone();
                    break;
                }

                case MessagingTypes.QUERY:
                {
                    if (msgPayload is QueryMessage queryMessage)
                    {
                        ParseQuery(queryMessage.payload, scene.sceneData.id);
                    }
                    break;
                }

                case MessagingTypes.OPEN_EXTERNAL_URL:
                {
                    if (msgPayload is Protocol.OpenExternalUrl payload)
                    {
                        OnOpenExternalUrlRequest?.Invoke(scene, payload.url);
                    }
                    break;
                }

                case MessagingTypes.OPEN_NFT_DIALOG:
                {
                    if (msgPayload is Protocol.OpenNftDialog payload)
                    {
                        DataStore.i.onOpenNFTPrompt.Set(new NFTPromptModel(payload.contactAddress, payload.tokenId,
                                                                           payload.comment), true);
                    }
                    break;
                }

                default:
                    Debug.LogError($"Unknown method {method}");
                    break;
                }
            }
            catch (Exception e)
            {
                throw new Exception(
                          $"Scene message error. scene: {scene.sceneData.id} method: {method} payload: {JsonUtility.ToJson(msgPayload)} {e}");
            }

            if (delayedComponent != null)
            {
                if (delayedComponent.isRoutineRunning)
                {
                    yieldInstruction = delayedComponent.yieldInstruction;
                }
            }
        }
    DCLBuilderInWorldEntity CreateSceneObject(SceneObject sceneObject, bool autoSelect = true, bool isFloor = false)
    {
        if (sceneObject.asset_pack_id == BuilderInWorldSettings.ASSETS_COLLECTIBLES && BuilderInWorldNFTController.i.IsNFTInUse(sceneObject.id))
        {
            return(null);
        }

        IsInsideTheLimits(sceneObject);

        //Note (Adrian): This is a workaround until the mapping is handle by kernel

        LoadParcelScenesMessage.UnityParcelScene data = sceneToEdit.sceneData;
        data.baseUrl = BuilderInWorldSettings.BASE_URL_CATALOG;

        foreach (KeyValuePair <string, string> content in sceneObject.contents)
        {
            ContentServerUtils.MappingPair mappingPair = new ContentServerUtils.MappingPair();
            mappingPair.file = content.Key;
            mappingPair.hash = content.Value;
            bool found = false;
            foreach (ContentServerUtils.MappingPair mappingPairToCheck in data.contents)
            {
                if (mappingPairToCheck.file == mappingPair.file)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                data.contents.Add(mappingPair);
            }
        }

        Environment.i.world.sceneController.UpdateParcelScenesExecute(data);


        DCLName         name         = (DCLName)sceneToEdit.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.NAME));
        DCLLockedOnEdit entityLocked = (DCLLockedOnEdit)sceneToEdit.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.LOCKED_ON_EDIT));

        DCLBuilderInWorldEntity entity = builderInWorldEntityHandler.CreateEmptyEntity(sceneToEdit, currentActiveMode.GetCreatedEntityPoint(), editionGO.transform.position);

        entity.isFloor = isFloor;

        if (entity.isFloor)
        {
            entityLocked.SetIsLocked(true);
        }
        else
        {
            entityLocked.SetIsLocked(false);
        }

        if (sceneObject.asset_pack_id == BuilderInWorldSettings.ASSETS_COLLECTIBLES)
        {
            NFTShape nftShape = (NFTShape)sceneToEdit.SharedComponentCreate(sceneObject.id, Convert.ToInt32(CLASS_ID.NFT_SHAPE));
            nftShape.model         = new NFTShape.Model();
            nftShape.model.color   = new Color(0.6404918f, 0.611472f, 0.8584906f);
            nftShape.model.src     = sceneObject.model;
            nftShape.model.assetId = sceneObject.id;

            sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, nftShape.id);
        }
        else
        {
            GLTFShape mesh = (GLTFShape)sceneToEdit.SharedComponentCreate(sceneObject.id, Convert.ToInt32(CLASS_ID.GLTF_SHAPE));
            mesh.model         = new LoadableShape.Model();
            mesh.model.src     = sceneObject.model;
            mesh.model.assetId = sceneObject.id;
            sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, mesh.id);
        }

        sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, name.id);
        sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, entityLocked.id);

        builderInWorldEntityHandler.SetEntityName(entity, sceneObject.name);

        if (sceneObject.IsSmartItem())
        {
            SmartItemComponent.Model model = new SmartItemComponent.Model();
            model.actions    = sceneObject.actions;
            model.parameters = sceneObject.parameters;

            string jsonModel = JsonUtility.ToJson(model);

            sceneToEdit.EntityComponentCreateOrUpdateFromUnity(entity.rootEntity.entityId, CLASS_ID_COMPONENT.SMART_ITEM, jsonModel);

            //Note (Adrian): This shouldn't work this way, we can't wait a frame to set the data of the component so we force it to update

            entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out BaseComponent baseComponent);
            ((SmartItemComponent)baseComponent).ForceUpdate(jsonModel);
        }

        if (sceneObject.asset_pack_id == BuilderInWorldSettings.VOXEL_ASSETS_PACK_ID)
        {
            entity.isVoxel = true;
        }

        if (autoSelect)
        {
            builderInWorldEntityHandler.DeselectEntities();
            builderInWorldEntityHandler.Select(entity.rootEntity);
        }

        entity.gameObject.transform.eulerAngles = Vector3.zero;

        currentActiveMode.CreatedEntity(entity);
        if (!isAdvancedModeActive)
        {
            Utils.LockCursor();
        }
        lastSceneObjectCreated = sceneObject;

        builderInWorldEntityHandler.NotifyEntityIsCreated(entity.rootEntity);
        InputDone();
        OnSceneObjectPlaced?.Invoke();

        return(entity);
    }