private void OnVariableUpdate(VariableUpdateData updateData) { string oldValue = m_Label.text; bool updateThis = updateData.VarName.Equals(oldValue); switch (updateData.Type) { case VariableUpdateData.Delete: { if (updateThis) { // dispose the block if (!mSourceBlockView.InToolbox) { mSourceBlockView.Dispose(); } } break; } case VariableUpdateData.Rename: { if (updateThis) { if (!mSourceBlockView.InToolbox || BlocklyUI.WorkspaceView.Toolbox.GetCategoryNameOfBlockView(mSourceBlockView) == Define.VARIABLE_CATEGORY_NAME) { m_Label.text = updateData.NewVarName; UpdateLayout(XY); } } break; } } }
protected void OnVariableUpdate(VariableUpdateData updateData) { switch (updateData.Type) { case VariableUpdateData.Create: { if (mVariableHelperViews.Count == 0) { CreateVariableHelperViews(); } CreateVariableGetterView(updateData.VarName); break; } case VariableUpdateData.Delete: { DeleteVariableGetterView(updateData.VarName); //change variable helper view List <VariableModel> allVars = mWorkspace.GetAllVariables(); if (allVars.Count == 0) { DeleteVariableHelperViews(); } else { foreach (BlockView view in mVariableHelperViews) { if (view.Block.GetFieldValue("VAR").Equals(updateData.VarName)) { view.Block.SetFieldValue("VAR", allVars[0].Name); } } } break; } case VariableUpdateData.Rename: { BlockView view; mVariableGetterViews.TryGetValue(updateData.VarName, out view); if (view != null) { mVariableGetterViews.Remove(updateData.VarName); mVariableGetterViews[updateData.NewVarName] = view; } break; } } }