Exemplo n.º 1
0
    private void MouseUp(int buttonID, Vector3 position)
    {
        if (!mousePressed || buttonID != 0)
        {
            return;
        }

        if (isCreatingMultipleVoxels)
        {
            lastVoxelCreated.rootEntity.transform.SetParent(null);
            bool canVoxelsBeCreated = true;

            foreach (VoxelPrefab voxel in createdVoxels.Values)
            {
                if (!voxel.IsAvailable())
                {
                    canVoxelsBeCreated = false;
                    break;
                }
            }

            BIWCompleteAction buildAction = new BIWCompleteAction();
            buildAction.actionType = BIWCompleteAction.ActionType.CREATE;

            List <BIWEntityAction> entityActionList = new List <BIWEntityAction>();

            foreach (Vector3Int voxelPosition in createdVoxels.Keys)
            {
                if (canVoxelsBeCreated)
                {
                    IDCLEntity entity = biwEntityHandler.DuplicateEntity(lastVoxelCreated).rootEntity;
                    entity.gameObject.tag = BIWSettings.VOXEL_TAG;
                    entity.gameObject.transform.position = voxelPosition;

                    BIWEntityAction biwEntityAction = new BIWEntityAction(entity, entity.entityId, BIWUtils.ConvertEntityToJSON(entity));
                    entityActionList.Add(biwEntityAction);
                }

                GameObject.Destroy(createdVoxels[voxelPosition].gameObject);
            }

            if (!canVoxelsBeCreated)
            {
                biwEntityHandler.DeleteEntity(lastVoxelCreated);
            }
            else
            {
                buildAction.CreateActionType(entityActionList, BIWCompleteAction.ActionType.CREATE);
                biwActionController.AddAction(buildAction);
            }

            createdVoxels.Clear();
            biwEntityHandler.DeselectEntities();

            lastVoxelCreated         = null;
            isCreatingMultipleVoxels = false;

            mousePressed = false;
            freeCameraMovement.SetCameraCanMove(true);
        }
    }