1
- using OxGFrame . AssetLoader . Bundle ;
1
+ using Cysharp . Threading . Tasks ;
2
+ using Newtonsoft . Json ;
3
+ using OxGFrame . AssetLoader . Bundle ;
2
4
using System ;
5
+ using System . Collections . Generic ;
6
+ using System . IO ;
3
7
using System . Linq ;
4
8
using UnityEditor ;
5
9
using UnityEngine ;
@@ -24,6 +28,15 @@ internal static BundleUrlConfigGeneratorWindow GetInstance()
24
28
[ SerializeField ]
25
29
public bool autoReveal ;
26
30
31
+ // Preset Plan
32
+ public List < BundleUrlPlan > bundleUrlPlans = new List < BundleUrlPlan > ( ) ;
33
+ private int _choicePlanIndex = 0 ;
34
+
35
+ private Vector2 _scrollview ;
36
+
37
+ private SerializedObject _serObj ;
38
+ private SerializedProperty _bundleUrlPlansPty ;
39
+
27
40
internal static string projectPath ;
28
41
internal static string keySaver ;
29
42
@@ -43,11 +56,19 @@ public static void ShowWindow()
43
56
44
57
private void OnEnable ( )
45
58
{
59
+ this . _serObj = new SerializedObject ( this ) ;
60
+ this . _bundleUrlPlansPty = this . _serObj . FindProperty ( "bundleUrlPlans" ) ;
61
+
46
62
this . bundleIp = EditorStorage . GetData ( keySaver , "bundleIp" , "127.0.0.1" ) ;
47
63
this . bundleFallbackIp = EditorStorage . GetData ( keySaver , "bundleFallbackIp" , "127.0.0.1" ) ;
48
64
this . storeLink = EditorStorage . GetData ( keySaver , "storeLink" , "http://" ) ;
49
65
50
66
this . autoReveal = Convert . ToBoolean ( EditorStorage . GetData ( keySaver , "autoReveal" , "true" ) ) ;
67
+
68
+ // Preset Bundle Url Plans
69
+ string jsonBundleUrlPlans = EditorStorage . GetData ( keySaver , "bundleUrlPlans" , string . Empty ) ;
70
+ if ( ! string . IsNullOrEmpty ( jsonBundleUrlPlans ) ) this . bundleUrlPlans = JsonConvert . DeserializeObject < List < BundleUrlPlan > > ( jsonBundleUrlPlans ) ;
71
+ this . _choicePlanIndex = Convert . ToInt32 ( EditorStorage . GetData ( keySaver , "_choicePlanIndex" , "0" ) ) ;
51
72
}
52
73
53
74
private void OnGUI ( )
@@ -56,6 +77,7 @@ private void OnGUI()
56
77
EditorGUI . BeginChangeCheck ( ) ;
57
78
58
79
this . _DrawExportBundleUrlConfigToStreamingAssetsView ( ) ;
80
+ this . _DrawBundleUrlPlansView ( ) ;
59
81
}
60
82
61
83
private void _DrawExportBundleUrlConfigToStreamingAssetsView ( )
@@ -164,5 +186,206 @@ private void _DrawProcessButtonView()
164
186
GUI . backgroundColor = bc ;
165
187
EditorGUILayout . EndHorizontal ( ) ;
166
188
}
189
+
190
+ #region Preset Bundle Plans
191
+ private void _DrawBundleUrlPlansView ( )
192
+ {
193
+ this . _scrollview = EditorGUILayout . BeginScrollView ( this . _scrollview , true , true ) ;
194
+
195
+ EditorGUILayout . Space ( ) ;
196
+
197
+ GUIStyle style = new GUIStyle ( ) ;
198
+ var bg = new Texture2D ( 1 , 1 ) ;
199
+ ColorUtility . TryParseHtmlString ( "#263840" , out Color color ) ;
200
+ Color [ ] pixels = Enumerable . Repeat ( color , Screen . width * Screen . height ) . ToArray ( ) ;
201
+ bg . SetPixels ( pixels ) ;
202
+ bg . Apply ( ) ;
203
+ style . normal . background = bg ;
204
+ EditorGUILayout . BeginVertical ( style ) ;
205
+
206
+ var centeredStyle = new GUIStyle ( GUI . skin . GetStyle ( "Label" ) ) ;
207
+ centeredStyle . alignment = TextAnchor . UpperCenter ;
208
+ GUILayout . Label ( new GUIContent ( "Preset Bundle Url Plans" ) , centeredStyle ) ;
209
+ EditorGUILayout . Space ( ) ;
210
+
211
+ EditorGUILayout . BeginHorizontal ( ) ;
212
+ // Add popup selection
213
+ List < string > planNames = new List < string > ( ) ;
214
+ if ( this . bundleUrlPlans . Count > 0 )
215
+ {
216
+ foreach ( var bundleUrlPlan in this . bundleUrlPlans )
217
+ {
218
+ planNames . Add ( bundleUrlPlan . planName ) ;
219
+ }
220
+ }
221
+ EditorGUI . BeginChangeCheck ( ) ;
222
+ this . _choicePlanIndex = EditorGUILayout . Popup ( "Plan Selection" , this . _choicePlanIndex , planNames . ToArray ( ) ) ;
223
+ if ( this . _choicePlanIndex < 0 ) this . _choicePlanIndex = 0 ;
224
+ if ( EditorGUI . EndChangeCheck ( ) )
225
+ {
226
+ EditorStorage . SaveData ( keySaver , "_choicePlanIndex" , this . _choicePlanIndex . ToString ( ) ) ;
227
+ }
228
+
229
+ // Load selection button
230
+ Color bc = GUI . backgroundColor ;
231
+ GUI . backgroundColor = new Color32 ( 83 , 152 , 255 , 255 ) ;
232
+ if ( GUILayout . Button ( "Copy Current" , GUILayout . MaxWidth ( 100f ) ) )
233
+ {
234
+ bool confirmation = EditorUtility . DisplayDialog
235
+ (
236
+ $ "Copy Current Notification",
237
+ $ "The plan selection is [{ this . bundleUrlPlans [ this . _choicePlanIndex ] . planName } ]\n Do you want to copy current all values?",
238
+ "copy current and override" ,
239
+ "cancel"
240
+ ) ;
241
+
242
+ if ( confirmation ) this . _CopyCurrentToBundleUrlPlan ( ) ;
243
+ }
244
+ GUI . backgroundColor = bc ;
245
+ bc = GUI . backgroundColor ;
246
+ GUI . backgroundColor = new Color32 ( 0 , 255 , 128 , 255 ) ;
247
+ if ( GUILayout . Button ( "Load Plan" , GUILayout . MaxWidth ( 100f ) ) )
248
+ {
249
+ this . _LoadBundleUrlPlanToCurrent ( ) ;
250
+ }
251
+ GUI . backgroundColor = bc ;
252
+ EditorGUILayout . EndHorizontal ( ) ;
253
+
254
+ EditorGUILayout . Space ( ) ;
255
+
256
+ EditorGUILayout . BeginHorizontal ( ) ;
257
+ this . _serObj . Update ( ) ;
258
+ EditorGUI . BeginChangeCheck ( ) ;
259
+ EditorGUILayout . PropertyField ( this . _bundleUrlPlansPty , true ) ;
260
+ if ( EditorGUI . EndChangeCheck ( ) )
261
+ {
262
+ this . _serObj . ApplyModifiedProperties ( ) ;
263
+ string json = JsonConvert . SerializeObject ( this . bundleUrlPlans ) ;
264
+ EditorStorage . SaveData ( keySaver , "bundleUrlPlans" , json ) ;
265
+ }
266
+
267
+ bc = GUI . backgroundColor ;
268
+ GUI . backgroundColor = new Color32 ( 255 , 151 , 240 , 255 ) ;
269
+ if ( GUILayout . Button ( "Reset" , GUILayout . MaxWidth ( 100f ) ) )
270
+ {
271
+ bool confirmation = EditorUtility . DisplayDialog
272
+ (
273
+ $ "Reset Bundle Url Plans Notification",
274
+ $ "Do you want to reset bundle url plans?",
275
+ "reset" ,
276
+ "cancel"
277
+ ) ;
278
+
279
+ if ( confirmation )
280
+ {
281
+ // Reset bundle plans
282
+ this . bundleUrlPlans = new List < BundleUrlPlan > ( ) { new BundleUrlPlan ( ) } ;
283
+ string json = JsonConvert . SerializeObject ( this . bundleUrlPlans ) ;
284
+ EditorStorage . SaveData ( keySaver , "bundleUrlPlans" , json ) ;
285
+
286
+ // Reset index
287
+ this . _choicePlanIndex = 0 ;
288
+ EditorStorage . SaveData ( keySaver , "_choicePlanIndex" , this . _choicePlanIndex . ToString ( ) ) ;
289
+ }
290
+ }
291
+ GUI . backgroundColor = bc ;
292
+ EditorGUILayout . EndHorizontal ( ) ;
293
+
294
+ EditorGUILayout . Space ( ) ;
295
+
296
+ EditorGUILayout . BeginHorizontal ( ) ;
297
+ GUILayout . FlexibleSpace ( ) ;
298
+ // Save File
299
+ bc = GUI . backgroundColor ;
300
+ GUI . backgroundColor = new Color32 ( 255 , 220 , 0 , 255 ) ;
301
+ if ( GUILayout . Button ( "Save File" , GUILayout . MaxWidth ( 100f ) ) )
302
+ {
303
+ this . _ExportBundleUrlPlans ( ) ;
304
+ }
305
+ GUI . backgroundColor = bc ;
306
+ // Load File
307
+ bc = GUI . backgroundColor ;
308
+ GUI . backgroundColor = new Color32 ( 0 , 249 , 255 , 255 ) ;
309
+ if ( GUILayout . Button ( "Load File" , GUILayout . MaxWidth ( 100f ) ) )
310
+ {
311
+ this . _ImportBundleUrlPlans ( ) ;
312
+ }
313
+ GUI . backgroundColor = bc ;
314
+ EditorGUILayout . EndHorizontal ( ) ;
315
+
316
+ EditorGUILayout . EndVertical ( ) ;
317
+
318
+ EditorGUILayout . EndScrollView ( ) ;
319
+ }
320
+
321
+ private void _LoadBundleUrlPlanToCurrent ( )
322
+ {
323
+ if ( this . bundleUrlPlans . Count == 0 ) return ;
324
+
325
+ var bundleUrlPlan = this . bundleUrlPlans [ this . _choicePlanIndex ] ;
326
+
327
+ this . bundleIp = bundleUrlPlan . bundleIp ;
328
+ this . bundleFallbackIp = bundleUrlPlan . bundleFallbackIp ;
329
+ this . storeLink = bundleUrlPlan . storeLink ;
330
+
331
+ // Save
332
+ EditorStorage . SaveData ( keySaver , "bundleIp" , this . bundleIp ) ;
333
+ EditorStorage . SaveData ( keySaver , "bundleFallbackIp" , this . bundleFallbackIp ) ;
334
+ EditorStorage . SaveData ( keySaver , "storeLink" , this . storeLink ) ;
335
+ }
336
+
337
+ private void _CopyCurrentToBundleUrlPlan ( )
338
+ {
339
+ if ( this . bundleUrlPlans . Count == 0 ) return ;
340
+
341
+ var bundleUrlPlan = this . bundleUrlPlans [ this . _choicePlanIndex ] ;
342
+
343
+ // Copy
344
+ bundleUrlPlan . bundleIp = this . bundleIp ;
345
+ bundleUrlPlan . bundleFallbackIp = this . bundleFallbackIp ;
346
+ bundleUrlPlan . storeLink = this . storeLink ;
347
+
348
+ this . bundleUrlPlans [ this . _choicePlanIndex ] = bundleUrlPlan ;
349
+
350
+ // Save
351
+ string json = JsonConvert . SerializeObject ( this . bundleUrlPlans ) ;
352
+ EditorStorage . SaveData ( keySaver , "bundleUrlPlans" , json ) ;
353
+ }
354
+
355
+ private void _ExportBundleUrlPlans ( )
356
+ {
357
+ string savePath = EditorStorage . GetData ( keySaver , $ "bundleUrlPlanFIlePath", Application . dataPath ) ;
358
+ var filePath = EditorUtility . SaveFilePanel ( "Save Bundle Url Plan Json File" , savePath , "BundleUrlPlan" , "json" ) ;
359
+
360
+ if ( ! string . IsNullOrEmpty ( filePath ) )
361
+ {
362
+ EditorStorage . SaveData ( keySaver , $ "bundleUrlPlanFIlePath", Path . GetDirectoryName ( filePath ) ) ;
363
+ string json = JsonConvert . SerializeObject ( this . bundleUrlPlans , Formatting . Indented ) ;
364
+ BundleHelper . WriteTxt ( json , filePath ) ;
365
+ AssetDatabase . Refresh ( ) ;
366
+ }
367
+ }
368
+
369
+ private void _ImportBundleUrlPlans ( )
370
+ {
371
+ string loadPath = EditorStorage . GetData ( keySaver , $ "bundleUrlPlanFIlePath", Application . dataPath ) ;
372
+ string filePath = EditorUtility . OpenFilePanel ( "Select Bundle Url Plan Json File" , ! string . IsNullOrEmpty ( loadPath ) ? loadPath : Application . dataPath , "json" ) ;
373
+
374
+ if ( ! string . IsNullOrEmpty ( filePath ) )
375
+ {
376
+ EditorStorage . SaveData ( keySaver , $ "bundleUrlPlanFIlePath", Path . GetDirectoryName ( filePath ) ) ;
377
+ string json = File . ReadAllText ( filePath ) ;
378
+ this . bundleUrlPlans = JsonConvert . DeserializeObject < List < BundleUrlPlan > > ( json ) ;
379
+
380
+ // Resave bundle plans without format
381
+ json = JsonConvert . SerializeObject ( this . bundleUrlPlans ) ;
382
+ EditorStorage . SaveData ( keySaver , "bundleUrlPlans" , json ) ;
383
+
384
+ // Reset index
385
+ this . _choicePlanIndex = 0 ;
386
+ EditorStorage . SaveData ( keySaver , "_choicePlanIndex" , this . _choicePlanIndex . ToString ( ) ) ;
387
+ }
388
+ }
389
+ #endregion
167
390
}
168
391
}
0 commit comments