-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91e50d1
commit 8822026
Showing
32 changed files
with
1,120 additions
and
79 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.RegularExpressions; | ||
using UnityEngine; | ||
using ET; | ||
using UnityEngine.Networking; | ||
|
||
namespace BM | ||
{ | ||
public static partial class AssetComponent | ||
{ | ||
#if BMWebGL | ||
/// <summary> | ||
/// 初始化 | ||
/// </summary> | ||
/// <param name="secretKey">WebGL模式下 secretKey 参数失效,仅作占位使用</param> | ||
public static async ETTask<bool> Initialize(string bundlePackageName, string secretKey = null) | ||
{ | ||
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Develop) | ||
{ | ||
AssetLogHelper.Log("AssetLoadMode = Develop 不需要初始化Bundle配置文件"); | ||
return false; | ||
} | ||
if (BundleNameToRuntimeInfo.ContainsKey(bundlePackageName)) | ||
{ | ||
AssetLogHelper.LogError(bundlePackageName + " 重复初始化"); | ||
return false; | ||
} | ||
BundleRuntimeInfo bundleRuntimeInfo = new BundleRuntimeInfo(bundlePackageName); | ||
BundleNameToRuntimeInfo.Add(bundlePackageName, bundleRuntimeInfo); | ||
|
||
string filePath = BundleFileExistPath_WebGL(bundlePackageName, "FileLogs.txt"); | ||
string fileLogs = await LoadWebGLFileText(filePath); | ||
{ | ||
Regex reg = new Regex(@"\<(.+?)>"); | ||
MatchCollection matchCollection = reg.Matches(fileLogs); | ||
List<string> dependFileName = new List<string>(); | ||
foreach (Match m in matchCollection) | ||
{ | ||
string[] fileLog = m.Groups[1].Value.Split('|'); | ||
LoadFile loadFile = new LoadFile(); | ||
loadFile.FilePath = fileLog[0]; | ||
loadFile.AssetBundleName = fileLog[1]; | ||
|
||
if (fileLog.Length > 2) | ||
{ | ||
for (int i = 2; i < fileLog.Length; i++) | ||
{ | ||
dependFileName.Add(fileLog[i]); | ||
} | ||
} | ||
loadFile.DependFileName = dependFileName.ToArray(); | ||
dependFileName.Clear(); | ||
bundleRuntimeInfo.LoadFileDic.Add(loadFile.FilePath, loadFile); | ||
} | ||
} | ||
|
||
string dependPath = BundleFileExistPath_WebGL(bundlePackageName, "DependLogs.txt"); | ||
string dependLogs = await LoadWebGLFileText(dependPath); | ||
{ | ||
Regex reg = new Regex(@"\<(.+?)>"); | ||
MatchCollection matchCollection = reg.Matches(dependLogs); | ||
foreach (Match m in matchCollection) | ||
{ | ||
string[] dependLog = m.Groups[1].Value.Split('|'); | ||
LoadDepend loadDepend = new LoadDepend(); | ||
loadDepend.FilePath = dependLog[0]; | ||
loadDepend.AssetBundleName = dependLog[1]; | ||
bundleRuntimeInfo.LoadDependDic.Add(loadDepend.FilePath, loadDepend); | ||
} | ||
} | ||
|
||
ETTask groupTcs = ETTask.Create(); | ||
string groupPath = BundleFileExistPath_WebGL(bundlePackageName, "GroupLogs.txt"); | ||
string groupLogs = await LoadWebGLFileText(groupPath); | ||
{ | ||
Regex reg = new Regex(@"\<(.+?)>"); | ||
MatchCollection matchCollection = reg.Matches(groupLogs); | ||
foreach (Match m in matchCollection) | ||
{ | ||
string[] groupLog = m.Groups[1].Value.Split('|'); | ||
LoadGroup loadGroup = new LoadGroup(); | ||
loadGroup.FilePath = groupLog[0]; | ||
loadGroup.AssetBundleName = groupLog[1]; | ||
if (groupLog.Length > 2) | ||
{ | ||
for (int i = 2; i < groupLog.Length; i++) | ||
{ | ||
loadGroup.DependFileName.Add(groupLog[i]); | ||
} | ||
} | ||
bundleRuntimeInfo.LoadGroupDic.Add(loadGroup.FilePath, loadGroup); | ||
bundleRuntimeInfo.LoadGroupDicKey.Add(loadGroup.FilePath); | ||
} | ||
} | ||
|
||
//加载当前分包的shader | ||
await LoadShader_WebGL(bundlePackageName); | ||
return true; | ||
} | ||
|
||
private static async ETTask LoadShader_WebGL(string bundlePackageName) | ||
{ | ||
ETTask tcs = ETTask.Create(); | ||
string shaderPath = BundleFileExistPath_WebGL(bundlePackageName, "shader_" + bundlePackageName.ToLower()); | ||
//判断文件是否存在 | ||
using (UnityWebRequest webRequest = UnityWebRequestAssetBundle.GetAssetBundle(shaderPath)) | ||
{ | ||
UnityWebRequestAsyncOperation weq = webRequest.SendWebRequest(); | ||
weq.completed += (o) => { tcs.SetResult(); }; | ||
await tcs; | ||
#if UNITY_2020_1_OR_NEWER | ||
if (webRequest.result == UnityWebRequest.Result.Success) | ||
#else | ||
if (string.IsNullOrEmpty(webRequest.error)) | ||
#endif | ||
{ | ||
AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(webRequest); | ||
BundleNameToRuntimeInfo[bundlePackageName].Shader = assetBundle; | ||
} | ||
else | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.IO; | ||
using System.Text; | ||
using ET; | ||
using UnityEngine.Networking; | ||
|
||
namespace BM | ||
{ | ||
#if BMWebGL | ||
public static partial class AssetComponent | ||
{ | ||
/// <summary> | ||
/// NintendoSwitch获取Bundle信息文件的路径 | ||
/// </summary> | ||
internal static string BundleFileExistPath_WebGL(string bundlePackageName, string fileName) | ||
{ | ||
string path = Path.Combine(AssetComponentConfig.LocalBundlePath, bundlePackageName, fileName); | ||
return path; | ||
} | ||
|
||
internal static async ETTask<string> LoadWebGLFileText(string filePath) | ||
{ | ||
ETTask tcs = ETTask.Create(); | ||
using (UnityWebRequest webRequest = UnityWebRequest.Get(filePath)) | ||
{ | ||
UnityWebRequestAsyncOperation weq = webRequest.SendWebRequest(); | ||
weq.completed += (o) => | ||
{ | ||
tcs.SetResult(); | ||
}; | ||
await tcs; | ||
#if UNITY_2020_1_OR_NEWER | ||
if (webRequest.result == UnityWebRequest.Result.Success) | ||
#else | ||
if (string.IsNullOrEmpty(webRequest.error)) | ||
#endif | ||
{ | ||
string str = webRequest.downloadHandler.text; | ||
return str; | ||
} | ||
else | ||
{ | ||
AssetLogHelper.LogError("WebGL初始化分包未找到要读取的文件: \t" + filePath); | ||
return ""; | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System.Collections.Generic; | ||
using ET; | ||
|
||
namespace BM | ||
{ | ||
public static partial class AssetComponent | ||
{ | ||
#if BMWebGL | ||
/// <summary> | ||
/// 检查分包是否需要更新 | ||
/// </summary> | ||
/// <param name="bundlePackageNames">所有分包的名称以及是否验证文件CRC</param> | ||
#pragma warning disable CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行 | ||
public static async ETTask<UpdateBundleDataInfo> CheckAllBundlePackageUpdate(Dictionary<string, bool> bundlePackageNames) | ||
#pragma warning restore CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行 | ||
{ | ||
UpdateBundleDataInfo updateBundleDataInfo = new UpdateBundleDataInfo(); | ||
updateBundleDataInfo.NeedUpdate = false; | ||
|
||
if (AssetComponentConfig.AssetLoadMode != AssetLoadMode.Build) | ||
{ | ||
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Local) | ||
{ | ||
AssetComponentConfig.HotfixPath = AssetComponentConfig.LocalBundlePath; | ||
} | ||
else | ||
{ | ||
#if !UNITY_EDITOR | ||
AssetLogHelper.LogError("AssetLoadMode = AssetLoadMode.Develop 只能在编辑器下运行"); | ||
#endif | ||
} | ||
} | ||
else | ||
{ | ||
AssetLogHelper.LogError("AssetLoadMode = AssetLoadMode.Build WebGL无需更新,请用Local模式"); | ||
} | ||
return updateBundleDataInfo; | ||
} | ||
|
||
/// <summary> | ||
/// 下载更新 | ||
/// </summary> | ||
#pragma warning disable CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行 | ||
public static async ETTask DownLoadUpdate(UpdateBundleDataInfo updateBundleDataInfo) | ||
#pragma warning restore CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行 | ||
{ | ||
AssetLogHelper.LogError("WebGL无需更新"); | ||
} | ||
|
||
#endif | ||
} | ||
} |
Oops, something went wrong.