예제 #1
0
    private void AddLockedComponent(BIWEntity entity)
    {
        DCLLockedOnEdit entityLocked = (DCLLockedOnEdit)sceneToEdit.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.LOCKED_ON_EDIT));

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

        sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, entityLocked.id);
    }
예제 #2
0
    public void BuilderInWorldEntityComponents()
    {
        string entityId = "1";

        TestHelpers.CreateSceneEntity(scene, entityId);

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

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

        Assert.IsTrue(biwEntity.entityUniqueId == scene.sceneData.id + scene.entities[entityId].entityId, "Entity id is not created correctly, this can lead to weird behaviour");

        SmartItemComponent.Model model = new SmartItemComponent.Model();
        string jsonModel = JsonUtility.ToJson(model);

        scene.EntityComponentCreateOrUpdateFromUnity(entityId, CLASS_ID_COMPONENT.SMART_ITEM, jsonModel);

        Assert.IsTrue(biwEntity.HasSmartItemComponent());

        DCLName name = (DCLName)scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.NAME));

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

        DCLName dclName = biwEntity.rootEntity.TryGetComponent <DCLName>();

        Assert.IsNotNull(dclName);

        string newName = "TestingName";

        dclName.ForceSetNewName(newName);
        Assert.AreEqual(newName, biwEntity.GetDescriptiveName());


        DCLLockedOnEdit entityLocked = (DCLLockedOnEdit)scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.LOCKED_ON_EDIT));

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

        DCLLockedOnEdit dclLockedOnEdit = biwEntity.rootEntity.TryGetComponent <DCLLockedOnEdit>();

        Assert.IsNotNull(dclLockedOnEdit);

        bool isLocked = true;

        dclLockedOnEdit.SetIsLocked(isLocked);
        Assert.AreEqual(biwEntity.IsLocked, isLocked);
    }
예제 #3
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)
        {
            DCLLockedOnEdit entityLocked = (DCLLockedOnEdit)rootEntity.scene.SharedComponentCreate(Guid.NewGuid().ToString(), Convert.ToInt32(CLASS_ID.LOCKED_ON_EDIT));
            entityLocked.SetIsLocked(isLocked);
            rootEntity.scene.SharedComponentAttach(rootEntity.entityId, entityLocked.id);
        }
    }
예제 #4
0
    public void SetIsLockedValue(bool isLocked)
    {
        bool foundComponent = false;

        foreach (KeyValuePair <Type, ISharedComponent> kvp in rootEntity.sharedComponents)
        {
            if (kvp.Value.GetClassId() == (int)CLASS_ID.LOCKED_ON_EDIT)
            {
                ((DCLLockedOnEdit)kvp.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);
        }
    }
예제 #5
0
        public BaseDisposable SharedComponentCreate(string id, int classId)
        {
            BaseDisposable disposableComponent;

            if (disposableComponents.TryGetValue(id, out disposableComponent))
            {
                return(disposableComponent);
            }

            BaseDisposable newComponent = null;

            switch ((CLASS_ID)classId)
            {
            case CLASS_ID.BOX_SHAPE:
            {
                newComponent = new BoxShape(this);
                break;
            }

            case CLASS_ID.SPHERE_SHAPE:
            {
                newComponent = new SphereShape(this);
                break;
            }

            case CLASS_ID.CONE_SHAPE:
            {
                newComponent = new ConeShape(this);
                break;
            }

            case CLASS_ID.CYLINDER_SHAPE:
            {
                newComponent = new CylinderShape(this);
                break;
            }

            case CLASS_ID.PLANE_SHAPE:
            {
                newComponent = new PlaneShape(this);
                break;
            }

            case CLASS_ID.GLTF_SHAPE:
            {
                newComponent = new GLTFShape(this);
                break;
            }

            case CLASS_ID.NFT_SHAPE:
            {
                newComponent = new NFTShape(this);
                break;
            }

            case CLASS_ID.OBJ_SHAPE:
            {
                newComponent = new OBJShape(this);
                break;
            }

            case CLASS_ID.BASIC_MATERIAL:
            {
                newComponent = new BasicMaterial(this);
                break;
            }

            case CLASS_ID.PBR_MATERIAL:
            {
                newComponent = new PBRMaterial(this);
                break;
            }

            case CLASS_ID.AUDIO_CLIP:
            {
                newComponent = new DCLAudioClip(this);
                break;
            }

            case CLASS_ID.TEXTURE:
            {
                newComponent = new DCLTexture(this);
                break;
            }

            case CLASS_ID.UI_INPUT_TEXT_SHAPE:
            {
                newComponent = new UIInputText(this);
                break;
            }

            case CLASS_ID.UI_FULLSCREEN_SHAPE:
            case CLASS_ID.UI_SCREEN_SPACE_SHAPE:
            {
                if (GetSharedComponent <UIScreenSpace>() == null)
                {
                    newComponent = new UIScreenSpace(this);
                }

                break;
            }

            case CLASS_ID.UI_CONTAINER_RECT:
            {
                newComponent = new UIContainerRect(this);
                break;
            }

            case CLASS_ID.UI_SLIDER_SHAPE:
            {
                newComponent = new UIScrollRect(this);
                break;
            }

            case CLASS_ID.UI_CONTAINER_STACK:
            {
                newComponent = new UIContainerStack(this);
                break;
            }

            case CLASS_ID.UI_IMAGE_SHAPE:
            {
                newComponent = new UIImage(this);
                break;
            }

            case CLASS_ID.UI_TEXT_SHAPE:
            {
                newComponent = new UIText(this);
                break;
            }

            case CLASS_ID.VIDEO_CLIP:
            {
                newComponent = new DCLVideoClip(this);
                break;
            }

            case CLASS_ID.VIDEO_TEXTURE:
            {
                newComponent = new DCLVideoTexture(this);
                break;
            }

            case CLASS_ID.FONT:
            {
                newComponent = new DCLFont(this);
                break;
            }

            case CLASS_ID.NAME:
            {
                newComponent = new DCLName(this);
                break;
            }

            case CLASS_ID.LOCKED_ON_EDIT:
            {
                newComponent = new DCLLockedOnEdit(this);
                break;
            }

            case CLASS_ID.VISIBLE_ON_EDIT:
            {
                newComponent = new DCLVisibleOnEdit(this);
                break;
            }

            default:
                Debug.LogError($"Unknown classId");
                break;
            }

            if (newComponent != null)
            {
                newComponent.id = id;
                disposableComponents.Add(id, newComponent);
                OnAddSharedComponent?.Invoke(id, newComponent);
            }

            return(newComponent);
        }
    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);
    }