/// <summary> /// Create a block from block definitions /// </summary> /// <param name="workspace">The Block's workspace</param> /// <param name="type">block unique type</param> /// <param name="uid">block uid</param> /// <returns></returns> public Block CreateBlock(Workspace workspace, string type, string uid = null) { Block block = new Block(workspace, type, uid); BlockDefinition definition; if (!mDefinitions.TryGetValue(type, out definition)) { //Debug.LogWarning("There is no block definition for type: " + type + ". Please ensure to load it first"); Debug.Log("Create an empty block: " + type); } else { List <Input> inputs = definition.CreateInputList(); Connection output = definition.CreateOutputConnection(); Connection prev = definition.CreatePreviousStatementConnection(); Connection next = definition.CreateNextStatementConnection(); Mutator mutator = definition.CreateMutator(); bool inputsInline = definition.GetInputsInlineDefault(); block.Reshape(inputs, output, prev, next); if (mutator != null) { block.SetMutator(mutator); } if (inputsInline) { block.SetInputsInline(true); } } return(block); }