@@ -11,18 +11,20 @@ class ProjectWindowInterface : AssetPostprocessor
11
11
private const string AssetsMenuRequestLock = "Assets/Request Lock" ;
12
12
private const string AssetsMenuReleaseLock = "Assets/Release Lock" ;
13
13
private const string AssetsMenuReleaseLockForced = "Assets/Release Lock (forced)" ;
14
- private static readonly List < GitStatusEntry > entries = new List < GitStatusEntry > ( ) ;
14
+
15
+ private static List < GitStatusEntry > entries = new List < GitStatusEntry > ( ) ;
15
16
private static List < GitLock > locks = new List < GitLock > ( ) ;
17
+ private static List < string > guids = new List < string > ( ) ;
18
+ private static List < string > guidsLocks = new List < string > ( ) ;
16
19
17
- private static readonly List < string > guids = new List < string > ( ) ;
18
- private static readonly List < string > guidsLocks = new List < string > ( ) ;
19
20
private static IApplicationManager manager ;
20
21
private static bool isBusy = false ;
21
22
private static ILogging logger ;
22
23
private static ILogging Logger { get { return logger = logger ?? LogHelper . GetLogger < ProjectWindowInterface > ( ) ; } }
23
24
private static CacheUpdateEvent lastRepositoryStatusChangedEvent ;
24
25
private static CacheUpdateEvent lastLocksChangedEvent ;
25
- private static IRepository Repository { get { return manager . Environment . Repository ; } }
26
+ private static IRepository Repository { get { return manager != null ? manager . Environment . Repository : null ; } }
27
+ private static bool IsInitialized { get { return Repository != null && Repository . CurrentRemote . HasValue ; } }
26
28
27
29
public static void Initialize ( IApplicationManager theManager )
28
30
{
@@ -31,14 +33,27 @@ public static void Initialize(IApplicationManager theManager)
31
33
32
34
manager = theManager ;
33
35
34
- if ( Repository != null )
36
+ if ( IsInitialized )
35
37
{
36
38
Repository . StatusEntriesChanged += RepositoryOnStatusEntriesChanged ;
37
39
Repository . LocksChanged += RepositoryOnLocksChanged ;
38
40
ValidateCachedData ( ) ;
39
41
}
40
42
}
41
43
44
+ private static bool EnsureInitialized ( )
45
+ {
46
+ if ( locks == null )
47
+ locks = new List < GitLock > ( ) ;
48
+ if ( entries == null )
49
+ entries = new List < GitStatusEntry > ( ) ;
50
+ if ( guids == null )
51
+ guids = new List < string > ( ) ;
52
+ if ( guidsLocks == null )
53
+ guidsLocks = new List < string > ( ) ;
54
+ return IsInitialized ;
55
+ }
56
+
42
57
private static void ValidateCachedData ( )
43
58
{
44
59
Repository . CheckAndRaiseEventsIfCacheNewer ( CacheType . GitStatus , lastRepositoryStatusChangedEvent ) ;
@@ -69,16 +84,14 @@ private static void RepositoryOnLocksChanged(CacheUpdateEvent cacheUpdateEvent)
69
84
[ MenuItem ( AssetsMenuRequestLock , true ) ]
70
85
private static bool ContextMenu_CanLock ( )
71
86
{
72
- if ( isBusy )
87
+ if ( ! EnsureInitialized ( ) )
73
88
return false ;
74
- if ( Repository == null || ! Repository . CurrentRemote . HasValue )
89
+ if ( isBusy )
75
90
return false ;
76
91
77
92
var selected = Selection . activeObject ;
78
93
if ( selected == null )
79
94
return false ;
80
- if ( locks == null )
81
- return false ;
82
95
83
96
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
84
97
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
@@ -113,7 +126,7 @@ private static void ContextMenu_Lock()
113
126
{
114
127
var error = ex . Message ;
115
128
if ( error . Contains ( "exit status 255" ) )
116
- error = "Failed to unlock : no permissions" ;
129
+ error = "Failed to lock : no permissions" ;
117
130
EditorUtility . DisplayDialog ( Localization . RequestLockActionTitle ,
118
131
error ,
119
132
Localization . Ok ) ;
@@ -129,22 +142,19 @@ private static void ContextMenu_Lock()
129
142
[ MenuItem ( AssetsMenuReleaseLock , true , 1000 ) ]
130
143
private static bool ContextMenu_CanUnlock ( )
131
144
{
132
- if ( isBusy )
145
+ if ( ! EnsureInitialized ( ) )
133
146
return false ;
134
- if ( Repository == null || ! Repository . CurrentRemote . HasValue )
147
+ if ( isBusy )
135
148
return false ;
136
149
137
150
var selected = Selection . activeObject ;
138
151
if ( selected == null )
139
152
return false ;
140
- if ( locks == null || locks . Count == 0 )
141
- return false ;
142
153
143
154
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
144
155
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
145
156
146
- var isLocked = locks . Any ( x => repositoryPath == x . Path ) ;
147
- return isLocked ;
157
+ return locks . Any ( x => repositoryPath == x . Path ) ;
148
158
}
149
159
150
160
[ MenuItem ( AssetsMenuReleaseLock , false , 1000 ) ]
@@ -184,22 +194,19 @@ private static void ContextMenu_Unlock()
184
194
[ MenuItem ( AssetsMenuReleaseLockForced , true , 1000 ) ]
185
195
private static bool ContextMenu_CanUnlockForce ( )
186
196
{
187
- if ( isBusy )
197
+ if ( ! EnsureInitialized ( ) )
188
198
return false ;
189
- if ( Repository == null || ! Repository . CurrentRemote . HasValue )
199
+ if ( isBusy )
190
200
return false ;
191
201
192
202
var selected = Selection . activeObject ;
193
203
if ( selected == null )
194
204
return false ;
195
- if ( locks == null || locks . Count == 0 )
196
- return false ;
197
205
198
206
NPath assetPath = AssetDatabase . GetAssetPath ( selected . GetInstanceID ( ) ) . ToNPath ( ) ;
199
207
NPath repositoryPath = manager . Environment . GetRepositoryPath ( assetPath ) ;
200
208
201
- var isLocked = locks . Any ( x => repositoryPath == x . Path ) ;
202
- return isLocked ;
209
+ return locks . Any ( x => repositoryPath == x . Path ) ;
203
210
}
204
211
205
212
[ MenuItem ( AssetsMenuReleaseLockForced , false , 1000 ) ]
@@ -238,12 +245,6 @@ private static void ContextMenu_UnlockForce()
238
245
239
246
private static void OnLocksUpdate ( )
240
247
{
241
- if ( locks == null )
242
- {
243
- return ;
244
- }
245
- locks = locks . ToList ( ) ;
246
-
247
248
guidsLocks . Clear ( ) ;
248
249
foreach ( var lck in locks )
249
250
{
@@ -272,6 +273,9 @@ private static void OnStatusUpdate()
272
273
273
274
private static void OnProjectWindowItemGUI ( string guid , Rect itemRect )
274
275
{
276
+ if ( ! EnsureInitialized ( ) )
277
+ return ;
278
+
275
279
if ( Event . current . type != EventType . Repaint || string . IsNullOrEmpty ( guid ) )
276
280
{
277
281
return ;
0 commit comments