unity-game-engineblockly

Unity and Google's Blockly library integration


For my undergrad final project I want to develop an educational game for teaching basic programming so I want to provide them some easy drag'n'drop visual programming editor like in this code it but i have no idea how to do this i'm new in unity and i did a lot of search in google but i didn't get it ( i'm quite loste ) .so please can any one help me in these and give me a clue so i can build on it. thank you for your help this is a example for my game design expl ( i want to move the player by drag and drop move right , move up ,move forward ......). I home my idea and question are clear


Solution

  • A few months ago I developed a project very similar to yours. I recently extrapolated a library from this project and published it on github. the library is called blockly-gamepad 🎮 and allows you to create the structure of a game with blockly and to interact with it using methods such as play() or pause().

    I believe this will greatly simplify the interaction between blockly and unity, if you are interested in the documentation you can find the live demo of a game.


    Here is a gif of the demo.

    enter image description here

    How it works

    This is a different and simplified approach compared to the normal use of blockly.

    At first you have to define the blocks (see how to define them in the documentation).
    You don't have to define any code generator, all that concerns the generation of code is carried out by the library.

    enter image description here


    Each block generate a request.

    // the request
    { method: 'TURN', args: ['RIGHT'] }
    


    When a block is executed the corresponding request is passed to your game.

    class Game{
        manageRequests(request){
            // requests are passed here
            if(request.method == 'TURN')
                // animate your sprite
                turn(request.args)
        }
    }
    


    You can use promises to manage asynchronous animations.

    class Game{
        async manageRequests(request){
            if(request.method == 'TURN')
                await turn(request.args)
        }
    }
    


    The link between the blocks and your game is managed by the gamepad.

    let gamepad = new Blockly.Gamepad(),
        game = new Game()
    
    // requests will be passed here
    gamepad.setGame(game, game.manageRequest)
    


    The gamepad provides some methods to manage the blocks execution and consequently the requests generation.

    // load the code from the blocks in the workspace
    gamepad.load()
    // reset the code loaded previously
    gamepad.reset()
    
    // the blocks are executed one after the other
    gamepad.play() 
    // play in reverse
    gamepad.play(true)
    // the blocks execution is paused
    gamepad.pause()
    // toggle play
    gamepad.togglePlay()
    
    // load the next request 
    gamepad.forward()
    // load the prior request
    gamepad.backward()
    
    // use a block as a breakpoint and play until it is reached
    gamepad.debug(id)
    

    You can read the full documentation here.
    I hope I was helpful and good luck with the project!.


    EDIT: I updated the name of the library, now it is called blockly-gamepad.