@@ -101,34 +101,37 @@ private static bool IsObjectUnlocked(Object selected)
101
101
private static void ContextMenu_Lock ( )
102
102
{
103
103
isBusy = true ;
104
- var selected = Selection . activeObject ;
105
104
106
105
var unlockedObjects = Selection . objects . Where ( IsObjectUnlocked ) . ToArray ( ) ;
107
- LockObject ( selected ) ;
106
+ var tasks = unlockedObjects . Select ( LockObject ) . ToArray ( ) ;
108
107
109
- isBusy = false ;
110
- Selection . activeGameObject = null ;
111
- EditorApplication . RepaintProjectWindow ( ) ;
108
+ var taskQueue = new TaskQueue ( ) ;
109
+ foreach ( var task in tasks )
110
+ {
111
+ taskQueue . Queue ( task ) ;
112
+ }
113
+
114
+ taskQueue . FinallyInUI ( ( success , exception ) =>
115
+ {
116
+ isBusy = false ;
117
+ Selection . activeGameObject = null ;
118
+ EditorApplication . RepaintProjectWindow ( ) ;
119
+ } ) . Start ( ) ;
112
120
}
113
121
114
- private static void LockObject ( Object selected )
122
+ private static ITask LockObject ( Object selected )
115
123
{
116
124
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
117
125
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
118
126
119
- Repository . RequestLock ( repositoryPath ) . FinallyInUI ( ( success , ex ) => {
120
- if ( success )
121
- {
122
- manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsLock , null ) ;
123
- }
124
- else
125
- {
126
- var error = ex . Message ;
127
- if ( error . Contains ( "exit status 255" ) )
128
- error = "Failed to unlock: no permissions" ;
129
- EditorUtility . DisplayDialog ( Localization . RequestLockActionTitle , error , Localization . Ok ) ;
130
- }
131
- } ) . Start ( ) ;
127
+ return Repository . RequestLock ( repositoryPath )
128
+ . FinallyInUI ( ( success , ex ) =>
129
+ {
130
+ if ( success )
131
+ {
132
+ manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsLock , null ) ;
133
+ }
134
+ } ) ;
132
135
}
133
136
134
137
[ MenuItem ( AssetsMenuReleaseLock , true , 1000 ) ]
@@ -160,15 +163,22 @@ private static bool IsObjectLocked(Object selected)
160
163
private static void ContextMenu_Unlock ( )
161
164
{
162
165
isBusy = true ;
163
- var selected = Selection . activeObject ;
164
166
165
167
var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
168
+ var tasks = lockedObjects . Select ( o => UnlockObject ( o , false ) ) . ToArray ( ) ;
166
169
167
- UnlockObject ( selected , false ) ;
170
+ var taskQueue = new TaskQueue ( ) ;
171
+ foreach ( var task in tasks )
172
+ {
173
+ taskQueue . Queue ( task ) ;
174
+ }
168
175
169
- isBusy = false ;
170
- Selection . activeGameObject = null ;
171
- EditorApplication . RepaintProjectWindow ( ) ;
176
+ taskQueue . FinallyInUI ( ( success , exception ) =>
177
+ {
178
+ isBusy = false ;
179
+ Selection . activeGameObject = null ;
180
+ EditorApplication . RepaintProjectWindow ( ) ;
181
+ } ) . Start ( ) ;
172
182
}
173
183
174
184
[ MenuItem ( AssetsMenuReleaseLockForced , true , 1000 ) ]
@@ -196,36 +206,37 @@ private static bool ContextMenu_CanUnlockForce()
196
206
private static void ContextMenu_UnlockForce ( )
197
207
{
198
208
isBusy = true ;
199
- var selected = Selection . activeObject ;
209
+
200
210
var lockedObjects = Selection . objects . Where ( IsObjectLocked ) . ToArray ( ) ;
211
+ var tasks = lockedObjects . Select ( o => UnlockObject ( o , true ) ) . ToArray ( ) ;
201
212
202
- UnlockObject ( selected , true ) ;
213
+ var taskQueue = new TaskQueue ( ) ;
214
+ foreach ( var task in tasks )
215
+ {
216
+ taskQueue . Queue ( task ) ;
217
+ }
203
218
204
- isBusy = false ;
205
- Selection . activeGameObject = null ;
206
- EditorApplication . RepaintProjectWindow ( ) ;
219
+ taskQueue . FinallyInUI ( ( success , exception ) =>
220
+ {
221
+ isBusy = false ;
222
+ Selection . activeGameObject = null ;
223
+ EditorApplication . RepaintProjectWindow ( ) ;
224
+ } ) . Start ( ) ;
207
225
}
208
226
209
- private static void UnlockObject ( Object selected , bool force )
227
+ private static ITask UnlockObject ( Object selected , bool force )
210
228
{
211
229
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
212
230
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
213
231
214
- Repository . ReleaseLock ( repositoryPath , force )
232
+ return Repository . ReleaseLock ( repositoryPath , force )
215
233
. FinallyInUI ( ( success , ex ) =>
216
234
{
217
235
if ( success )
218
236
{
219
237
manager . TaskManager . Run ( manager . UsageTracker . IncrementUnityProjectViewContextLfsUnlock , null ) ;
220
238
}
221
- else
222
- {
223
- var error = ex . Message ;
224
- if ( error . Contains ( "exit status 255" ) )
225
- error = "Failed to unlock: no permissions" ;
226
- EditorUtility . DisplayDialog ( Localization . ReleaseLockActionTitle , error , Localization . Ok ) ;
227
- }
228
- } ) . Start ( ) ;
239
+ } ) ;
229
240
}
230
241
231
242
private static void OnLocksUpdate ( )
0 commit comments