private void Unsubscribe(SmoothGroupEditor editor)
 {
     if (editor == null)
     {
         return;
     }
     editor.Clear           -= OnClear;
     editor.ExpandSelection -= OnExpandSelection;
     editor.Smooth          -= OnSmooth;
 }
        private void OnClear(object sender, EventArgs e)
        {
            SmoothGroupEditor editor = (SmoothGroupEditor)sender;
            PBMesh            pbMesh = editor.Data.PBMesh;

            IMeshEditor     meshEditor = m_proBuilderTool.GetEditor();
            MeshEditorState oldState   = meshEditor.GetState(false);

            PBSmoothing.ClearGroup(pbMesh, meshEditor.GetSelection());

            m_smoothGroups[pbMesh].Rebuild(pbMesh);
            m_proBuilderTool.TryUpdatePivotTransform();

            MeshEditorState newState = meshEditor.GetState(false);

            m_proBuilderTool.RecordState(oldState, newState, true);
        }
        private void UpdateEditorsPanel()
        {
            foreach (Transform child in m_contentPanel)
            {
                SmoothGroupEditor editor = child.GetComponent <SmoothGroupEditor>();
                Unsubscribe(editor);

                Destroy(child.gameObject);
            }

            IMeshEditor meshEditor = m_proBuilderTool.GetEditor();

            if (meshEditor == null)
            {
                return;
            }

            MeshSelection selection = meshEditor.GetSelection();

            if (selection == null)
            {
                return;
            }

            selection = selection.ToFaces(false);
            if (!selection.HasFaces)
            {
                return;
            }

            const int maxVisibleGroups = 8;
            int       index            = 0;

            foreach (PBMesh pbMesh in selection.GetSelectedMeshes())
            {
                index++;
                if (index == maxVisibleGroups)
                {
                    return;
                }

                SmoothGroupEditor editor = Instantiate(m_groupPrefab, m_contentPanel);
                editor.Data = m_smoothGroups[pbMesh];
                Subscribe(editor);
            }
        }
 private void Subscribe(SmoothGroupEditor editor)
 {
     editor.Clear           += OnClear;
     editor.ExpandSelection += OnExpandSelection;
     editor.Smooth          += OnSmooth;
 }