Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 05f7e95

Browse files
Merge pull request #991 from github-for-unity/fixes/990-grumble-mumble
It is not safe to instantiate scriptable objects in attribute constructors in 2018.3
2 parents 1cfcaad + 7f2e7d7 commit 05f7e95

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/ScriptObjectSingleton.cs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,34 @@ namespace GitHub.Unity
1010
sealed class LocationAttribute : Attribute
1111
{
1212
public enum Location { PreferencesFolder, ProjectFolder, LibraryFolder, UserFolder }
13-
public string filepath { get; set; }
13+
14+
private string relativePath;
15+
private Location location;
16+
17+
private string filePath;
18+
public string FilePath {
19+
get {
20+
if (filePath != null) return filePath;
21+
22+
if (relativePath[0] == '/')
23+
relativePath = relativePath.Substring(1);
24+
25+
if (location == Location.PreferencesFolder)
26+
filePath = InternalEditorUtility.unityPreferencesFolder + "/" + relativePath;
27+
else if (location == Location.UserFolder)
28+
filePath = EntryPoint.ApplicationManager.Environment.UserCachePath.Combine(relativePath).ToString(SlashMode.Forward);
29+
else if (location == Location.LibraryFolder)
30+
filePath = EntryPoint.ApplicationManager.Environment.UnityProjectPath.Combine("Library", "gfu", relativePath);
31+
32+
return filePath;
33+
}
34+
}
35+
1436
public LocationAttribute(string relativePath, Location location)
1537
{
1638
Guard.ArgumentNotNullOrWhiteSpace(relativePath, "relativePath");
17-
18-
if (relativePath[0] == '/')
19-
relativePath = relativePath.Substring(1);
20-
21-
if (location == Location.PreferencesFolder)
22-
filepath = InternalEditorUtility.unityPreferencesFolder + "/" + relativePath;
23-
else if (location == Location.UserFolder)
24-
filepath = EntryPoint.ApplicationManager.Environment.UserCachePath.Combine(relativePath).ToString(SlashMode.Forward);
25-
else if (location == Location.LibraryFolder)
26-
filepath = EntryPoint.ApplicationManager.Environment.UnityProjectPath.Combine("Library", "gfu", relativePath);
39+
this.relativePath = relativePath;
40+
this.location = location;
2741
}
2842
}
2943

@@ -99,7 +113,7 @@ protected virtual void Save(bool saveAsText)
99113

100114
if (attr == null)
101115
return null;
102-
return attr.filepath.ToNPath();
116+
return attr.FilePath.ToNPath();
103117
}
104118
}
105119
}

0 commit comments

Comments
 (0)