imagicbell / ublockly

reimplementation of google blockly for Unity
http://imagicbell.github.io/unity/2017/10/11/blockly-one.html
Apache License 2.0
138 stars 52 forks source link

如果我想自己做一个block,该怎么做呢 #3

Closed wstcgez closed 3 years ago

imagicbell commented 4 years ago
  1. 用json定义该block,参考built-in blocks (/Source/JsonBlocks/ 目录下);
  2. 如果使用C#,解释该Block的行为(code interpreter),参考built-in blocks (/Source/Script/CodeDB/CSharp/Interpreters/ 目录下); 3.如果使用Lua,为该Block生成Lua代码(code generator),参考built-in blocks (/Source/Script/CodeDB/Lua/Generators/ 目录下); 4.如果是特殊的block(带有变形功能),需要提供可供编辑变形的UI。(这一步比较麻烦,可能你并不需要)
wstcgez commented 4 years ago

json定义和code interpreter都写了,但是会报错,不知道哪边细节没做好。

ArgumentNullException: Value cannot be null. Parameter name: collection System.ThrowHelper.ThrowArgumentNullException (System.ExceptionArgument argument) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Collections.Generic.List1[T].InsertRange (System.Int32 index, System.Collections.Generic.IEnumerable1[T] collection) (at <437ba245d8404784b9fbab9b439ac908>:0) System.Collections.Generic.List1[T].AddRange (System.Collections.Generic.IEnumerable1[T] collection) (at <437ba245d8404784b9fbab9b439ac908>:0) UBlockly.UGUI.ToolboxBlockCategory.Init () (at Assets/ublockly-master/Source/Script/UGUIView/Toolbox/ToolboxConfig.cs:71) UBlockly.UGUI.ToolboxConfig.Load (System.String configName) (at Assets/ublockly-master/Source/Script/UGUIView/Toolbox/ToolboxConfig.cs:47) UBlockly.UGUI.WorkspaceView.BindModel (UBlockly.Workspace workspace) (at Assets/ublockly-master/Source/Script/UGUIView/WorkspaceView.cs:63) UBlockly.UGUI.BlocklyUI.NewWorkspace () (at Assets/ublockly-master/Source/Script/UGUIView/BlocklyUI.cs:38) UBlockly.UGUI.WorkspaceView.Awake () (at Assets/ublockly-master/Source/Script/UGUIView/WorkspaceView.cs:196)

imagicbell commented 4 years ago

从这个log里我看不出问题出在哪里。 方便把你的case给我一下,我试一下。 或者你自己也可以debug源代码看一下?

wstcgez commented 4 years ago

JSON: [{ "type": "find_obj", "message0": "%{BKY_COROUTINE_WAIT_TITLE} %1 %{BKY_COROUTINE_FRAME}", "args0": [ { "type": "field_input", "name": "NAME", "text": "" } ], "output": "String", "colour": "%{BKY_OBJ_HUE}", "tooltip": "", "helpUrl": "" }]

INTER: using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq;

namespace UBlockly { [CodeInterpreter(BlockType = "find_obj")] public class Find_obj_Cmdtor : ValueCmdtor { protected override DataStruct Execute(Block block) { string value = block.GetFieldValue("NAME"); return new DataStruct(value); } } }

imagicbell commented 4 years ago

问题出在你没有给新加的block定义一个“类别”,如果你是直接加在built-in的类别里面,比如说couroutine,那么blockType需要加上couroutine的前缀用来区分“类别”,也用于UI的的类别显示,例如 coroutine_find_obj. 如果你要自己新加一个类别,那么需要在 UBlocklyData/Toolboxs/Configs/toolbox_default.json中加一个。 抱歉,文档欠缺,我后面补全,谢谢~