private void OnDisable()
        {
            var guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(database));

            if (database != null)
            {
                EditorPrefs.SetString(DatabaseGUIDPrefsKey, guid);
            }
            instance = null;
        }
        private void OnEnable()
        {
            instance = this;
            minSize  = new Vector2(300, 240);
            database = DialogueEditorWindow.GetCurrentlyEditedDatabase();
            if (database == null)
            {
                EditorTools.FindInitialDatabase();
            }

            if (database == null && EditorPrefs.HasKey(DatabaseGUIDPrefsKey))
            {
                var guid = EditorPrefs.GetString(DatabaseGUIDPrefsKey);
                database = AssetDatabase.LoadAssetAtPath <DialogueDatabase>(guid);
            }
            template = TemplateTools.LoadFromEditorPrefs();
            if (variableView == null)
            {
                variableView = new DialogueEditorVariableView();
            }
            variableView.Initialize(database, template, false);
        }
        private void DrawVariableMenu()
        {
            if (!isDialogueEditorWindow)
            {
                EditorGUI.BeginDisabledGroup(!Application.isPlaying);
                if (GUILayout.Button(new GUIContent("Refresh", "Refresh runtime values."), "MiniButton", GUILayout.Width(64)))
                {
                    RefreshRuntimeValues();
                }
                EditorGUI.EndDisabledGroup();
            }

            if (GUILayout.Button("Menu", "MiniPullDown", GUILayout.Width(56)))
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("New Variable"), false, () => { CreateNewVariable(string.Empty); });
                menu.AddItem(new GUIContent("Sort/By Name"), false, SortVariablesByName);
                menu.AddItem(new GUIContent("Sort/By ID"), false, SortVariablesByID);
                if (isDialogueEditorWindow)
                {
                    menu.AddItem(new GUIContent("Sync From DB"), database.syncInfo.syncVariables, ToggleSyncVariablesFromDB);
                }
                menu.AddItem(new GUIContent("Use Group Foldouts"), showVariableGroupFoldouts, ToggleShowVariableGroupFoldouts);
                if (isDialogueEditorWindow)
                {
                    menu.AddItem(new GUIContent("Variable Viewer..."), false, () => { VariableViewWindow.OpenVariableViewWindow(); });
                }
                menu.ShowAsContext();
            }
        }