Skip to content

Commit 1cbcada

Browse files
Merge pull request michael811125#38 from michael811125/dev
added set plans for url set
2 parents e7e83fd + aed7c38 commit 1cbcada

File tree

8 files changed

+534
-12
lines changed

8 files changed

+534
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System;
2+
using UnityEngine;
3+
4+
namespace OxGFrame.AssetLoader.Editor
5+
{
6+
[Serializable]
7+
public class BundleUrlPlan
8+
{
9+
[SerializeField]
10+
public string planName = string.Empty;
11+
[SerializeField]
12+
public string bundleIp = "127.0.0.1";
13+
[SerializeField]
14+
public string bundleFallbackIp = "127.0.0.1";
15+
[SerializeField]
16+
public string storeLink = "http://";
17+
18+
public BundleUrlPlan()
19+
{
20+
this.planName = "Bundle Url Plan";
21+
}
22+
}
23+
}

Assets/OxGFrame/AssetLoader/Scripts/Editor/Bundle/BundleUrlPlan.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/OxGFrame/AssetLoader/Scripts/Editor/Bundle/EditorWindow/BundleConfigGeneratorWindow.cs

+1
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,7 @@ private void _ExportBundlePlans()
845845
EditorStorage.SaveData(keySaver, $"bundlePlanFIlePath", Path.GetDirectoryName(filePath));
846846
string json = JsonConvert.SerializeObject(this.bundlePlans, Formatting.Indented);
847847
BundleHelper.WriteTxt(json, filePath);
848+
AssetDatabase.Refresh();
848849
}
849850
}
850851

Assets/OxGFrame/AssetLoader/Scripts/Editor/Bundle/EditorWindow/BundleUrlConfigGeneratorWindow.cs

+224-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
using OxGFrame.AssetLoader.Bundle;
1+
using Cysharp.Threading.Tasks;
2+
using Newtonsoft.Json;
3+
using OxGFrame.AssetLoader.Bundle;
24
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
37
using System.Linq;
48
using UnityEditor;
59
using UnityEngine;
@@ -24,6 +28,15 @@ internal static BundleUrlConfigGeneratorWindow GetInstance()
2428
[SerializeField]
2529
public bool autoReveal;
2630

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+
2740
internal static string projectPath;
2841
internal static string keySaver;
2942

@@ -43,11 +56,19 @@ public static void ShowWindow()
4356

4457
private void OnEnable()
4558
{
59+
this._serObj = new SerializedObject(this);
60+
this._bundleUrlPlansPty = this._serObj.FindProperty("bundleUrlPlans");
61+
4662
this.bundleIp = EditorStorage.GetData(keySaver, "bundleIp", "127.0.0.1");
4763
this.bundleFallbackIp = EditorStorage.GetData(keySaver, "bundleFallbackIp", "127.0.0.1");
4864
this.storeLink = EditorStorage.GetData(keySaver, "storeLink", "http://");
4965

5066
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"));
5172
}
5273

5374
private void OnGUI()
@@ -56,6 +77,7 @@ private void OnGUI()
5677
EditorGUI.BeginChangeCheck();
5778

5879
this._DrawExportBundleUrlConfigToStreamingAssetsView();
80+
this._DrawBundleUrlPlansView();
5981
}
6082

6183
private void _DrawExportBundleUrlConfigToStreamingAssetsView()
@@ -164,5 +186,206 @@ private void _DrawProcessButtonView()
164186
GUI.backgroundColor = bc;
165187
EditorGUILayout.EndHorizontal();
166188
}
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}]\nDo 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
167390
}
168391
}

0 commit comments

Comments
 (0)