@@ -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