Ejemplo 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);
        }
    }
    public void CreateActionEntityCreated(IDCLEntity entity)
    {
        BIWEntityAction biwEntityAction = new BIWEntityAction(entity, entity.entityId, BIWUtils.ConvertEntityToJSON(entity));

        BIWCompleteAction buildAction = new BIWCompleteAction();

        buildAction.CreateActionType(biwEntityAction, ActionType.CREATE);

        AddAction(buildAction);
    }
    public void DuplicateSelectedEntities()
    {
        BIWCompleteAction buildAction = new BIWCompleteAction();

        buildAction.actionType = BIWCompleteAction.ActionType.CREATE;

        List <BIWEntityAction> entityActionList    = new List <BIWEntityAction>();
        List <BIWEntity>       entitiesToDuplicate = new List <BIWEntity>(selectedEntities);

        DeselectEntities();

        foreach (BIWEntity entityToDuplicate in entitiesToDuplicate)
        {
            if (entityToDuplicate.isNFT)
            {
                continue;
            }

            var             entityDuplicated = DuplicateEntity(entityToDuplicate);
            BIWEntityAction biwEntityAction  = new BIWEntityAction(entityDuplicated.rootEntity, entityDuplicated.rootEntity.entityId, BIWUtils.ConvertEntityToJSON(entityDuplicated.rootEntity));
            entityActionList.Add(biwEntityAction);
            SelectEntity(entityDuplicated);
        }

        currentActiveMode?.SetDuplicationOffset(DUPLICATE_OFFSET);

        buildAction.CreateActionType(entityActionList, BIWCompleteAction.ActionType.CREATE);
        actionController.AddAction(buildAction);
    }
    public void CreateActionEntityDeleted(List <BIWEntity> entityList)
    {
        BIWCompleteAction      buildAction      = new BIWCompleteAction();
        List <BIWEntityAction> entityActionList = new List <BIWEntityAction>();

        foreach (BIWEntity entity in entityList)
        {
            BIWEntityAction biwEntityAction = new BIWEntityAction(entity.rootEntity.entityId, BIWUtils.ConvertEntityToJSON(entity.rootEntity), entity.rootEntity.entityId);
            entityActionList.Add(biwEntityAction);
        }

        buildAction.CreateActionType(entityActionList, BIWCompleteAction.ActionType.DELETE);

        AddAction(buildAction);
    }