【问题标题】:Unity and Google's Blockly library integrationUnity 和 Google 的 Blockly 库集成
【发布时间】:2020-10-15 18:41:04
【问题描述】:

对于我的本科期末项目,我想开发一个用于教授基本编程的教育游戏,所以我想为他们提供一些简单的拖放可视化编程编辑器,例如 code it,但我不知道该怎么做我是团结的新手,我在谷歌做了很多搜索,但我没有得到它(我很迷茫)。所以请任何人帮助我并给我一个线索,这样我就可以建立它.谢谢您的帮助 这是我的游戏设计expl 的示例(我想通过拖放来移动玩家向右移动、向上移动、向前移动......)。我家我的想法和问题很清楚

【问题讨论】:

    标签: unity3d blockly


    【解决方案1】:

    几个月前,我开发了一个与您的项目非常相似的项目。我最近从这个项目中推断出一个库并将其发布在 github 上。该库名为blockly-gamepad ?,允许您使用blockly 创建game 的结构,并使用play()pause() 等方法与其交互。

    我相信这将大大简化blocklyunity之间的交互,如果您对文档感兴趣可以找到游戏的直播demo


    这是演示的 GIF。

    工作原理

    与正常使用blockly相比,这是一种不同且简化的方法

    首先您必须定义 (请参阅如何在documentation 中定义它们)
    您不必定义any code generator,所有与代码生成有关的事情都由库执行。


    每个块都会生成一个请求

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


    当一个块被执行时,相应的请求被传递给你的游戏

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


    您可以使用 promises 来管理 异步动画

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


    积木与您的游戏之间的链接由游戏手柄管理。

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


    游戏手柄提供了一些方法来管理块执行以及请求生成

    // 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)
    

    您可以阅读完整的文档here
    我希望我对这个项目有所帮助并祝你好运!


    编辑:我更新了库的名称,现在称为blockly-gamepad

    【讨论】:

      【解决方案2】:

      您的游戏看起来很酷! 对于 code-it,我们使用 Blockly 作为代码编辑器。然后代码由游戏中的 Lua 解释器执行。你可以做一些更简单的事情:为每个动作创建一个块类型,如 MoveForward 等,并让它们生成函数调用,如 SendMessage('gameInterfaceObject','MoveForward')。在游戏中,您需要一个 Object 来监听来自网站的此类消息。

      您的游戏与网站的交互方式如下: https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html

      【讨论】:

        猜你喜欢
        • 2014-10-31
        • 2014-05-15
        • 1970-01-01
        • 1970-01-01
        • 2018-02-28
        • 2019-05-30
        • 1970-01-01
        • 1970-01-01
        • 2016-12-06
        相关资源
        最近更新 更多