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

It is not safe to instantiate scriptable objects in attribute constructors in 2018.3 #991

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,34 @@ namespace GitHub.Unity
sealed class LocationAttribute : Attribute
{
public enum Location { PreferencesFolder, ProjectFolder, LibraryFolder, UserFolder }
public string filepath { get; set; }

private string relativePath;
private Location location;

private string filePath;
public string FilePath {
get {
if (filePath != null) return filePath;

if (relativePath[0] == '/')
relativePath = relativePath.Substring(1);

if (location == Location.PreferencesFolder)
filePath = InternalEditorUtility.unityPreferencesFolder + "/" + relativePath;
else if (location == Location.UserFolder)
filePath = EntryPoint.ApplicationManager.Environment.UserCachePath.Combine(relativePath).ToString(SlashMode.Forward);
else if (location == Location.LibraryFolder)
filePath = EntryPoint.ApplicationManager.Environment.UnityProjectPath.Combine("Library", "gfu", relativePath);

return filePath;
}
}

public LocationAttribute(string relativePath, Location location)
{
Guard.ArgumentNotNullOrWhiteSpace(relativePath, "relativePath");

if (relativePath[0] == '/')
relativePath = relativePath.Substring(1);

if (location == Location.PreferencesFolder)
filepath = InternalEditorUtility.unityPreferencesFolder + "/" + relativePath;
else if (location == Location.UserFolder)
filepath = EntryPoint.ApplicationManager.Environment.UserCachePath.Combine(relativePath).ToString(SlashMode.Forward);
else if (location == Location.LibraryFolder)
filepath = EntryPoint.ApplicationManager.Environment.UnityProjectPath.Combine("Library", "gfu", relativePath);
this.relativePath = relativePath;
this.location = location;
}
}

Expand Down Expand Up @@ -99,7 +113,7 @@ protected virtual void Save(bool saveAsText)

if (attr == null)
return null;
return attr.filepath.ToNPath();
return attr.FilePath.ToNPath();
}
}
}