private void Disable()
    {
        m_bActive = false;
        viewModel.Disable();

        Undo.undoRedoPerformed    -= MyUndoCallback;
        viewModel.OnCellZChanged  -= OnCellZChanged;
        viewModel.OnCellXYChanged -= OnCellXYChanged;
        viewModel.OnPrefabChanged -= OnPrefabChanged;
        viewModel.OnGridChanged   -= OnGridChanged;
        viewModel.OnToolChanged   -= OnToolChanged;


        GameObject.DestroyImmediate(m_currentBrush);
        m_currentBrush = null;

        // Try to re-select if there was just a prefab selected
        if (Selection.activeGameObject != null && !Selection.activeGameObject.scene.IsValid())
        {
            viewModel.SelectPrefab(Selection.activeGameObject);

            if (target)
            {
                Selection.activeGameObject = ((MonoBehaviour)target).gameObject;
            }

            useNextViewModel = viewModel;
            viewModel        = null;
        }
    }
    // Add menu named "My Window" to the Window menu
    public static void Show(GNBlockMapEditorVM viewModel)
    {
        // Get existing open window or if none, make a new one:
        GNBlockMapEditorBoxTransformWindow window = (GNBlockMapEditorBoxTransformWindow)EditorWindow.GetWindow(typeof(GNBlockMapEditorBoxTransformWindow));

        window.viewModel = viewModel;
        window.Show();
    }
    private void Enable()
    {
        if (useNextViewModel != null)
        {
            viewModel        = useNextViewModel;
            inputController  = new GNBlockMapEditorInputController(viewModel);
            useNextViewModel = null;
        }
        else
        {
            viewModel       = GNBlockMapEditorVM.CreateInstance <GNBlockMapEditorVM>();
            inputController = new GNBlockMapEditorInputController(viewModel);
        }

        m_blockMap = (GNBlockMap)target;

        viewModel.Enable(m_blockMap);

        Undo.undoRedoPerformed    += MyUndoCallback;
        viewModel.OnCellZChanged  += OnCellZChanged;
        viewModel.OnCellXYChanged += OnCellXYChanged;
        viewModel.OnPrefabChanged += OnPrefabChanged;
        viewModel.OnGridChanged   += OnGridChanged;
        viewModel.OnToolChanged   += OnToolChanged;

        // clean previous brushes
        for (int i = 0; i < m_blockMap.transform.childCount; i++)
        {
            Transform currentChild = m_blockMap.transform.GetChild(i);
            if (currentChild.name == "_brush")
            {
                GameObject.DestroyImmediate(currentChild.gameObject);
            }
        }

        OnPrefabChanged();
        OnGridChanged();
        FocusSceneView();
        Repaint();
        m_bActive = true;
    }
 public GNBlockMapEditorInputController(GNBlockMapEditorVM _viewModel)
 {
     this.viewModel = _viewModel;
     this.viewModel.OnCellXYChanged += OnCellChanged;
     this.viewModel.OnCellZChanged  += OnCellChanged;
 }