Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit 98a676a

Browse files
committed
LTS v1.0.1 Release package
Fixed session path in Packages crashing unity when installed through git Difference to master: - Exported as package for Unity Package Manager using Unity package tools - Changed default editor path to Packages/com.seneral.nodeeditorframework
1 parent 73de61c commit 98a676a

14 files changed

+286
-67
lines changed

Editor/NodeEditorWindow.cs

Lines changed: 93 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,44 @@ namespace NodeEditorFramework.Standard
88
{
99
public class NodeEditorWindow : EditorWindow
1010
{
11+
12+
/* Instructions for custom windows! Read if you copy this code to create a custom window for your tool
13+
14+
If you use NodeEditorUserCache to cache and manage the session files, you will need a path to save the curSession and lastSession files to
15+
You can continue using the default temp folder, but then your window will share the session with the default window, which might not be desired
16+
To change the temp folder of this window, there are several options, depending on whether you intent to distribute through the Unity Package Manager or not:
17+
18+
Distribution through Unity Package Manager:
19+
The temp folder HAS to be in the Assets folder, so the Packages/ subfolder won't do. Here are your options:
20+
1. Put your temp folder in a subfolder of the existing temp folder by writing to TEMP_PATH_SUBFOLDER (e.g. "Texture_Composer/") (RECOMMENDED)
21+
2. Change TEMP_PATH_MARKER_GUID to any GUID generated by Unity and change the default location in TEMP_PATH_DEFAULT
22+
To generate a new GUID, create any file, read GUID from .meta file, and delete the file
23+
This will allow users to move your temp folder individually by moving a specifically created marker file
24+
// Both base upon a new variable temp path system, only required if we have no folder in Assets/ that we can call ours to store the sessions in
25+
// It will start with a default folder, but will allow users to easily move it by moving the files and a marker to any folder in Assets/
26+
27+
Normal Distribution as unitypackage or through the Asset Store:
28+
You can use your editorPath where the scripts are stored as a base for storing the temp files. Two options:
29+
1. Do not change anything and use NodeEditor.editorPath as storage folder (DEFAULT, RECOMMENDED)
30+
Optionally store in a subfolder specified by TEMP_PATH_SUBFOLDER (e.g. "Texture_Composer/")
31+
ANY editor tool that embeds the Node Editor Framework in a custom location needs to change NodeEditor.editorPath anyway
32+
3. Change TEMP_PATH_FIXED to a fixed path in the Assets folder, preferrably in your own tools folder
33+
*/
34+
private const bool TEMP_PATH_USE_EDITOR_PATH_IF_IN_ASSETS = true; // If NodeEditor.editorPath starts with Assets/, use that as a base folder
35+
private const string TEMP_PATH_MARKER_GUID = "7b443eac9ba200a4d8d0c7640900a150"; // Marker GUID of default Node Editor Window
36+
private const string TEMP_PATH_DEFAULT = "Assets/DefaultEditorResources/Node_Editor_Framework/";
37+
private const string TEMP_PATH_SUBFOLDER = null; // e.g. Texture_Composer/
38+
private const string TEMP_PATH_FIXED = null;
39+
private const string META_FILE =
40+
@"fileFormatVersion: 2
41+
guid: MARKER_GUID
42+
DefaultImporter:
43+
externalObjects: {}
44+
userData:
45+
assetBundleName:
46+
assetBundleVariant:
47+
";
48+
1149
// Information about current instance
1250
private static NodeEditorWindow _editor;
1351
public static NodeEditorWindow editor { get { AssureEditor(); return _editor; } }
@@ -118,6 +156,7 @@ private void OnFocus ()
118156
private void NormalReInit()
119157
{
120158
NodeEditor.ReInit(false);
159+
AssureCache();
121160
AssureSetup();
122161
if (canvasCache.nodeCanvas)
123162
{
@@ -129,24 +168,68 @@ private void NormalReInit()
129168
private void AssureSetup()
130169
{
131170
if (canvasCache == null)
132-
{ // Create cache
133-
string basePath = Application.dataPath.Substring (0, Application.dataPath.LastIndexOf ("Assets"));
134-
if (System.IO.Directory.Exists(basePath + NodeEditor.editorPath))
135-
canvasCache = new NodeEditorUserCache(NodeEditor.editorPath);
136-
else
137-
{
138-
Debug.LogWarning ("Editor Path '" + NodeEditor.editorPath + "' invalid! Caching in Temp folder!");
139-
canvasCache = new NodeEditorUserCache("Temp/");
140-
}
141-
}
171+
AssureCache();
172+
else if (!AssetDatabase.IsValidFolder(ResourceManager.StripTrailingSeparator(canvasCache.GetCachePath())))
173+
AssureCache();
142174
canvasCache.AssureCanvas();
175+
143176
if (editorInterface == null)
144177
{ // Setup editor interface
145178
editorInterface = new NodeEditorInterface();
146179
editorInterface.canvasCache = canvasCache;
147180
editorInterface.ShowNotificationAction = ShowNotification;
148181
}
149182
}
183+
private void AssureCache()
184+
{
185+
// Get temp path to save cache to
186+
string tempPath;
187+
if (TEMP_PATH_USE_EDITOR_PATH_IF_IN_ASSETS && NodeEditor.editorPath.StartsWith("Assets")
188+
&& AssetDatabase.IsValidFolder(ResourceManager.StripTrailingSeparator(NodeEditor.editorPath)))
189+
{
190+
tempPath = NodeEditor.editorPath;
191+
}
192+
else if (!string.IsNullOrEmpty(TEMP_PATH_FIXED)) {
193+
tempPath = TEMP_PATH_FIXED;
194+
Directory.CreateDirectory(tempPath);
195+
}
196+
else
197+
{ // Use variable temp path, only required if we have no folder in Assets/ that we can call ours to store the sessions in
198+
// It will start with a default folder, but will allow users to easily move it by moving the files and a marker to any folder in Assets/
199+
// 1. Try to find temp path marker
200+
tempPath = AssetDatabase.GUIDToAssetPath(TEMP_PATH_MARKER_GUID);
201+
// Sometimes this will return a path but the asset behind it has been deleted
202+
if (!string.IsNullOrEmpty(tempPath) && !AssetDatabase.IsValidFolder(ResourceManager.UnifyPathSeparators(Path.GetDirectoryName(tempPath), '/')))
203+
tempPath = "";
204+
if (string.IsNullOrEmpty(tempPath) || !File.Exists(tempPath))
205+
{ // 2. Create temp path marker with specified GUID
206+
if (string.IsNullOrEmpty(tempPath))
207+
{ // No previous folder trace to use
208+
Directory.CreateDirectory(TEMP_PATH_DEFAULT);
209+
tempPath = TEMP_PATH_DEFAULT;
210+
}
211+
using (File.Create(tempPath + "NEFTempFilesMarker")) {}
212+
using (StreamWriter sw = File.CreateText(tempPath + "NEFTempFilesMarker.meta"))
213+
sw.Write(META_FILE.Replace("MARKER_GUID", TEMP_PATH_MARKER_GUID));
214+
AssetDatabase.Refresh();
215+
tempPath = AssetDatabase.GUIDToAssetPath(TEMP_PATH_MARKER_GUID);
216+
Debug.LogWarning("Created temp marker '" + tempPath + "'! You can move this marker along with the cache files curSession and lastSession to a different cache location.");
217+
}
218+
tempPath = ResourceManager.UnifyPathSeparators(Path.GetDirectoryName(tempPath), '/') + "/";
219+
}
220+
if (!string.IsNullOrEmpty(TEMP_PATH_SUBFOLDER))
221+
{ // 3. Apply subfolder
222+
tempPath = tempPath + TEMP_PATH_SUBFOLDER;
223+
Directory.CreateDirectory(tempPath);
224+
}
225+
226+
// Make sure we have a cache at that temp path with a canvas
227+
if (canvasCache == null)
228+
canvasCache = new NodeEditorUserCache(tempPath);
229+
else
230+
canvasCache.SetCachePath(tempPath);
231+
canvasCache.AssureCanvas();
232+
}
150233

151234
#endregion
152235

Runtime/Framework/Core/NodeCanvas.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,15 @@ public void UpdateSource (string path)
196196
}
197197
else
198198
{
199-
int nameStart = path.LastIndexOf ('/')+1;
199+
int nameStart = Mathf.Max(path.LastIndexOf ('/'), path.LastIndexOf ('\\'))+1;
200200
newName = path.Substring (nameStart, path.Length-nameStart-6);
201201
}
202-
if (!newName.ToLower ().Contains ("lastsession"))
202+
if (!newName.ToLower ().Contains ("lastsession") && !newName.ToLower ().Contains ("cursession"))
203203
{
204204
savePath = path;
205205
saveName = newName;
206206
livesInScene = path.StartsWith ("SCENE/");
207207
}
208-
return;
209208
}
210209

211210
#endregion

Runtime/Framework/SaveSystem/NodeEditorUserCache.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ public NodeEditorUserCache(string CachePath)
6464
#endif
6565
}
6666

67+
/// <summary>
68+
/// Sets the cache path to a new location if cache is enabled. Does not check validity or moves files
69+
/// </summary>
70+
public void SetCachePath(string CachePath)
71+
{
72+
#if CACHE
73+
if (useCache)
74+
cachePath = CachePath;
75+
#endif
76+
}
77+
78+
/// <summary>
79+
/// Returns the cache path if cache is enabled, else an empty string
80+
/// </summary>
81+
public string GetCachePath()
82+
{
83+
#if CACHE
84+
if (useCache)
85+
return cachePath;
86+
#endif
87+
return "";
88+
}
89+
6790

6891
/// <summary>
6992
/// Assures a canvas is loaded, either from the cache or new

Runtime/Resources/Textures/NE_Button.png.meta

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Resources/Textures/NE_Button_Hover.png.meta

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Resources/Textures/NE_Button_Selected.png.meta

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Resources/Textures/NE_SelectedBG.png.meta

Lines changed: 19 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Resources/Textures/NE_Toolbar.png.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Resources/Textures/NE_ToolbarButton.png.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)