@@ -10,20 +10,34 @@ namespace GitHub.Unity
10
10
sealed class LocationAttribute : Attribute
11
11
{
12
12
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
+
14
36
public LocationAttribute ( string relativePath , Location location )
15
37
{
16
38
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 ;
27
41
}
28
42
}
29
43
@@ -99,7 +113,7 @@ protected virtual void Save(bool saveAsText)
99
113
100
114
if ( attr == null )
101
115
return null ;
102
- return attr . filepath . ToNPath ( ) ;
116
+ return attr . FilePath . ToNPath ( ) ;
103
117
}
104
118
}
105
119
}
0 commit comments