DCLBuilderInWorldEntity SetupEntityToEdit(IDCLEntity entity, bool hasBeenCreated = false) { if (!convertedEntities.ContainsKey(GetConvertedUniqueKeyForEntity(entity))) { DCLBuilderInWorldEntity entityToEdit = Utils.GetOrCreateComponent <DCLBuilderInWorldEntity>(entity.gameObject); entityToEdit.Init(entity, editMaterial); convertedEntities.Add(entityToEdit.entityUniqueId, entityToEdit); entity.OnRemoved += RemoveConvertedEntity; entityToEdit.IsNew = hasBeenCreated; string entityName = entityToEdit.GetDescriptiveName(); var catalogItem = entityToEdit.GetCatalogItemAssociated(); if ((string.IsNullOrEmpty(entityName) || entityNameList.Contains(entityName)) && catalogItem != null) { entityName = GetNewNameForEntity(catalogItem); SetEntityName(entityToEdit, entityName); } else if (!string.IsNullOrEmpty(entityName) && !entityNameList.Contains(entityName)) { entityNameList.Add(entityName); } return(entityToEdit); } else { return(convertedEntities[GetConvertedUniqueKeyForEntity(entity)]); } }
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 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); }
public void UndoRedoCreateDeleteActions() { actionController.CreateActionEntityCreated(scene.entities[ENTITY_ID]); actionController.TryToUndoAction(); Assert.IsFalse(scene.entities.ContainsKey(ENTITY_ID)); actionController.TryToRedoAction(); Assert.IsTrue(scene.entities.ContainsKey(ENTITY_ID)); DCLBuilderInWorldEntity biwEntity = Utils.GetOrCreateComponent <DCLBuilderInWorldEntity>(scene.entities[ENTITY_ID].gameObject); biwEntity.Init(scene.entities[ENTITY_ID], null); actionController.CreateActionEntityDeleted(biwEntity); actionController.TryToUndoAction(); Assert.IsTrue(scene.entities.ContainsKey(ENTITY_ID)); actionController.TryToRedoAction(); Assert.IsFalse(scene.entities.ContainsKey(ENTITY_ID)); }