2
2
using System . Collections ;
3
3
using System . Collections . Generic ;
4
4
using UnityEditor ;
5
+ using UnityEditor . EditorTools ;
5
6
using UnityEngine ;
6
7
7
8
namespace Wanderer . GameFramework
@@ -13,8 +14,261 @@ public class AssetGroupEditor:EditorWindow
13
14
private JsonData _newData ;
14
15
private JsonData _selectFoldersJsonData ;
15
16
private Vector2 _scrollView = Vector2 . zero ;
17
+ private string [ ] _assetFilter ;
16
18
17
19
18
- }
20
+ [ MenuItem ( "Tools/Assets Management/Asset Group #&G" ) ]
21
+ private static void OpenWindow ( )
22
+ {
23
+ GetWindow < AssetGroupEditor > ( "Asset Group Editor" ) ;
24
+ }
25
+
26
+ private void OnEnable ( )
27
+ {
28
+ _config = ProjectSettingsConfig . LoadJsonData ( _configName ) ;
29
+ if ( _config == null )
30
+ {
31
+ _config = new JsonData ( ) ;
32
+ _config . SetJsonType ( JsonType . Array ) ;
33
+ }
34
+ _newData = new JsonData ( ) ;
35
+
36
+ _assetFilter = AssetFilterEditor . GetAssetFilters ( ) . ToArray ( ) ;
37
+ }
38
+
39
+ private void OnDisable ( )
40
+ {
41
+ _config = null ;
42
+ _newData = null ;
43
+ }
44
+ List < int > linexs = new List < int > ( ) ;
45
+
46
+ private void OnGUI ( )
47
+ {
48
+ linexs . Clear ( ) ;
49
+
50
+ //Ö÷´°¿Ú
51
+ GUILayout . BeginHorizontal ( ) ;
52
+ GUILayout . FlexibleSpace ( ) ;
53
+ if ( GUILayout . Button ( "Apply" , GUILayout . Width ( 100 ) ) )
54
+ {
55
+ ProjectSettingsConfig . SaveJsonData ( _configName , _config ) ;
56
+ EditorUtility . DisplayDialog ( "Save Config" , "Data saved successfully!" , "OK" ) ;
57
+ }
58
+ GUILayout . EndHorizontal ( ) ;
59
+
60
+ _scrollView = GUILayout . BeginScrollView ( _scrollView ) ;
61
+
62
+ GUILayout . BeginHorizontal ( "box" , GUILayout . Width ( Screen . width ) ) ; //GUILayout.Width(100)
63
+ GUILayout . Label ( "Group Name" , GUILayout . Width ( 150 ) ) ;
64
+ Rect latRect = GUILayoutUtility . GetLastRect ( ) ;
65
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
66
+
67
+ GUILayout . Label ( "Annotation" , GUILayout . Width ( 100 ) ) ;
68
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
69
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
70
+
71
+ GUILayout . Label ( "Variant" , GUILayout . Width ( 100 ) ) ;
72
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
73
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
74
+
75
+ GUILayout . Label ( "Filter" , GUILayout . Width ( 100 ) ) ;
76
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
77
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
78
+
79
+ GUILayout . Label ( "Search In Folders" , GUILayout . Width ( 300 ) ) ;
80
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
81
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
82
+
83
+ GUILayout . Label ( "Split" , GUILayout . Width ( 100 ) ) ;
84
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
85
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
86
+
87
+ GUILayout . Label ( "Split Count" , GUILayout . Width ( 100 ) ) ;
88
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
89
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
90
+
91
+ GUILayout . Label ( "Force Update" , GUILayout . Width ( 100 ) ) ;
92
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
93
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
94
+
95
+ GUILayout . Label ( "Preload" ) ;
96
+ latRect = GUILayoutUtility . GetLastRect ( ) ;
97
+ linexs . Add ( ( int ) ( latRect . x + latRect . width ) ) ;
98
+
99
+ GUILayout . EndHorizontal ( ) ;
100
+
101
+ int configCount = _config . Count ;
102
+ if ( configCount > 0 )
103
+ {
104
+ for ( int i = 0 ; i < configCount ; i ++ )
105
+ {
106
+ GUILayout . BeginHorizontal ( "box" , GUILayout . Width ( Screen . width ) ) ;
107
+ DrawJsonData ( _config [ i ] ) ;
108
+ if ( GUILayout . Button ( "-" , GUILayout . Width ( 30 ) ) )
109
+ {
110
+ _config . Remove ( _config [ i ] ) ;
111
+ GUIUtility . ExitGUI ( ) ;
112
+ }
113
+ GUILayout . EndHorizontal ( ) ;
114
+ }
115
+ }
116
+
117
+ foreach ( var item in linexs )
118
+ {
119
+ Rect lineRect = new Rect ( item , 0 , 1 , Screen . height ) ;
120
+ EditorGUI . DrawRect ( lineRect , new Color ( 0.2196079f , 0.2196079f , 0.2196079f , 1.0f ) * 1.5f ) ;
121
+ }
122
+
123
+ GUILayout . EndScrollView ( ) ;
124
+
125
+
126
+ GUILayout . BeginHorizontal ( "box" , GUILayout . Width ( Screen . width ) ) ;
127
+ DrawJsonData ( _newData ) ;
128
+ if ( GUILayout . Button ( "+" , GUILayout . Width ( 30 ) ) )
129
+ {
130
+ bool addResult = false ;
131
+ if ( _newData . Keys . Count > 0 )
132
+ {
133
+ JsonData selectFoldersJsonData = _newData [ "SearchInFolders" ] ;
134
+ if ( selectFoldersJsonData != null && selectFoldersJsonData . Count > 0 )
135
+ {
136
+ _config . Add ( _newData ) ;
137
+ _newData = new JsonData ( ) ;
138
+ addResult = true ;
139
+ }
140
+ }
141
+
142
+ if ( ! addResult )
143
+ {
144
+ EditorUtility . DisplayDialog ( "Tips" , "The search folder cannot be empty!" , "OK" ) ;
145
+ }
146
+
147
+ }
148
+ GUILayout . EndHorizontal ( ) ;
149
+
150
+
151
+
152
+ }
153
+
154
+ //»æÖÆjsondata
155
+ private void DrawJsonData ( JsonData jsonData )
156
+ {
157
+ string key = "AssetBundleName" ;
158
+ if ( ! jsonData . Keys . Contains ( key ) )
159
+ {
160
+ jsonData [ key ] = "Game" ;
161
+ }
162
+ string content = jsonData [ key ] . ToString ( ) ;
163
+ string newContent = EditorGUILayout . TextField ( content , GUILayout . Width ( 150 ) ) ;
164
+ if ( ! content . Equals ( newContent ) )
165
+ {
166
+ jsonData [ key ] = newContent ;
167
+ }
168
+
169
+ key = "Annotation" ;
170
+ if ( ! jsonData . Keys . Contains ( key ) )
171
+ {
172
+ jsonData [ key ] = "" ;
173
+ }
174
+ content = jsonData [ key ] . ToString ( ) ;
175
+ newContent = EditorGUILayout . TextField ( content , GUILayout . Width ( 100 ) ) ;
176
+ if ( ! content . Equals ( newContent ) )
177
+ {
178
+ jsonData [ key ] = newContent ;
179
+ }
180
+
181
+ key = "Variant" ;
182
+ if ( ! jsonData . Keys . Contains ( key ) )
183
+ {
184
+ jsonData [ key ] = "" ;
185
+ }
186
+ content = jsonData [ key ] . ToString ( ) ;
187
+ newContent = EditorGUILayout . TextField ( content , GUILayout . Width ( 100 ) ) ;
188
+ if ( ! content . Equals ( newContent ) )
189
+ {
190
+ jsonData [ key ] = newContent ;
191
+ }
192
+
193
+ key = "Filter" ;
194
+ if ( ! jsonData . Keys . Contains ( key ) )
195
+ {
196
+ jsonData [ key ] = 1024 ;
197
+ }
198
+ int filter = ( int ) jsonData [ key ] ;
199
+ int newFilter = EditorGUILayout . MaskField ( filter , _assetFilter , GUILayout . Width ( 100 ) ) ;
200
+ if ( filter != newFilter )
201
+ {
202
+ jsonData [ key ] = newFilter ;
203
+ }
204
+
205
+ key = "SearchInFolders" ;
206
+ if ( ! jsonData . Keys . Contains ( key ) )
207
+ {
208
+ jsonData [ key ] = new JsonData ( ) ;
209
+ jsonData [ key ] . SetJsonType ( JsonType . Array ) ;
210
+ }
211
+ JsonData selectFoldersJsonData = jsonData [ key ] ;
212
+ content = selectFoldersJsonData . ToJson ( ) ;
213
+ newContent = EditorGUILayout . TextField ( content , GUILayout . Width ( 300 ) ) ;
214
+ if ( ! content . Equals ( newContent ) )
215
+ {
216
+ var jd = JsonMapper . ToObject ( newContent ) ;
217
+ if ( jd != null )
218
+ {
219
+ jsonData [ key ] = jd ;
220
+ }
221
+ }
222
+ key = "Split" ;
223
+ if ( ! jsonData . Keys . Contains ( key ) )
224
+ {
225
+ jsonData [ key ] = false ;
226
+ }
227
+ bool isSplit = ( bool ) jsonData [ key ] ;
228
+ bool newIsSplit = EditorGUILayout . Toggle ( isSplit , GUILayout . Width ( 100 ) ) ;
229
+ if ( isSplit != newIsSplit )
230
+ {
231
+ jsonData [ key ] = newIsSplit ;
232
+ }
233
+
234
+ key = "SplitCount" ;
235
+ if ( ! jsonData . Keys . Contains ( key ) )
236
+ {
237
+ jsonData [ key ] = 1 ;
238
+ }
239
+ int splitCount = ( int ) jsonData [ key ] ;
240
+ int newSplitCount = EditorGUILayout . IntField ( splitCount , GUILayout . Width ( 100 ) ) ;
241
+ if ( splitCount != newSplitCount )
242
+ {
243
+ jsonData [ key ] = newSplitCount ;
244
+ }
245
+
246
+ key = "ForceUpdate" ;
247
+ if ( ! jsonData . Keys . Contains ( key ) )
248
+ {
249
+ jsonData [ key ] = true ;
250
+ }
251
+ bool forceUpdate = ( bool ) jsonData [ key ] ;
252
+ bool newForceUpdate = EditorGUILayout . Toggle ( forceUpdate , GUILayout . Width ( 110 ) ) ;
253
+ if ( forceUpdate != newForceUpdate )
254
+ {
255
+ jsonData [ key ] = newForceUpdate ;
256
+ }
257
+
258
+ key = "Preload" ;
259
+ if ( ! jsonData . Keys . Contains ( key ) )
260
+ {
261
+ jsonData [ key ] = false ;
262
+ }
263
+ bool preloadUpdate = ( bool ) jsonData [ key ] ;
264
+ bool newPreloadUpdate = EditorGUILayout . Toggle ( preloadUpdate , GUILayout . Width ( 70 ) ) ;
265
+ if ( preloadUpdate != newPreloadUpdate )
266
+ {
267
+ jsonData [ key ] = newPreloadUpdate ;
268
+ }
269
+ }
270
+
271
+
272
+ }
19
273
20
274
}
0 commit comments