private void Update() { if (!mousePressed || !isVoxelModelActivated || !isCreatingMultipleVoxels) { return; } Vector3Int currentPosition = Vector3Int.zero; VoxelEntityHit voxelHit = buildModeController.GetCloserUnselectedVoxelEntityOnPointer(); if (voxelHit != null && voxelHit.entityHitted.tag == BuilderInWorldSettings.VOXEL_TAG && !voxelHit.entityHitted.IsSelected) { Vector3Int position = ConverPositionToVoxelPosition(voxelHit.entityHitted.rootEntity.gameObject.transform.position); position += voxelHit.hitVector; currentPosition = position; FillVoxels(lastVoxelPositionPressed, currentPosition); } else { RaycastHit hit; UnityEngine.Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, RAYCAST_MAX_DISTANCE, groundLayer)) { currentPosition = ConverPositionToVoxelPosition(hit.point); FillVoxels(lastVoxelPositionPressed, currentPosition); } } }
public void SetEditObjectLikeVoxel() { if (mousePressed || !isVoxelModelActivated) { return; } VoxelEntityHit voxelHit = buildModeController.GetCloserUnselectedVoxelEntityOnPointer(); if (voxelHit != null && voxelHit.entityHitted.IsSelected) { return; } if (voxelHit != null && voxelHit.entityHitted.tag == BuilderInWorldSettings.VOXEL_TAG) { Vector3 position = ConverPositionToVoxelPosition(voxelHit.entityHitted.rootEntity.gameObject.transform.position); position += voxelHit.hitVector; editionGO.transform.position = position; } else { RaycastHit hit; UnityEngine.Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, RAYCAST_MAX_DISTANCE, groundLayer)) { Vector3 position = hit.point; editionGO.transform.position = ConverPositionToVoxelPosition(hit.point); } } }
public VoxelEntityHit GetCloserUnselectedVoxelEntityOnPointer() { RaycastHit[] hits; UnityEngine.Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); ; float currentDistance = 9999; VoxelEntityHit voxelEntityHit = null; hits = Physics.RaycastAll(ray, RAYCAST_MAX_DISTANCE, layerToRaycast); foreach (RaycastHit hit in hits) { string entityID = hit.collider.gameObject.name; if (sceneToEdit.entities.ContainsKey(entityID)) { DCLBuilderInWorldEntity entityToCheck = builderInWorldEntityHandler.GetConvertedEntity(sceneToEdit.entities[entityID]); if (entityToCheck == null) { continue; } Camera camera = Camera.main; if (!entityToCheck.IsSelected && entityToCheck.tag == BuilderInWorldSettings.VOXEL_TAG) { if (Vector3.Distance(camera.transform.position, entityToCheck.rootEntity.gameObject.transform.position) < currentDistance) { voxelEntityHit = new VoxelEntityHit(entityToCheck, hit); currentDistance = Vector3.Distance(camera.transform.position, entityToCheck.rootEntity.gameObject.transform.position); } } } } return(voxelEntityHit); }