public void SmartItemComponent() { SmartItemComponent.Model model = new SmartItemComponent.Model(); string testFloatKey = "TestFloat"; float testFloat = 20f; string intKey = "Speed"; int testInt = 10; string stringKey = "TextExample"; string testString = "unit test example"; string onClickKey = "OnClick"; Dictionary <object, object> onClickDict = new Dictionary <object, object>(); onClickDict.Add(testFloatKey, testFloat); model.values = new Dictionary <object, object>(); model.values.Add(intKey, testInt); model.values.Add(testFloatKey, testFloat); model.values.Add(stringKey, testString); model.values.Add(onClickKey, onClickDict); string jsonModel = JsonUtility.ToJson(model); string entityId = "1"; TestHelpers.CreateSceneEntity(scene, entityId); SmartItemComponent smartItemComponent = null; //Note (Adrian): This shouldn't work this way, we should have a function to create the component from Model directly scene.EntityComponentCreateOrUpdateFromUnity(entityId, CLASS_ID_COMPONENT.SMART_ITEM, jsonModel); if (scene.entities[entityId].TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out BaseComponent baseComponent)) { //Note (Adrian): We can't wait to set the component 1 frame in production, so we set it like production smartItemComponent = ((SmartItemComponent)baseComponent); smartItemComponent.SetModel(model); } else { Assert.Fail("Smart Compoenent not found"); } Assert.AreEqual(testInt, smartItemComponent.model.values[intKey]); Assert.AreEqual(testFloat, smartItemComponent.model.values[testFloatKey]); Assert.AreEqual(testString, smartItemComponent.model.values[stringKey]); Dictionary <object, object> onClickDictFromComponent = (Dictionary <object, object>)smartItemComponent.model.values[onClickKey]; Assert.AreEqual(testFloat, onClickDictFromComponent[testFloatKey]); }
private void AddSmartItemComponent(DCLBuilderInWorldEntity entity) { SmartItemComponent.Model model = new SmartItemComponent.Model(); model.values = new Dictionary <object, object>(); sceneToEdit.EntityComponentCreateOrUpdateWithModel(entity.rootEntity.entityId, CLASS_ID_COMPONENT.SMART_ITEM, model); //Note (Adrian): We can't wait to set the component 1 frame, so we set it if (entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent component)) { ((SmartItemComponent)component).UpdateFromModel(model); } }
public static BIWEntity CreateSmartItemEntity(BIWEntityHandler entityHandler, ParcelScene scene, SmartItemComponent.Model model = null) { if (model == null) { model = new SmartItemComponent.Model(); } BIWEntity entity = entityHandler.CreateEmptyEntity(scene, Vector3.zero, Vector3.zero); scene.EntityComponentCreateOrUpdateWithModel(entity.rootEntity.entityId, CLASS_ID_COMPONENT.SMART_ITEM, model); return(entity); }
public void SmartItemComponent() { SmartItemComponent.Model model = new SmartItemComponent.Model(); string testFloatKey = "TestFloat"; float testFloat = 20f; string intKey = "Speed"; int testInt = 10; string stringKey = "TextExample"; string testString = "unit test example"; string onClickKey = "OnClick"; Dictionary <object, object> onClickDict = new Dictionary <object, object>(); onClickDict.Add(testFloatKey, testFloat); model.values = new Dictionary <object, object>(); model.values.Add(intKey, testInt); model.values.Add(testFloatKey, testFloat); model.values.Add(stringKey, testString); model.values.Add(onClickKey, onClickDict); SmartItemComponent smartItemComponent = null; scene.EntityComponentCreateOrUpdateWithModel(ENTITY_ID, CLASS_ID_COMPONENT.SMART_ITEM, model); if (scene.entities[ENTITY_ID].TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent baseComponent)) { //Note (Adrian): We can't wait to set the component 1 frame in production, so we set it like production smartItemComponent = ((SmartItemComponent)baseComponent); smartItemComponent.UpdateFromModel(model); } else { Assert.Fail("Smart Component not found"); } Assert.AreEqual(testInt, smartItemComponent.GetValues()[intKey]); Assert.AreEqual(testFloat, smartItemComponent.GetValues()[testFloatKey]); Assert.AreEqual(testString, smartItemComponent.GetValues()[stringKey]); Dictionary <object, object> onClickDictFromComponent = (Dictionary <object, object>)smartItemComponent.GetValues()[onClickKey]; Assert.AreEqual(testFloat, onClickDictFromComponent[testFloatKey]); }
public void EntityDeselected() { if (currentEntity == null) { return; } if (currentEntity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out BaseComponent component)) { SmartItemComponent smartItemComponent = (SmartItemComponent)component; SmartItemComponent.Model modelo = smartItemComponent.model; modelo.ToString(); OnSmartItemComponentUpdate?.Invoke(currentEntity); } }
private void AddSmartItemComponent(DCLBuilderInWorldEntity entity) { SmartItemComponent.Model model = new SmartItemComponent.Model(); model.values = new Dictionary <object, object>(); string jsonModel = JsonUtility.ToJson(model); //Note (Adrian): This shouldn't work this way, we should have a function to create the component from Model directly sceneToEdit.EntityComponentCreateOrUpdateFromUnity(entity.rootEntity.entityId, CLASS_ID_COMPONENT.SMART_ITEM, jsonModel); //Note (Adrian): We can't wait to set the component 1 frame, so we set it if (entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out BaseComponent baseComponent)) { ((SmartItemComponent)baseComponent).SetModel(model); } }
private void AddSmartItemComponent(BIWEntity entity) { //Note (Adrian): This will disable the smart item component until it is implemented in kernel //TODO: After the implementation in kernel of smart items, we should eliminate this return return; SmartItemComponent.Model model = new SmartItemComponent.Model(); model.values = new Dictionary <object, object>(); sceneToEdit.EntityComponentCreateOrUpdateWithModel(entity.rootEntity.entityId, CLASS_ID_COMPONENT.SMART_ITEM, model); //Note (Adrian): We can't wait to set the component 1 frame, so we set it if (entity.rootEntity.TryGetBaseComponent(CLASS_ID_COMPONENT.SMART_ITEM, out IEntityComponent component)) { ((SmartItemComponent)component).UpdateFromModel(model); } }
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); }
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); }