imagicbell / ublockly

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

Create new blocks #29

Closed HerrAugust closed 3 years ago

HerrAugust commented 3 years ago

Hi,

The explaination about creating new blocks is pretty confusing.

I create a new category in toolbox_default.json and its content is now:

     "Style": "classic",
     "BlockCategoryList": [
          {
               "CategoryName": "CONTROL",
               "ColorHex": "#669966",
               "BlockTypePrefix": "controls"
          },
          {
               "CategoryName": "MATH",
               "ColorHex": "#4668a5",
               "BlockTypePrefix": "math"
          },
          {
               "CategoryName": "TEXT",
               "ColorHex": "#f6546a",
               "BlockTypePrefix": "text"
          },
          {
               "CategoryName": "ARDUINO",
               "ColorHex": "#f6546a",
               "BlockTypePrefix": "uc3marduino"
          }
     ]
}

Then, I create a new file in the folder \Assets\UBlockly\JsonBlocks\ called uc3marduino.json with content (just to try if it works):

  {
    "type": "uc3marduino_t",
    "message0": "\" %1 \"",
    "args0": [{
      "type": "field_input",
      "name": "TEXT",
      "text": ""
    }],
    "output": "String",
    "colour": "%{BKY_TEXT_HUE}",
    "helpUrl": "%{BKY_TEXT_TEXT_HELPURL}",
    "tooltip": "%{BKY_TEXT_TEXT_TOOLTIP}",
    "extensions": [
      "text_quotes",
      "parent_tooltip_when_inline"
    ]
  }
]

Then, I modify the file UBlocklyData\Resources\BlockResSettings.assets:

 - IndexName: variables
    ResName: variables
    TextFile: {fileID: 4900000, guid: d0e6cc79a30de40e6ab2a13928a03d85, type: 3}
  - IndexName: uc3mandroid
    ResName: uc3mandroid
    TextFile: {fileID: 4900000, guid: d0e6cc79a30de40e6ab2a13928a03d86, type: 3}
  m_ToolboxFiles:
  - IndexName: default
    ResName: toolbox_default
    TextFile: {fileID: 4900000, guid: 5c0bdd5df6d904a27af2a1b56125a6e0, type: 3}
    Selected: 1
  m_BlockViewPrefabPath: Assets/UBlocklyData/BlockGenPrefabs/
  m_BlockViewPrefabs:
  - IndexName: colour_picker
    ResName: Block_colour_picker
    Prefab: {fileID: 1465611821804190, guid: 9c45cd753686049bea63954b59419ac3, type: 2}
...

Can anyone tell what I miss? I get error:

Parameter name: collection
System.ThrowHelper.ThrowArgumentNullException (System.ExceptionArgument argument) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.List`1[T].InsertRange (System.Int32 index, System.Collections.Generic.IEnumerable`1[T] collection) (at <695d1cc93cca45069c528c15c9fdd749>:0)
System.Collections.Generic.List`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] collection) (at <695d1cc93cca45069c528c15c9fdd749>:0)
UBlockly.UGUI.ToolboxBlockCategory.Init () (at Assets/UBlockly/Script/UGUIView/Toolbox/ToolboxConfig.cs:69)
UBlockly.UGUI.ToolboxConfig.Load () (at Assets/UBlockly/Script/UGUIView/Toolbox/ToolboxConfig.cs:45)
UBlockly.UGUI.WorkspaceView.BindModel (UBlockly.Workspace workspace) (at Assets/UBlockly/Script/UGUIView/WorkspaceView.cs:62)
UBlockly.UGUI.BlocklyUI.NewWorkspace () (at Assets/UBlockly/Script/UGUIView/BlocklyUI.cs:38)
UBlockly.UGUI.WorkspaceView.Awake () (at Assets/UBlockly/Script/UGUIView/WorkspaceView.cs:169)
HerrAugust commented 3 years ago

Solved by adding the new block to the already available categories.