void OnDestroy() { // we are closing the shadergraph window MaterialGraphEditWindow newWindow = null; if (!PromptSaveIfDirtyOnQuit()) { // user does not want to close the window. // we can't stop the close from this code path though.. // all we can do is open a new window and transfer our data to the new one to avoid losing it // newWin = Instantiate<MaterialGraphEditWindow>(this); newWindow = EditorWindow.CreateWindow <MaterialGraphEditWindow>(typeof(MaterialGraphEditWindow), typeof(SceneView)); newWindow.Initialize(this); } else { // the window is closing for good.. cleanup undo history for the graph object Undo.ClearUndo(graphObject); } graphObject = null; graphEditorView = null; // show new window if we have one if (newWindow != null) { newWindow.Show(); newWindow.Focus(); } }
public void Initialize(MaterialGraphEditWindow other) { // create a new window that copies the entire editor state of an existing window // this function is used to "reopen" an editor window that is closing, but where the user has canceled the close // for example, if the graph of a closing window was dirty, but could not be saved try { EditorApplication.wantsToQuit -= PromptSaveIfDirtyOnQuit; selectedGuid = other.selectedGuid; graphObject = CreateInstance <GraphObject>(); graphObject.hideFlags = HideFlags.HideAndDontSave; graphObject.graph = other.graphObject.graph; graphObject.graph.messageManager = this.messageManager; UpdateTitle(); Repaint(); EditorApplication.wantsToQuit += PromptSaveIfDirtyOnQuit; } catch (Exception e) { Debug.LogException(e); m_HasError = true; m_GraphEditorView = null; graphObject = null; throw; } }