6
6
using System . Collections . Generic ;
7
7
using System . IO ;
8
8
using System . Linq ;
9
- using UnityEditor . Scripting ;
10
9
using UnityEditorInternal ;
11
10
using UnityEditor . Scripting . ScriptCompilation ;
12
11
using UnityEditor . Experimental . AssetImporters ;
@@ -19,11 +18,28 @@ namespace UnityEditor
19
18
[ CanEditMultipleObjects ]
20
19
internal class AssemblyDefinitionImporterInspector : AssetImporterEditor
21
20
{
21
+ internal class Styles
22
+ {
23
+ public static readonly GUIContent name = EditorGUIUtility . TrTextContent ( "Name" ) ;
24
+ public static readonly GUIContent references = EditorGUIUtility . TrTextContent ( "References" ) ;
25
+ public static readonly GUIContent platforms = EditorGUIUtility . TrTextContent ( "Platforms" ) ;
26
+ public static readonly GUIContent anyPlatform = EditorGUIUtility . TrTextContent ( "Any Platform" ) ;
27
+ public static readonly GUIContent includePlatforms = EditorGUIUtility . TrTextContent ( "Include Platforms" ) ;
28
+ public static readonly GUIContent excludePlatforms = EditorGUIUtility . TrTextContent ( "Exclude Platforms" ) ;
29
+ public static readonly GUIContent selectAll = EditorGUIUtility . TrTextContent ( "Select all" ) ;
30
+ public static readonly GUIContent deselectAll = EditorGUIUtility . TrTextContent ( "Deselect all" ) ;
31
+ public static readonly GUIContent apply = EditorGUIUtility . TrTextContent ( "Apply" ) ;
32
+ public static readonly GUIContent revert = EditorGUIUtility . TrTextContent ( "Revert" ) ;
33
+ public static readonly GUIContent loadError = EditorGUIUtility . TrTextContent ( "Load error" ) ;
34
+ }
35
+
36
+ GUIStyle m_TextStyle ;
37
+
22
38
internal enum MixedBool : int
23
39
{
24
40
Mixed = - 1 ,
25
- True = 0 ,
26
- False = 1
41
+ False = 0 ,
42
+ True = 1
27
43
}
28
44
29
45
internal class AssemblyDefinitionReference
@@ -55,7 +71,6 @@ public string path
55
71
56
72
AssemblyDefintionState m_State ;
57
73
ReorderableList m_ReferencesList ;
58
- GUIStyle m_TextStyle ;
59
74
60
75
public override bool showImportedObject { get { return false ; } }
61
76
@@ -85,22 +100,22 @@ public override void OnInspectorGUI()
85
100
using ( new EditorGUI . DisabledScope ( true ) )
86
101
{
87
102
var value = string . Join ( ", " , m_TargetStates . Select ( t => t . name ) . ToArray ( ) ) ;
88
- EditorGUILayout . TextField ( "Name" , value , EditorStyles . textField ) ;
103
+ EditorGUILayout . TextField ( Styles . name , value , EditorStyles . textField ) ;
89
104
}
90
105
}
91
106
else
92
107
{
93
- m_State . name = EditorGUILayout . TextField ( "Name" , m_State . name , EditorStyles . textField ) ;
108
+ m_State . name = EditorGUILayout . TextField ( Styles . name , m_State . name , EditorStyles . textField ) ;
94
109
}
95
110
96
- GUILayout . Label ( "References" , EditorStyles . boldLabel ) ;
111
+ GUILayout . Label ( Styles . references , EditorStyles . boldLabel ) ;
97
112
m_ReferencesList . DoLayoutList ( ) ;
98
113
99
- GUILayout . Label ( "Platforms" , EditorStyles . boldLabel ) ;
114
+ GUILayout . Label ( Styles . platforms , EditorStyles . boldLabel ) ;
100
115
EditorGUILayout . BeginVertical ( GUI . skin . box ) ;
101
116
102
117
var compatibleWithAnyPlatform = m_State . compatibleWithAnyPlatform ;
103
- m_State . compatibleWithAnyPlatform = ToggleWithMixedValue ( "Any Platform" , m_State . compatibleWithAnyPlatform ) ;
118
+ m_State . compatibleWithAnyPlatform = ToggleWithMixedValue ( Styles . anyPlatform , m_State . compatibleWithAnyPlatform ) ;
104
119
105
120
if ( compatibleWithAnyPlatform == MixedBool . Mixed && m_State . compatibleWithAnyPlatform != MixedBool . Mixed )
106
121
{
@@ -120,25 +135,25 @@ public override void OnInspectorGUI()
120
135
121
136
if ( m_State . compatibleWithAnyPlatform != MixedBool . Mixed )
122
137
{
123
- GUILayout . Label ( m_State . compatibleWithAnyPlatform == MixedBool . False ? "Exclude Platforms" : "Include Platforms" , EditorStyles . boldLabel ) ;
138
+ GUILayout . Label ( m_State . compatibleWithAnyPlatform == MixedBool . True ? Styles . excludePlatforms : Styles . includePlatforms , EditorStyles . boldLabel ) ;
124
139
125
140
for ( int i = 0 ; i < platforms . Length ; ++ i )
126
141
{
127
- m_State . platformCompatibility [ i ] = ToggleWithMixedValue ( platforms [ i ] . DisplayName , m_State . platformCompatibility [ i ] ) ;
142
+ m_State . platformCompatibility [ i ] = ToggleWithMixedValue ( new GUIContent ( platforms [ i ] . DisplayName ) , m_State . platformCompatibility [ i ] ) ;
128
143
}
129
144
130
145
EditorGUILayout . Space ( ) ;
131
146
132
147
GUILayout . BeginHorizontal ( ) ;
133
148
134
- if ( GUILayout . Button ( "Select all" ) )
149
+ if ( GUILayout . Button ( Styles . selectAll ) )
135
150
{
136
- SetPlatformCompatibility ( m_State , MixedBool . False ) ;
151
+ SetPlatformCompatibility ( m_State , MixedBool . True ) ;
137
152
}
138
153
139
- if ( GUILayout . Button ( "Deselect all" ) )
154
+ if ( GUILayout . Button ( Styles . deselectAll ) )
140
155
{
141
- SetPlatformCompatibility ( m_State , MixedBool . True ) ;
156
+ SetPlatformCompatibility ( m_State , MixedBool . False ) ;
142
157
}
143
158
144
159
GUILayout . FlexibleSpace ( ) ;
@@ -159,12 +174,12 @@ public override void OnInspectorGUI()
159
174
160
175
using ( new EditorGUI . DisabledScope ( ! m_State . modified ) )
161
176
{
162
- if ( GUILayout . Button ( "Revert" ) )
177
+ if ( GUILayout . Button ( Styles . revert ) )
163
178
{
164
179
LoadAssemblyDefinitionFiles ( ) ;
165
180
}
166
181
167
- if ( GUILayout . Button ( "Apply" ) )
182
+ if ( GUILayout . Button ( Styles . apply ) )
168
183
{
169
184
SaveAndUpdateAssemblyDefinitionStates ( m_State , m_TargetStates ) ;
170
185
}
@@ -208,15 +223,15 @@ static void UpdatePlatformCompatibility(MixedBool compatibleWithAnyPlatform, Ass
208
223
}
209
224
}
210
225
211
- static MixedBool ToggleWithMixedValue ( string title , MixedBool value )
226
+ static MixedBool ToggleWithMixedValue ( GUIContent title , MixedBool value )
212
227
{
213
228
EditorGUI . showMixedValue = value == MixedBool . Mixed ;
214
229
215
230
EditorGUI . BeginChangeCheck ( ) ;
216
231
217
- bool newBoolValue = EditorGUILayout . Toggle ( title , value == MixedBool . False ) ;
232
+ bool newBoolValue = EditorGUILayout . Toggle ( title , value == MixedBool . True ) ;
218
233
if ( EditorGUI . EndChangeCheck ( ) )
219
- return newBoolValue ? MixedBool . False : MixedBool . True ;
234
+ return newBoolValue ? MixedBool . True : MixedBool . False ;
220
235
221
236
EditorGUI . showMixedValue = false ;
222
237
return value ;
@@ -240,12 +255,12 @@ static void SetPlatformCompatibility(AssemblyDefintionState state, MixedBool com
240
255
241
256
static MixedBool InverseCompability ( MixedBool compatibility )
242
257
{
243
- if ( compatibility == MixedBool . False )
244
- return MixedBool . True ;
245
-
246
258
if ( compatibility == MixedBool . True )
247
259
return MixedBool . False ;
248
260
261
+ if ( compatibility == MixedBool . False )
262
+ return MixedBool . True ;
263
+
249
264
return MixedBool . Mixed ;
250
265
}
251
266
@@ -254,7 +269,7 @@ void ShowLoadErrorExceptionGUI(Exception e)
254
269
if ( m_TextStyle == null )
255
270
m_TextStyle = "ScriptText" ;
256
271
257
- GUILayout . Label ( "Load Error" , EditorStyles . boldLabel ) ;
272
+ GUILayout . Label ( Styles . loadError , EditorStyles . boldLabel ) ;
258
273
Rect rect = GUILayoutUtility . GetRect ( EditorGUIUtility . TempContent ( e . Message ) , m_TextStyle ) ;
259
274
EditorGUI . HelpBox ( rect , e . Message , MessageType . Error ) ;
260
275
}
@@ -383,7 +398,7 @@ static AssemblyDefintionState LoadAssemblyDefintionState(string path)
383
398
throw new AssemblyDefinitionException ( string . Format ( "Reference assembly definition file '{0}' not found" , referencePath ) , path ) ;
384
399
385
400
assemblyDefinitionFile . data = CustomScriptAssemblyData . FromJson ( assemblyDefinitionFile . asset . text ) ;
386
- assemblyDefinitionFile . displayValue = MixedBool . True ;
401
+ assemblyDefinitionFile . displayValue = MixedBool . False ;
387
402
state . references . Add ( assemblyDefinitionFile ) ;
388
403
}
389
404
catch ( AssemblyDefinitionException e )
@@ -398,25 +413,25 @@ static AssemblyDefintionState LoadAssemblyDefintionState(string path)
398
413
var platforms = Compilation . CompilationPipeline . GetAssemblyDefinitionPlatforms ( ) ;
399
414
state . platformCompatibility = new MixedBool [ platforms . Length ] ;
400
415
401
- state . compatibleWithAnyPlatform = MixedBool . False ;
416
+ state . compatibleWithAnyPlatform = MixedBool . True ;
402
417
string [ ] dataPlatforms = null ;
403
418
404
419
if ( data . includePlatforms != null && data . includePlatforms . Length > 0 )
405
420
{
406
- state . compatibleWithAnyPlatform = MixedBool . True ;
421
+ state . compatibleWithAnyPlatform = MixedBool . False ;
407
422
dataPlatforms = data . includePlatforms ;
408
423
}
409
424
else if ( data . excludePlatforms != null && data . excludePlatforms . Length > 0 )
410
425
{
411
- state . compatibleWithAnyPlatform = MixedBool . False ;
426
+ state . compatibleWithAnyPlatform = MixedBool . True ;
412
427
dataPlatforms = data . excludePlatforms ;
413
428
}
414
429
415
430
if ( dataPlatforms != null )
416
431
foreach ( var platform in dataPlatforms )
417
432
{
418
433
var platformIndex = GetPlatformIndex ( platforms , platform ) ;
419
- state . platformCompatibility [ platformIndex ] = MixedBool . False ;
434
+ state . platformCompatibility [ platformIndex ] = MixedBool . True ;
420
435
}
421
436
422
437
return state ;
@@ -486,13 +501,13 @@ static void SaveAssemblyDefinitionState(AssemblyDefintionState state)
486
501
487
502
for ( int i = 0 ; i < platforms . Length ; ++ i )
488
503
{
489
- if ( state . platformCompatibility [ i ] == MixedBool . False )
504
+ if ( state . platformCompatibility [ i ] == MixedBool . True )
490
505
dataPlatforms . Add ( platforms [ i ] . Name ) ;
491
506
}
492
507
493
508
if ( dataPlatforms . Any ( ) )
494
509
{
495
- if ( state . compatibleWithAnyPlatform == MixedBool . False )
510
+ if ( state . compatibleWithAnyPlatform == MixedBool . True )
496
511
data . excludePlatforms = dataPlatforms . ToArray ( ) ;
497
512
else
498
513
data . includePlatforms = dataPlatforms . ToArray ( ) ;
0 commit comments