Beispiel #1
0
    public void RemoveObjects(Block[] blocks, Model[] models)
    {
        EditLayer layer = this.CurrentLayer;

        this.AddCommand(new Command(
                            () => {
            layer.RemoveBlocks(blocks);
            layer.RemoveModels(models, true);
        }, () => {
            layer.AddModels(models);
            layer.AddBlocks(blocks);
        }));
    }
Beispiel #2
0
    public void AddObjects(Block[] blocks, Model[] models)
    {
        EditLayer layer = this.CurrentLayer;

        Block[] removedBlocks = null;           // 上書きされたブロック
        Model[] removedModels = null;           // 上書きされたモデル
        this.AddCommand(new Command(
                            () => {
            removedBlocks = layer.AddBlocks(blocks);
            removedModels = layer.AddModels(models);
        }, () => {
            layer.RemoveModels(models, true);
            layer.RemoveBlocks(blocks);
            layer.AddBlocks(removedBlocks);
            layer.AddModels(removedModels);
            removedBlocks = null;
            removedModels = null;
        }));
    }
Beispiel #3
0
    public void MoveObjects(Block[] blocks, Model[] models, Vector3 moveVector,
                            Vector3 centerPosition, int rotation)
    {
        EditLayer layer = this.CurrentLayer;

        Block[] removedBlocks = null;           // 上書きされたブロック
        Model[] removedModels = null;           // 上書きされたモデル

        if (blocks.Length == 0 && models.Length == 0)
        {
            return;
        }
        this.AddCommand(new Command(
                            () => {
            // レイヤーから一旦削除
            layer.RemoveBlocks(blocks);
            layer.RemoveModels(models, false);
            // ブロックを移動回転させる
            foreach (var block in blocks)
            {
                Vector3 offset = block.position - centerPosition;
                offset         = EditUtil.RotatePosition(offset, rotation);
                block.SetPosition(centerPosition + offset + moveVector);
                block.SetDirection(EditUtil.RotateDirection(block.direction, rotation));
            }
            // モデルを移動回転させる
            foreach (var model in models)
            {
                Vector3 offset = model.position - centerPosition;
                offset         = EditUtil.RotatePosition(offset, rotation);
                model.SetPosition(centerPosition + offset + moveVector);
                model.SetRotation(model.rotation + rotation * 90);
            }
            // レイヤーに戻す
            removedBlocks = layer.AddBlocks(blocks);
            removedModels = layer.AddModels(models);
        }, () => {
            // レイヤーから一旦削除
            layer.RemoveBlocks(blocks);
            layer.RemoveModels(models, false);
            // 退避したブロックを復活させる
            layer.AddBlocks(removedBlocks);
            layer.AddModels(removedModels);
            removedBlocks = null;
            removedModels = null;
            // ブロックを逆方向に移動回転させる
            foreach (var block in blocks)
            {
                Vector3 offset = block.position - centerPosition - moveVector;
                offset         = EditUtil.RotatePosition(offset, -rotation);
                block.SetPosition(centerPosition + offset);
                block.SetDirection(EditUtil.RotateDirection(block.direction, -rotation));
            }
            // モデルを逆方向に移動回転させる
            foreach (var model in models)
            {
                Vector3 offset = model.position - centerPosition - moveVector;
                offset         = EditUtil.RotatePosition(offset, -rotation);
                model.SetPosition(centerPosition + offset);
                model.SetRotation(model.rotation - rotation * 90);
            }
            // レイヤーに戻す
            layer.AddBlocks(blocks);
            layer.AddModels(models);
        }));
    }