Closed wstcgez closed 3 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.IEnumerable
1[T] collection) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Collections.Generic.List1[T].AddRange (System.Collections.Generic.IEnumerable
1[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)
从这个log里我看不出问题出在哪里。 方便把你的case给我一下,我试一下。 或者你自己也可以debug源代码看一下?
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); } } }
问题出在你没有给新加的block定义一个“类别”,如果你是直接加在built-in的类别里面,比如说couroutine,那么blockType需要加上couroutine的前缀用来区分“类别”,也用于UI的的类别显示,例如 coroutine_find_obj. 如果你要自己新加一个类别,那么需要在 UBlocklyData/Toolboxs/Configs/toolbox_default.json中加一个。 抱歉,文档欠缺,我后面补全,谢谢~