Skip to content

Commit 2cda89b

Browse files
committed
增加一些方便测试的实用功能
1 parent 9c41aca commit 2cda89b

77 files changed

Lines changed: 793 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Assets/BundleMaster/BundleMasterRuntime/AssetComponentConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class AssetComponentConfig
2525
/// <summary>
2626
/// 资源服务器的地址 http://192.168.50.157/BundleData/
2727
/// </summary>
28-
public static string BundleServerUrl = "http://192.168.50.157/BundleData/";
28+
public static string BundleServerUrl = "https://www.download.cutale.cn/TestBundle/0.0.1/";
2929

3030
/// <summary>
3131
/// 默认加载的Bundle名

Assets/BundleMaster/BundleMasterRuntime/Helper/PathUnifiedHelper.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/BundleMasterEditor/BuildAssets.cs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
using System.Text.RegularExpressions;
77
using UnityEngine;
88
using UnityEditor;
9-
using UnityEditor.U2D;
10-
using Debug = UnityEngine.Debug;
119
using UnityEngine.Rendering;
12-
using UnityEngine.U2D;
1310

1411
namespace BM
1512
{
@@ -110,83 +107,6 @@ public static void BuildAllBundle()
110107
AssetLogHelper.Log("打包结束, 耗时" + sw.Elapsed.TotalMilliseconds + " ms \n" + assetLoadTable.BuildBundlePath);
111108
}
112109

113-
[MenuItem("Tools/BuildAsset/Copy资源到StreamingAssets")]
114-
public static void CopyToStreamingAssets()
115-
{
116-
if (!Directory.Exists(Application.streamingAssetsPath))
117-
{
118-
Directory.CreateDirectory(Application.streamingAssetsPath);
119-
}
120-
DeleteHelper.DeleteDir(Application.streamingAssetsPath);
121-
AssetLoadTable assetLoadTable = AssetDatabase.LoadAssetAtPath<AssetLoadTable>(BundleMasterWindow.AssetLoadTablePath);
122-
foreach (AssetsSetting assetsSetting in assetLoadTable.AssetsSettings)
123-
{
124-
if (!(assetsSetting is AssetsLoadSetting assetsLoadSetting))
125-
{
126-
continue;
127-
}
128-
string assetPathFolder;
129-
if (assetsLoadSetting.EncryptAssets)
130-
{
131-
assetPathFolder = Path.Combine(assetLoadTable.BuildBundlePath + "/../", assetLoadTable.EncryptPathFolder, assetsLoadSetting.BuildName);
132-
}
133-
else
134-
{
135-
assetPathFolder = Path.Combine(assetLoadTable.BuildBundlePath, assetsLoadSetting.BuildName);
136-
}
137-
string directoryPath = Path.Combine(Application.streamingAssetsPath, assetsLoadSetting.BuildName);
138-
if (!Directory.Exists(directoryPath))
139-
{
140-
Directory.CreateDirectory(directoryPath);
141-
}
142-
DirectoryInfo subBundlePath = new DirectoryInfo(assetPathFolder);
143-
FileInfo[] fileInfos = subBundlePath.GetFiles();
144-
foreach (FileInfo fileInfo in fileInfos)
145-
{
146-
if (fileInfo.DirectoryName == null)
147-
{
148-
AssetLogHelper.LogError("找不到文件的路径: " + fileInfo.Name);
149-
continue;
150-
}
151-
string filePath = Path.Combine(fileInfo.DirectoryName, fileInfo.Name);
152-
string suffix = Path.GetExtension(filePath);
153-
if ((!fileInfo.Name.StartsWith("shader_") && string.IsNullOrWhiteSpace(suffix)) || suffix == ".manifest")
154-
{
155-
continue;
156-
}
157-
File.Copy(filePath, Path.Combine(directoryPath, fileInfo.Name));
158-
}
159-
}
160-
foreach (AssetsSetting assetsSetting in assetLoadTable.AssetsSettings)
161-
{
162-
if (!(assetsSetting is AssetsOriginSetting assetsOriginSetting))
163-
{
164-
continue;
165-
}
166-
string assetPathFolder = Path.Combine(assetLoadTable.BuildBundlePath, assetsOriginSetting.BuildName);
167-
string directoryPath = Path.Combine(Application.streamingAssetsPath, assetsOriginSetting.BuildName);
168-
if (!Directory.Exists(directoryPath))
169-
{
170-
Directory.CreateDirectory(directoryPath);
171-
}
172-
//获取所有资源目录
173-
HashSet<string> files = new HashSet<string>();
174-
HashSet<string> dirs = new HashSet<string>();
175-
BuildAssetsTools.GetOriginsPath(assetPathFolder, files, dirs);
176-
//Copy资源
177-
foreach (string dir in dirs)
178-
{
179-
Directory.CreateDirectory(dir.Replace(assetPathFolder, directoryPath));
180-
}
181-
foreach (string file in files)
182-
{
183-
File.Copy(file, file.Replace(assetPathFolder, directoryPath), true);
184-
}
185-
}
186-
AssetDatabase.Refresh();
187-
AssetLogHelper.Log("已将资源复制到StreamingAssets");
188-
}
189-
190110
private static void Build(AssetLoadTable assetLoadTable, AssetsLoadSetting assetsLoadSetting, HashSet<string> assetLoadPath, HashSet<string> alwaysIncludedShaders)
191111
{
192112
Dictionary<string, LoadFile> loadFileDic = new Dictionary<string, LoadFile>();

Assets/Editor/BundleMasterEditor/BuildSettings/AssetLoadTable.asset

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ MonoBehaviour:
2222
GeneratePathCode: 0
2323
GenerateCodeScriptPath: Scripts
2424
AssetsSettings:
25-
- {fileID: 11400000, guid: 7864a3de00b6f7e409b8d6050575dab9, type: 2}
26-
- {fileID: 11400000, guid: 0b8c754664ab2214fbfcd1f1a78cf066, type: 2}
27-
- {fileID: 11400000, guid: e86646ac61bb70c45b2c990888d4e2ec, type: 2}
25+
- {fileID: 11400000, guid: 16487b58a96f3cb49831b2b0f3d089d2, type: 2}
26+
- {fileID: 11400000, guid: 3a33b62bd85398649adfde01acf447f9, type: 2}

Assets/Editor/BundleMasterEditor/BuildSettings/AssetsLoadSetting_0.asset.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Editor/BundleMasterEditor/BuildSettings/AssetsLoadSetting_1.asset.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System.Collections.Generic;
2+
using System.IO;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace BM
7+
{
8+
/// <summary>
9+
/// 一些打包会用到的实用的功能
10+
/// </summary>
11+
public class BundleUsefulTool : EditorWindow
12+
{
13+
[MenuItem("Tools/BuildAsset/Copy资源到StreamingAssets")]
14+
public static void CopyToStreamingAssets()
15+
{
16+
if (!Directory.Exists(Application.streamingAssetsPath))
17+
{
18+
Directory.CreateDirectory(Application.streamingAssetsPath);
19+
}
20+
DeleteHelper.DeleteDir(Application.streamingAssetsPath);
21+
AssetLoadTable assetLoadTable = AssetDatabase.LoadAssetAtPath<AssetLoadTable>(BundleMasterWindow.AssetLoadTablePath);
22+
foreach (AssetsSetting assetsSetting in assetLoadTable.AssetsSettings)
23+
{
24+
if (!(assetsSetting is AssetsLoadSetting assetsLoadSetting))
25+
{
26+
continue;
27+
}
28+
string assetPathFolder;
29+
if (assetsLoadSetting.EncryptAssets)
30+
{
31+
assetPathFolder = Path.Combine(assetLoadTable.BuildBundlePath + "/../", assetLoadTable.EncryptPathFolder, assetsLoadSetting.BuildName);
32+
}
33+
else
34+
{
35+
assetPathFolder = Path.Combine(assetLoadTable.BuildBundlePath, assetsLoadSetting.BuildName);
36+
}
37+
string directoryPath = Path.Combine(Application.streamingAssetsPath, assetsLoadSetting.BuildName);
38+
if (!Directory.Exists(directoryPath))
39+
{
40+
Directory.CreateDirectory(directoryPath);
41+
}
42+
DirectoryInfo subBundlePath = new DirectoryInfo(assetPathFolder);
43+
FileInfo[] fileInfos = subBundlePath.GetFiles();
44+
foreach (FileInfo fileInfo in fileInfos)
45+
{
46+
if (fileInfo.DirectoryName == null)
47+
{
48+
AssetLogHelper.LogError("找不到文件的路径: " + fileInfo.Name);
49+
continue;
50+
}
51+
string filePath = Path.Combine(fileInfo.DirectoryName, fileInfo.Name);
52+
string suffix = Path.GetExtension(filePath);
53+
if ((!fileInfo.Name.StartsWith("shader_") && string.IsNullOrWhiteSpace(suffix)) || suffix == ".manifest")
54+
{
55+
continue;
56+
}
57+
File.Copy(filePath, Path.Combine(directoryPath, fileInfo.Name));
58+
}
59+
}
60+
foreach (AssetsSetting assetsSetting in assetLoadTable.AssetsSettings)
61+
{
62+
if (!(assetsSetting is AssetsOriginSetting assetsOriginSetting))
63+
{
64+
continue;
65+
}
66+
string assetPathFolder = Path.Combine(assetLoadTable.BuildBundlePath, assetsOriginSetting.BuildName);
67+
string directoryPath = Path.Combine(Application.streamingAssetsPath, assetsOriginSetting.BuildName);
68+
if (!Directory.Exists(directoryPath))
69+
{
70+
Directory.CreateDirectory(directoryPath);
71+
}
72+
//获取所有资源目录
73+
HashSet<string> files = new HashSet<string>();
74+
HashSet<string> dirs = new HashSet<string>();
75+
BuildAssetsTools.GetOriginsPath(assetPathFolder, files, dirs);
76+
//Copy资源
77+
foreach (string dir in dirs)
78+
{
79+
Directory.CreateDirectory(dir.Replace(assetPathFolder, directoryPath));
80+
}
81+
foreach (string file in files)
82+
{
83+
File.Copy(file, file.Replace(assetPathFolder, directoryPath), true);
84+
}
85+
}
86+
AssetDatabase.Refresh();
87+
AssetLogHelper.Log("已将资源复制到StreamingAssets");
88+
}
89+
90+
[MenuItem("Tools/BuildAsset/实用工具/清空热更目录下的文件")]
91+
public static void ClearHotfixPathPath()
92+
{
93+
DeleteHelper.DeleteDir(AssetComponentConfig.HotfixPath);
94+
AssetDatabase.Refresh();
95+
}
96+
97+
[MenuItem("Tools/BuildAsset/实用工具/清空本地目录下的文件")]
98+
public static void ClearLocalBundlePath()
99+
{
100+
DeleteHelper.DeleteDir(AssetComponentConfig.LocalBundlePath);
101+
AssetDatabase.Refresh();
102+
}
103+
104+
[MenuItem("Tools/BuildAsset/实用工具/清空打包目录下的文件")]
105+
public static void ClearLocalBuildPath()
106+
{
107+
AssetLoadTable assetLoadTable = AssetDatabase.LoadAssetAtPath<AssetLoadTable>(BundleMasterWindow.AssetLoadTablePath);
108+
DeleteHelper.DeleteDir(assetLoadTable.BundlePath);
109+
}
110+
111+
[MenuItem("Tools/BuildAsset/实用工具/清空加密目录下的文件")]
112+
public static void ClearLocalEncryptPath()
113+
{
114+
AssetLoadTable assetLoadTable = AssetDatabase.LoadAssetAtPath<AssetLoadTable>(BundleMasterWindow.AssetLoadTablePath);
115+
DeleteHelper.DeleteDir(assetLoadTable.EncryptPathFolder);
116+
}
117+
}
118+
119+
120+
}

Assets/Editor/BundleMasterEditor/BundleUsefulTool.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Init.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
public class Init : MonoBehaviour
1010
{
11-
private Transform uiManagerTf;
12-
private UpdateBundleDataInfo updateBundleDataInfo;
11+
private Transform _uiManagerTf;
12+
private UpdateBundleDataInfo _updateBundleDataInfo;
1313

1414
private void Awake()
1515
{
@@ -38,18 +38,18 @@ void OnLowMemory()
3838

3939
void OnDestroy()
4040
{
41-
updateBundleDataInfo?.CancelUpdate();
41+
_updateBundleDataInfo?.CancelUpdate();
4242
LMTD.ThreadFactory.Destroy();
4343
}
4444

4545
private void Initialization()
4646
{
4747
//重新配置热更路径(开发方便用, 打包移动端需要注释注释)
4848
AssetComponentConfig.HotfixPath = Application.dataPath + "/../HotfixBundles/";
49-
uiManagerTf = gameObject.transform.Find("UIManager");
49+
_uiManagerTf = gameObject.transform.Find("UIManager");
5050
AssetComponentConfig.DefaultBundlePackageName = "AllBundle";
5151
//创建下载UI
52-
GameObject downLoadUI = GameObject.Instantiate(Resources.Load<GameObject>("DownLoadUI"), uiManagerTf);
52+
GameObject downLoadUI = GameObject.Instantiate(Resources.Load<GameObject>("DownLoadUI"), _uiManagerTf);
5353
DownLoad(downLoadUI).Coroutine();
5454

5555
}
@@ -67,46 +67,46 @@ private async ETTask DownLoad(GameObject downLoadUI)
6767
//{"Main", false},
6868
//{"APK", false},
6969
};
70-
updateBundleDataInfo = await AssetComponent.CheckAllBundlePackageUpdate(updatePackageBundle);
71-
if (!updateBundleDataInfo.NeedUpdate)
70+
_updateBundleDataInfo = await AssetComponent.CheckAllBundlePackageUpdate(updatePackageBundle);
71+
if (!_updateBundleDataInfo.NeedUpdate)
7272
{
7373
GameObject.Destroy(downLoadUI);
7474
InitializePackage().Coroutine();
7575
return;
7676
}
7777
downLoadUI.SetActive(true);
78-
Debug.LogError("需要更新, 大小: " + updateBundleDataInfo.NeedUpdateSize);
78+
Debug.LogError("需要更新, 大小: " + _updateBundleDataInfo.NeedUpdateSize);
7979
Slider progressSlider = downLoadUI.transform.Find("ProgressSlider").GetComponent<Slider>();
8080
Text progressText = downLoadUI.transform.Find("ProgressValue/Text").GetComponent<Text>();
8181
Text speedText = downLoadUI.transform.Find("SpeedValue/Text").GetComponent<Text>();
8282
Button cancelDownLoad = downLoadUI.transform.Find("Cancel").GetComponent<Button>();
8383
Button reDownLoad = downLoadUI.transform.Find("ReDown").GetComponent<Button>();
84-
updateBundleDataInfo.DownLoadFinishCallback += () =>
84+
_updateBundleDataInfo.DownLoadFinishCallback += () =>
8585
{
8686
GameObject.Destroy(downLoadUI);
8787
InitializePackage().Coroutine();
8888
};
89-
updateBundleDataInfo.ProgressCallback += p =>
89+
_updateBundleDataInfo.ProgressCallback += p =>
9090
{
9191
progressSlider.value = p / 100.0f;
9292
progressText.text = p.ToString("#0.00") + "%";
9393
};
94-
updateBundleDataInfo.DownLoadSpeedCallback += s =>
94+
_updateBundleDataInfo.DownLoadSpeedCallback += s =>
9595
{
9696
speedText.text = (s / 1024.0f).ToString("#0.00") + " kb/s";
9797
};
98-
updateBundleDataInfo.ErrorCancelCallback += () =>
98+
_updateBundleDataInfo.ErrorCancelCallback += () =>
9999
{
100100
Debug.LogError("下载取消");
101101
};
102102
cancelDownLoad.onClick.RemoveAllListeners();
103-
cancelDownLoad.onClick.AddListener(updateBundleDataInfo.CancelUpdate);
103+
cancelDownLoad.onClick.AddListener(_updateBundleDataInfo.CancelUpdate);
104104
reDownLoad.onClick.RemoveAllListeners();
105105
reDownLoad.onClick.AddListener(() =>
106106
{
107107
DownLoad(downLoadUI).Coroutine();
108108
});
109-
AssetComponent.DownLoadUpdate(updateBundleDataInfo).Coroutine();
109+
AssetComponent.DownLoadUpdate(_updateBundleDataInfo).Coroutine();
110110
}
111111

112112
private async ETTask InitializePackage()
@@ -122,7 +122,7 @@ private async ETTask InitUI()
122122
await AssetComponent.LoadAsync(out LoadHandler atlasHandler2, BPath.Assets_Bundles_Atlas_UISpriteAtlas__spriteatlas);
123123
//异步加载资源
124124
GameObject loginUIAsset = await AssetComponent.LoadAsync<GameObject>(out LoadHandler loginUIHandler, BPath.Assets_Bundles_LoginUI__prefab);
125-
GameObject loginUIObj = UnityEngine.Object.Instantiate(loginUIAsset, uiManagerTf, false);
125+
GameObject loginUIObj = UnityEngine.Object.Instantiate(loginUIAsset, _uiManagerTf, false);
126126

127127
// GameObject subUI = await AssetComponent.LoadAsync<GameObject>(out LoadHandler usbUIHandler, "Assets/Bundles/SubBundleAssets/SubUI_Copy.prefab");
128128
// GameObject subUIObj = UnityEngine.Object.Instantiate(subUI, loginUIObj.transform, false);
@@ -176,7 +176,7 @@ private async ETTask ResetUI()
176176
{
177177
//异步加载资源
178178
UnityEngine.Object resetUIAsset = await AssetComponent.LoadAsync(BPath.Assets_Bundles_ResetUI__prefab);
179-
GameObject resetUIObj = UnityEngine.Object.Instantiate(resetUIAsset as GameObject, uiManagerTf, false);
179+
GameObject resetUIObj = UnityEngine.Object.Instantiate(resetUIAsset as GameObject, _uiManagerTf, false);
180180
resetUIObj.transform.Find("Reset").GetComponent<Button>().onClick.AddListener(() =>
181181
{
182182
GameObject.Destroy(resetUIObj);

Assets/Scripts/InstallHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static async ETTask InstallApk()
1111
{
1212
//创建下载UI
1313
Transform uiManagerTf = GameObject.Find("UIManager").transform;
14-
GameObject downLoadUI = GameObject.Instantiate(Resources.Load<GameObject>("DownLoadUI"), uiManagerTf);
14+
GameObject downLoadUI = Object.Instantiate(Resources.Load<GameObject>("DownLoadUI"), uiManagerTf);
1515

1616
Dictionary<string, bool> updatePackageBundle = new Dictionary<string, bool>()
1717
{
@@ -42,7 +42,7 @@ public static async ETTask InstallApk()
4242
Debug.LogError("需要更新新的APK " + updateBundleDataInfo.NeedUpdateSize);
4343
await AssetComponent.DownLoadUpdate(updateBundleDataInfo);
4444
}
45-
GameObject.Destroy(downLoadUI);
45+
Object.Destroy(downLoadUI);
4646

4747
return;
4848

0 commit comments

Comments
 (0)