@@ -2154,6 +2154,9 @@ private string LibraryPrefix {
2154
2154
// Path of the file that indicates whether the asset database is currently being refreshed
2155
2155
// due to this module.
2156
2156
private const string REFRESH_PATH = "Temp/VersionHandlerImplRefresh" ;
2157
+ // Path of the file that indicates whether files need to be cleaned up after an asset database
2158
+ // refresh.
2159
+ private const string CLEANUP_FILES_PENDING_PATH = "Temp/VersionHandlerImplCleanupFilesPending" ;
2157
2160
2158
2161
// Whether compilation is currently occuring.
2159
2162
private static bool compiling = false ;
@@ -2231,6 +2234,26 @@ private static bool Refreshing {
2231
2234
}
2232
2235
}
2233
2236
2237
+ /// <summary>
2238
+ /// Whether files need to be cleaned up after an asset database refresh.
2239
+ /// </summary>
2240
+ private static bool CleanupFilesPending {
2241
+ get {
2242
+ return File . Exists ( CLEANUP_FILES_PENDING_PATH ) ;
2243
+ }
2244
+
2245
+ set {
2246
+ bool pending = CleanupFilesPending ;
2247
+ if ( pending != value ) {
2248
+ if ( value ) {
2249
+ File . WriteAllText ( CLEANUP_FILES_PENDING_PATH , "Cleanup files after refresh" ) ;
2250
+ } else {
2251
+ File . Delete ( CLEANUP_FILES_PENDING_PATH ) ;
2252
+ }
2253
+ }
2254
+ }
2255
+ }
2256
+
2234
2257
/// <summary>
2235
2258
/// Whether all editor DLLs have been loaded into the app domain.
2236
2259
/// </summary>
@@ -2289,7 +2312,16 @@ private static void NotifyWhenCompliationComplete(bool forceNotification) {
2289
2312
// If a refresh was initiated by this module, clear the refresh flag.
2290
2313
var wasRefreshing = Refreshing ;
2291
2314
Refreshing = false ;
2292
- if ( wasRefreshing || forceNotification ) NotifyUpdateCompleteMethods ( ) ;
2315
+ if ( wasRefreshing || forceNotification ) {
2316
+ if ( CleanupFilesPending ) {
2317
+ CleanupFilesPending = false ;
2318
+ RunOnMainThread . Run ( ( ) => {
2319
+ UpdateVersionedAssetsOnMainThread ( false , ( ) => { } ,
2320
+ setCleanupFilesPending : false ) ;
2321
+ } , runNow : false ) ;
2322
+ }
2323
+ NotifyUpdateCompleteMethods ( ) ;
2324
+ }
2293
2325
return true ;
2294
2326
} ) ;
2295
2327
}
@@ -2638,8 +2670,9 @@ public static void UpdateVersionedAssets(bool forceUpdate) {
2638
2670
/// <param name="complete">Called when this is method is complete.</param>
2639
2671
public static void UpdateVersionedAssets ( bool forceUpdate , Action complete ) {
2640
2672
CancelUpdateVersionedAssets ( ) ;
2641
- RunOnMainThread . Run ( ( ) => { UpdateVersionedAssetsOnMainThread ( forceUpdate , complete ) ; } ,
2642
- runNow : false ) ;
2673
+ RunOnMainThread . Run ( ( ) => {
2674
+ UpdateVersionedAssetsOnMainThread ( forceUpdate , complete ) ; } ,
2675
+ runNow : false ) ;
2643
2676
}
2644
2677
2645
2678
/// <summary>
@@ -2650,7 +2683,11 @@ public static void UpdateVersionedAssets(bool forceUpdate, Action complete) {
2650
2683
/// </summary>
2651
2684
/// <param name="forceUpdate">Whether to force an update.</param>
2652
2685
/// <param name="complete">Called when this is method is complete.</param>
2653
- private static void UpdateVersionedAssetsOnMainThread ( bool forceUpdate , Action complete ) {
2686
+ /// <param name="setCleanupFilesPending">Whether to set the CleanupFilesPending flag to run
2687
+ /// this method again after an asset database refresh is complete.</param>
2688
+ private static void UpdateVersionedAssetsOnMainThread ( bool forceUpdate ,
2689
+ Action complete ,
2690
+ bool setCleanupFilesPending = true ) {
2654
2691
// If this module is disabled do nothing.
2655
2692
if ( ! forceUpdate && ! Enabled ) {
2656
2693
complete ( ) ;
@@ -2709,7 +2746,8 @@ private static void UpdateVersionedAssetsOnMainThread(bool forceUpdate, Action c
2709
2746
}
2710
2747
}
2711
2748
2712
- if ( cleanupFiles . Count > 0 && ! Refreshing ) {
2749
+ bool cleanupFilesPending = cleanupFiles . Count > 0 ;
2750
+ if ( cleanupFilesPending && ! Refreshing ) {
2713
2751
var window = MultiSelectWindow . CreateMultiSelectWindow ( PLUGIN_NAME ) ;
2714
2752
Action < string > logObsoleteFile = ( filename ) => {
2715
2753
Log ( "Leaving obsolete file: " + filename , verbose : true ) ;
@@ -2749,6 +2787,7 @@ private static void UpdateVersionedAssetsOnMainThread(bool forceUpdate, Action c
2749
2787
window . OnCancel = leaveFiles ;
2750
2788
window . Show ( ) ;
2751
2789
} else {
2790
+ if ( cleanupFilesPending && setCleanupFilesPending ) CleanupFilesPending = true ;
2752
2791
complete ( ) ;
2753
2792
}
2754
2793
0 commit comments