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 has default input blocks ? #23

Open vml933 opened 3 years ago

vml933 commented 3 years ago

Hello, I want to do : when user drag block(math_arithmetic) on canvas, it default has to 2 block(math_number) in the block(math_arithmetic) slots, not 2 empty slot.

Is it possible to do that ? can you give me some tip? Thanks.

imagicbell commented 3 years ago

This is a very good suggestion. Google Blockly has this feature. I didn't move this to ublockly. But it can be done. I've checked the google's code. They append the default input into the block in the initialization phase. That is to build a block, we not only create the original block object, but also connect the default input block. But in ublockly, we might have a simpler implementation. My thought is:
When we drag the block from the tool box into workspace, in addition to clone the original block object, we also check the input, create the input block and connect it to the parent block.
I will add this feature in the future. However, if you would like to have a try, PR is welcome:smile:

vml933 commented 3 years ago

Hello: I have some progress, similar your thought: drag the block to workspace, then check the input and create block and append, but my codes is dirty for now ,I try to solve it.

Thanks your help.