public DCLBuilderInWorldEntity CreateCatalogItem(CatalogItem catalogItem, bool autoSelect = true, bool isFloor = false) { if (catalogItem.IsNFT() && BuilderInWorldNFTController.i.IsNFTInUse(catalogItem.id)) { return(null); } IsInsideTheLimits(catalogItem); //Note (Adrian): This is a workaround until the mapping is handle by kernel AddSceneMappings(catalogItem); Vector3 startPosition = biwModeController.GetModeCreationEntryPoint(); Vector3 editionPosition = biwModeController.GetCurrentEditionPosition(); DCLBuilderInWorldEntity entity = builderInWorldEntityHandler.CreateEmptyEntity(sceneToEdit, startPosition, editionPosition, false); entity.isFloor = isFloor; entity.SetRotation(Vector3.zero); if (!isFloor) { CreateLoadingObject(entity); } AddShape(catalogItem, entity); AddEntityNameComponent(catalogItem, entity); AddLockedComponent(entity); if (catalogItem.IsSmartItem()) { AddSmartItemComponent(entity); } if (catalogItem.IsVoxel()) { entity.isVoxel = true; } if (autoSelect) { builderInWorldEntityHandler.DeselectEntities(); builderInWorldEntityHandler.Select(entity.rootEntity); } entity.gameObject.transform.eulerAngles = Vector3.zero; biwModeController.CreatedEntity(entity); lastCatalogItemCreated = catalogItem; entity.OnShapeFinishLoading += OnShapeLoadFinish; builderInWorldEntityHandler.EntityListChanged(); builderInWorldEntityHandler.NotifyEntityIsCreated(entity.rootEntity); OnInputDone?.Invoke(); OnSceneObjectPlaced?.Invoke(); return(entity); }
private void MouseUp(int buttonID, Vector3 position) { if (!mousePressed || buttonID != 0) { return; } if (isCreatingMultipleVoxels) { lastVoxelCreated.transform.SetParent(null); bool canVoxelsBeCreated = true; foreach (VoxelPrefab voxel in createdVoxels.Values) { if (!voxel.IsAvailable()) { canVoxelsBeCreated = false; break; } } BuildInWorldCompleteAction buildAction = new BuildInWorldCompleteAction(); buildAction.actionType = BuildInWorldCompleteAction.ActionType.CREATE; List <BuilderInWorldEntityAction> entityActionList = new List <BuilderInWorldEntityAction>(); foreach (Vector3Int voxelPosition in createdVoxels.Keys) { if (canVoxelsBeCreated) { DecentralandEntity entity = builderInWorldEntityHandler.DuplicateEntity(lastVoxelCreated); entity.gameObject.tag = BuilderInWorldSettings.VOXEL_TAG; entity.gameObject.transform.position = voxelPosition; BuilderInWorldEntityAction builderInWorldEntityAction = new BuilderInWorldEntityAction(entity, entity.entityId, BuilderInWorldUtils.ConvertEntityToJSON(entity)); entityActionList.Add(builderInWorldEntityAction); } Destroy(createdVoxels[voxelPosition].gameObject); } if (!canVoxelsBeCreated) { builderInWorldEntityHandler.DeleteEntity(lastVoxelCreated); } else { buildAction.CreateActionType(entityActionList, BuildInWorldCompleteAction.ActionType.CREATE); actionController.AddAction(buildAction); } createdVoxels.Clear(); builderInWorldEntityHandler.DeselectEntities(); lastVoxelCreated = null; isCreatingMultipleVoxels = false; mousePressed = false; freeCameraMovement.SetCameraCanMove(true); } }
private void MouseClickDetected() { DCLBuilderInWorldEntity entityToSelect = builderInWorldEntityHandler.GetEntityOnPointer(); if (entityToSelect != null) { builderInWorldEntityHandler.EntityClicked(entityToSelect); } else if (!isMultiSelectionActive) { builderInWorldEntityHandler.DeselectEntities(); } }
public void CreateFloor(CatalogItem floorSceneObject) { Vector3 initialPosition = new Vector3(ParcelSettings.PARCEL_SIZE / 2, 0, ParcelSettings.PARCEL_SIZE / 2); Vector2Int[] parcelsPoints = sceneToEdit.sceneData.parcels; foreach (Vector2Int parcel in parcelsPoints) { DCLBuilderInWorldEntity decentralandEntity = biwCreatorController.CreateSceneObject(floorSceneObject, false, true); decentralandEntity.rootEntity.OnShapeUpdated += OnFloorLoaded; decentralandEntity.transform.position = WorldStateUtils.ConvertPointInSceneToUnityPosition(initialPosition, parcel); dclBuilderMeshLoadIndicatorController.ShowIndicator(decentralandEntity.rootEntity.gameObject.transform.position, decentralandEntity.rootEntity.entityId); GameObject floorPlaceHolder = GameObject.Instantiate(floorPrefab, decentralandEntity.rootEntity.gameObject.transform.position, Quaternion.identity); floorPlaceHolderDict.Add(decentralandEntity.rootEntity.entityId, floorPlaceHolder); builderInWorldBridge?.EntityTransformReport(decentralandEntity.rootEntity, sceneToEdit); } builderInWorldEntityHandler.DeselectEntities(); lastFloorCalalogItemUsed = floorSceneObject; }
public virtual void Deactivate() { gameObject.SetActive(false); isModeActive = false; builderInWorldEntityHandler.DeselectEntities(); }
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); }