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); }
public static IEnumerator NFTShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene) { var entity = TestHelpers.CreateSceneEntity(scene); TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) }); var componentModel = new NFTShape.Model() { src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" }; NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel); yield return(component.routine); TestHelpers.SharedComponentAttach(component, entity); yield return(null); LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity); yield return(new WaitUntil(() => shapeLoader.alreadyLoaded)); Assert.IsTrue(MeshIsInvalid(entity.meshesInfo)); }
IEnumerator InstantiateNFTShape(Vector3 position, int styleIndex) { var entity = TestHelpers.CreateSceneEntity(scene); TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = position }); yield return(null); var componentModel = new NFTShape.Model() { src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536", color = Color.gray, style = styleIndex }; NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel); yield return(component.routine); TestHelpers.SharedComponentAttach(component, entity); // Override texture with a local test one var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT; nftShape.loaderController.UpdateTexture(Resources.Load <Texture2D>("TestTexture")); nftShape.loaderController.transform.localScale = new Vector3(1.5f, 1.5f, 1f); }
public IEnumerator ShapeUpdate() { string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); var entity = scene.entities[entityId]; Assert.IsTrue(entity.meshRootGameObject == null, "entity mesh object should be null as the NFTShape hasn't been initialized yet"); var componentModel = new NFTShape.Model() { src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536" }; NFTShape component = TestHelpers.SharedComponentCreate <NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, componentModel); yield return(component.routine); TestHelpers.SharedComponentAttach(component, entity); Assert.IsTrue(entity.meshRootGameObject != null, "entity mesh object should already exist as the NFTShape already initialized"); var nftShape = LoadableShape.GetLoaderForEntity(entity) as LoadWrapper_NFT; var backgroundMaterial = nftShape.loaderController.backgroundMaterial; Assert.IsTrue(backgroundMaterial.GetColor("_BaseColor") == new Color(0.6404918f, 0.611472f, 0.8584906f), "The NFT frame background color should be the default one"); // Update color and check if it changed componentModel.color = Color.yellow; yield return(TestHelpers.SharedComponentUpdate(component, componentModel)); Assert.AreEqual(Color.yellow, backgroundMaterial.GetColor("_BaseColor"), "The NFT frame background color should be yellow"); }
public IDCLEntity CreateEntityFromJSON(string entityJson) { EntityData data = BIWUtils.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); } var convertedEntity = SetupEntityToEdit(newEntity, true); if (convertedEntity.rootEntity.TryGetSharedComponent(CLASS_ID.GLTF_SHAPE, out var gltfComponent)) { gltfComponent.CallWhenReady(convertedEntity.ShapeLoadFinish); } if (convertedEntity.rootEntity.TryGetSharedComponent(CLASS_ID.NFT_SHAPE, out var nftComponent)) { nftComponent.CallWhenReady(convertedEntity.ShapeLoadFinish); } creatorController.CreateLoadingObject(convertedEntity); EntityListChanged(); return(newEntity); }
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); }
private void AddShape(CatalogItem catalogItem, DCLBuilderInWorldEntity entity) { if (catalogItem.IsNFT()) { NFTShape nftShape = (NFTShape)sceneToEdit.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; sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, nftShape.id); } else { GLTFShape mesh = (GLTFShape)sceneToEdit.SharedComponentCreate(catalogItem.id, Convert.ToInt32(CLASS_ID.GLTF_SHAPE)); mesh.model = new LoadableShape.Model(); mesh.model.src = catalogItem.model; mesh.model.assetId = catalogItem.id; sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, mesh.id); } }
private void AddShape(CatalogItem catalogItem, BIWEntity entity) { if (catalogItem.IsNFT()) { NFTShape nftShape = (NFTShape)sceneToEdit.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; sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, nftShape.id); nftShape.CallWhenReady(entity.ShapeLoadFinish); } else { GLTFShape gltfComponent = (GLTFShape)sceneToEdit.SharedComponentCreate(catalogItem.id, Convert.ToInt32(CLASS_ID.GLTF_SHAPE)); gltfComponent.model = new LoadableShape.Model(); gltfComponent.model.src = catalogItem.model; gltfComponent.model.assetId = catalogItem.id; sceneToEdit.SharedComponentAttach(entity.rootEntity.entityId, gltfComponent.id); gltfComponent.CallWhenReady(entity.ShapeLoadFinish); } }
public BaseDisposable SharedComponentCreate(string id, string name, int classId) { SceneController.i.OnMessageDecodeStart?.Invoke("ComponentCreated"); sharedComponentCreatedMessage.id = id; sharedComponentCreatedMessage.name = name; sharedComponentCreatedMessage.classId = classId; SceneController.i.OnMessageDecodeEnds?.Invoke("ComponentCreated"); BaseDisposable disposableComponent; if (disposableComponents.TryGetValue(sharedComponentCreatedMessage.id, out disposableComponent)) { return(disposableComponent); } BaseDisposable newComponent = null; switch ((CLASS_ID)sharedComponentCreatedMessage.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 (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; } default: Debug.LogError($"Unknown classId"); break; } if (newComponent != null) { newComponent.id = sharedComponentCreatedMessage.id; disposableComponents.Add(sharedComponentCreatedMessage.id, newComponent); if (state != State.READY) { disposableNotReady.Add(id); } } return(newComponent); }
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); }