gpt4 book ai didi

unity-game-engine - Unity 和 Google 的 Blockly 库集成

转载 作者:行者123 更新时间:2023-12-02 14:59:10 24 4
gpt4 key购买 nike

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

最佳答案

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

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


这是演示的 gif。

enter image description here

它是如何工作的

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

首先,您必须定义 block (请参阅 documentation 中如何定义它们)
您不必定义任何代码生成器,所有涉及代码生成的工作都由库执行。

enter image description here


每个 block 都会生成一个请求

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


当执行 block 时,相应的请求将传递到您的游戏

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


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

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


block 和游戏之间的链接由游戏 handle 管理。

let gamepad = new Blockly.Gamepad(),
game = new Game()

// requests will be passed here
gamepad.setGame(game, game.manageRequest)


游戏 handle 提供了一些方法来管理 block 的执行以及请求的生成

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

关于unity-game-engine - Unity 和 Google 的 Blockly 库集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56725374/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com