Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2k stars 415 forks source link

Multiple instances of node editors open at once #188

Open sunny8751 opened 4 years ago

sunny8751 commented 4 years ago

It would be super useful to have multiple node editors open to edit different canvases simultaneously. Is there a way of doing this currently?

Seneral commented 4 years ago

Theoretically if they are different windows that properly use different cache paths (e.g. two different tools), then already yes. However the default window currently does not support that.

It also depends on what you expect it to do. Do you want it to be tabs in a single window, so that when you close the window and reopen it, all tabs reopen as well? Or just multiple window instances each with their own single canvas? Then what happens if you close one of these instances (or unity crashes) - do you expect to be able to reopen these canvases, just as you would when you have only one window? Unlikely, since the system would have no way to know which previously closed canvases you expect to work on again, and you can't store them infinitely, so likely you'd have to give up on that functionality, at least partially.

So I see two options: A tabbed window (with correspondingly a lot of effort to adjust the UI) that behaves as you would expect it to, or multiple windows, but only the last window to close actually stores the working canvas so you can reopen it.

For option 1 (tabbed canvas): Give each tab an own NodeCanvasUserCache with unique but deterministic cache path (e.g. _1, _2, ... postfix). Then on window open, check the cache paths and reopen all tabs. Then of course create the tabbing UI. Since I expect you want multiple views at the same time, also add split view support. Technically no problem, the backend should support all that, but that is quite some extra effort designing the UI...

For option 2 (multiple instances):

  1. Allow multiple windows unity-side, and on creation find all open instances, and assign a unoccupied ID to the new window. If there is a cache file without an assigned open instance, assume the editor crashed or something and you're reopening the instances one by one, and use that cache's ID. This also covers the case of reopening the canvas the last window had open.
  2. Use the cache path with your ID as suffix, so you have several cache files (last+cur Session) with unique suffixes.
  3. On window close, if you are NOT the last window to close, delete your cache file, thus always leaving exactly one cache file (or if the editor crashed, all cache files) for the next opened instance to reopen. Note that the cache files are still required to exist for the other instances, especially the curSession, since that is required for the Undo to survive playmode changes, scene changes and script recompiles.

So yeah, there's no one good solution I'd be happy going with. If you want to implement either, these should be the steps required for it. I'd be happy to help you with it, but currently I do not have the time to do such an endeavor, sorry.