Skip to content

Commit 0532fd5

Browse files
committed
提交 WebGL 与 NintendoSwitch 的适配
1 parent 2836e98 commit 0532fd5

161 files changed

Lines changed: 1807 additions & 483 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.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
/Logs
1111
/Library
1212
/UserSettings
13-
/obj
13+
/obj
14+
/SwitchIL2CPPCache

Assets/BundleMaster/BMWebGLAdapter.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text.RegularExpressions;
4+
using UnityEngine;
5+
using ET;
6+
using UnityEngine.Networking;
7+
8+
namespace BM
9+
{
10+
public static partial class AssetComponent
11+
{
12+
#if BMWebGL
13+
/// <summary>
14+
/// 初始化
15+
/// </summary>
16+
/// <param name="secretKey">WebGL模式下 secretKey 参数失效,仅作占位使用</param>
17+
public static async ETTask<bool> Initialize(string bundlePackageName, string secretKey = null)
18+
{
19+
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Develop)
20+
{
21+
AssetLogHelper.Log("AssetLoadMode = Develop 不需要初始化Bundle配置文件");
22+
return false;
23+
}
24+
if (BundleNameToRuntimeInfo.ContainsKey(bundlePackageName))
25+
{
26+
AssetLogHelper.LogError(bundlePackageName + " 重复初始化");
27+
return false;
28+
}
29+
BundleRuntimeInfo bundleRuntimeInfo = new BundleRuntimeInfo(bundlePackageName);
30+
BundleNameToRuntimeInfo.Add(bundlePackageName, bundleRuntimeInfo);
31+
32+
string filePath = BundleFileExistPath_WebGL(bundlePackageName, "FileLogs.txt");
33+
string fileLogs = await LoadWebGLFileText(filePath);
34+
{
35+
Regex reg = new Regex(@"\<(.+?)>");
36+
MatchCollection matchCollection = reg.Matches(fileLogs);
37+
List<string> dependFileName = new List<string>();
38+
foreach (Match m in matchCollection)
39+
{
40+
string[] fileLog = m.Groups[1].Value.Split('|');
41+
LoadFile loadFile = new LoadFile();
42+
loadFile.FilePath = fileLog[0];
43+
loadFile.AssetBundleName = fileLog[1];
44+
45+
if (fileLog.Length > 2)
46+
{
47+
for (int i = 2; i < fileLog.Length; i++)
48+
{
49+
dependFileName.Add(fileLog[i]);
50+
}
51+
}
52+
loadFile.DependFileName = dependFileName.ToArray();
53+
dependFileName.Clear();
54+
bundleRuntimeInfo.LoadFileDic.Add(loadFile.FilePath, loadFile);
55+
}
56+
}
57+
58+
string dependPath = BundleFileExistPath_WebGL(bundlePackageName, "DependLogs.txt");
59+
string dependLogs = await LoadWebGLFileText(dependPath);
60+
{
61+
Regex reg = new Regex(@"\<(.+?)>");
62+
MatchCollection matchCollection = reg.Matches(dependLogs);
63+
foreach (Match m in matchCollection)
64+
{
65+
string[] dependLog = m.Groups[1].Value.Split('|');
66+
LoadDepend loadDepend = new LoadDepend();
67+
loadDepend.FilePath = dependLog[0];
68+
loadDepend.AssetBundleName = dependLog[1];
69+
bundleRuntimeInfo.LoadDependDic.Add(loadDepend.FilePath, loadDepend);
70+
}
71+
}
72+
73+
ETTask groupTcs = ETTask.Create();
74+
string groupPath = BundleFileExistPath_WebGL(bundlePackageName, "GroupLogs.txt");
75+
string groupLogs = await LoadWebGLFileText(groupPath);
76+
{
77+
Regex reg = new Regex(@"\<(.+?)>");
78+
MatchCollection matchCollection = reg.Matches(groupLogs);
79+
foreach (Match m in matchCollection)
80+
{
81+
string[] groupLog = m.Groups[1].Value.Split('|');
82+
LoadGroup loadGroup = new LoadGroup();
83+
loadGroup.FilePath = groupLog[0];
84+
loadGroup.AssetBundleName = groupLog[1];
85+
if (groupLog.Length > 2)
86+
{
87+
for (int i = 2; i < groupLog.Length; i++)
88+
{
89+
loadGroup.DependFileName.Add(groupLog[i]);
90+
}
91+
}
92+
bundleRuntimeInfo.LoadGroupDic.Add(loadGroup.FilePath, loadGroup);
93+
bundleRuntimeInfo.LoadGroupDicKey.Add(loadGroup.FilePath);
94+
}
95+
}
96+
97+
//加载当前分包的shader
98+
await LoadShader_WebGL(bundlePackageName);
99+
return true;
100+
}
101+
102+
private static async ETTask LoadShader_WebGL(string bundlePackageName)
103+
{
104+
ETTask tcs = ETTask.Create();
105+
string shaderPath = BundleFileExistPath_WebGL(bundlePackageName, "shader_" + bundlePackageName.ToLower());
106+
//判断文件是否存在
107+
using (UnityWebRequest webRequest = UnityWebRequestAssetBundle.GetAssetBundle(shaderPath))
108+
{
109+
UnityWebRequestAsyncOperation weq = webRequest.SendWebRequest();
110+
weq.completed += (o) => { tcs.SetResult(); };
111+
await tcs;
112+
#if UNITY_2020_1_OR_NEWER
113+
if (webRequest.result == UnityWebRequest.Result.Success)
114+
#else
115+
if (string.IsNullOrEmpty(webRequest.error))
116+
#endif
117+
{
118+
AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(webRequest);
119+
BundleNameToRuntimeInfo[bundlePackageName].Shader = assetBundle;
120+
}
121+
else
122+
{
123+
return;
124+
}
125+
}
126+
}
127+
#endif
128+
}
129+
}

Assets/BundleMaster/BMWebGLAdapter/AssetComponentInit_WebGL.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.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.IO;
2+
using System.Text;
3+
using ET;
4+
using UnityEngine.Networking;
5+
6+
namespace BM
7+
{
8+
#if BMWebGL
9+
public static partial class AssetComponent
10+
{
11+
/// <summary>
12+
/// NintendoSwitch获取Bundle信息文件的路径
13+
/// </summary>
14+
internal static string BundleFileExistPath_WebGL(string bundlePackageName, string fileName)
15+
{
16+
string path = Path.Combine(AssetComponentConfig.LocalBundlePath, bundlePackageName, fileName);
17+
return path;
18+
}
19+
20+
internal static async ETTask<string> LoadWebGLFileText(string filePath)
21+
{
22+
ETTask tcs = ETTask.Create();
23+
using (UnityWebRequest webRequest = UnityWebRequest.Get(filePath))
24+
{
25+
UnityWebRequestAsyncOperation weq = webRequest.SendWebRequest();
26+
weq.completed += (o) =>
27+
{
28+
tcs.SetResult();
29+
};
30+
await tcs;
31+
#if UNITY_2020_1_OR_NEWER
32+
if (webRequest.result == UnityWebRequest.Result.Success)
33+
#else
34+
if (string.IsNullOrEmpty(webRequest.error))
35+
#endif
36+
{
37+
string str = webRequest.downloadHandler.text;
38+
return str;
39+
}
40+
else
41+
{
42+
AssetLogHelper.LogError("WebGL初始化分包未找到要读取的文件: \t" + filePath);
43+
return "";
44+
}
45+
46+
}
47+
}
48+
49+
50+
}
51+
#endif
52+
}

Assets/BundleMaster/BMWebGLAdapter/AssetComponentTools_WebGL.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.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Collections.Generic;
2+
using ET;
3+
4+
namespace BM
5+
{
6+
public static partial class AssetComponent
7+
{
8+
#if BMWebGL
9+
/// <summary>
10+
/// 检查分包是否需要更新
11+
/// </summary>
12+
/// <param name="bundlePackageNames">所有分包的名称以及是否验证文件CRC</param>
13+
#pragma warning disable CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行
14+
public static async ETTask<UpdateBundleDataInfo> CheckAllBundlePackageUpdate(Dictionary<string, bool> bundlePackageNames)
15+
#pragma warning restore CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行
16+
{
17+
UpdateBundleDataInfo updateBundleDataInfo = new UpdateBundleDataInfo();
18+
updateBundleDataInfo.NeedUpdate = false;
19+
20+
if (AssetComponentConfig.AssetLoadMode != AssetLoadMode.Build)
21+
{
22+
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Local)
23+
{
24+
AssetComponentConfig.HotfixPath = AssetComponentConfig.LocalBundlePath;
25+
}
26+
else
27+
{
28+
#if !UNITY_EDITOR
29+
AssetLogHelper.LogError("AssetLoadMode = AssetLoadMode.Develop 只能在编辑器下运行");
30+
#endif
31+
}
32+
}
33+
else
34+
{
35+
AssetLogHelper.LogError("AssetLoadMode = AssetLoadMode.Build WebGL无需更新,请用Local模式");
36+
}
37+
return updateBundleDataInfo;
38+
}
39+
40+
/// <summary>
41+
/// 下载更新
42+
/// </summary>
43+
#pragma warning disable CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行
44+
public static async ETTask DownLoadUpdate(UpdateBundleDataInfo updateBundleDataInfo)
45+
#pragma warning restore CS1998 // 异步方法缺少 "await" 运算符,将以同步方式运行
46+
{
47+
AssetLogHelper.LogError("WebGL无需更新");
48+
}
49+
50+
#endif
51+
}
52+
}

Assets/BundleMaster/BMWebGLAdapter/AssetComponentUpdate_WebGL.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.

0 commit comments

Comments
 (0)