Skip to content

Commit 81ea09c

Browse files
committed
fix(WechatFileSystem): 为所有方法添加Preserve属性防止代码裁剪
添加UnityEngine.Scripting.Preserve属性到WechatFileSystem类的所有方法,防止Unity的代码裁剪功能在构建时意外移除这些方法。
1 parent b635f8d commit 81ea09c

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Runtime/Mini Game/WechatFileSystem/WechatFileSystem.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public static class WechatFileSystemCreater
99
{
10+
[UnityEngine.Scripting.Preserve]
1011
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices)
1112
{
1213
string fileSystemClass = typeof(WechatFileSystem).FullName;
@@ -15,6 +16,7 @@ public static FileSystemParameters CreateFileSystemParameters(string packageRoot
1516
return fileSystemParams;
1617
}
1718

19+
[UnityEngine.Scripting.Preserve]
1820
public static FileSystemParameters CreateFileSystemParameters(string packageRoot, IRemoteServices remoteServices, IWebDecryptionServices decryptionServices)
1921
{
2022
string fileSystemClass = typeof(WechatFileSystem).FullName;
@@ -35,6 +37,7 @@ public static FileSystemParameters CreateFileSystemParameters(string packageRoot
3537
/// </summary>
3638
internal class WechatFileSystem : IFileSystem
3739
{
40+
[UnityEngine.Scripting.Preserve]
3841
private class WebRemoteServices : IRemoteServices
3942
{
4043
private readonly string _webPackageRoot;
@@ -117,24 +120,28 @@ public WechatFileSystem()
117120
{
118121
}
119122

123+
[UnityEngine.Scripting.Preserve]
120124
public virtual FSInitializeFileSystemOperation InitializeFileSystemAsync()
121125
{
122126
var operation = new WXFSInitializeOperation(this);
123127
return operation;
124128
}
125129

130+
[UnityEngine.Scripting.Preserve]
126131
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
127132
{
128133
var operation = new WXFSLoadPackageManifestOperation(this, packageVersion, timeout);
129134
return operation;
130135
}
131136

137+
[UnityEngine.Scripting.Preserve]
132138
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
133139
{
134140
var operation = new WXFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
135141
return operation;
136142
}
137143

144+
[UnityEngine.Scripting.Preserve]
138145
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
139146
{
140147
if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString())
@@ -155,6 +162,7 @@ public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest m
155162
}
156163
}
157164

165+
[UnityEngine.Scripting.Preserve]
158166
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
159167
{
160168
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
@@ -164,6 +172,7 @@ public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, D
164172
return operation;
165173
}
166174

175+
[UnityEngine.Scripting.Preserve]
167176
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
168177
{
169178
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
@@ -179,6 +188,7 @@ public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
179188
}
180189
}
181190

191+
[UnityEngine.Scripting.Preserve]
182192
public virtual void SetParameter(string name, object value)
183193
{
184194
if (name == FileSystemParametersDefine.REMOTE_SERVICES)
@@ -199,6 +209,7 @@ public virtual void SetParameter(string name, object value)
199209
}
200210
}
201211

212+
[UnityEngine.Scripting.Preserve]
202213
public virtual void OnCreate(string packageName, string packageRoot)
203214
{
204215
PackageName = packageName;
@@ -228,21 +239,25 @@ public virtual void OnCreate(string packageName, string packageRoot)
228239
_fileSystemMgr = WX.GetFileSystemManager();
229240
}
230241

242+
[UnityEngine.Scripting.Preserve]
231243
public virtual void OnDestroy()
232244
{
233245
}
234246

247+
[UnityEngine.Scripting.Preserve]
235248
public virtual bool Belong(PackageBundle bundle)
236249
{
237250
return true;
238251
}
239252

253+
[UnityEngine.Scripting.Preserve]
240254
public virtual bool Exists(PackageBundle bundle)
241255
{
242256
string filePath = GetCacheFileLoadPath(bundle);
243257
return CheckCacheFileExist(filePath);
244258
}
245259

260+
[UnityEngine.Scripting.Preserve]
246261
public virtual bool NeedDownload(PackageBundle bundle)
247262
{
248263
if (Belong(bundle) == false)
@@ -251,21 +266,25 @@ public virtual bool NeedDownload(PackageBundle bundle)
251266
return Exists(bundle) == false;
252267
}
253268

269+
[UnityEngine.Scripting.Preserve]
254270
public virtual bool NeedUnpack(PackageBundle bundle)
255271
{
256272
return false;
257273
}
258274

275+
[UnityEngine.Scripting.Preserve]
259276
public virtual bool NeedImport(PackageBundle bundle)
260277
{
261278
return false;
262279
}
263280

281+
[UnityEngine.Scripting.Preserve]
264282
public virtual string GetBundleFilePath(PackageBundle bundle)
265283
{
266284
return GetCacheFileLoadPath(bundle);
267285
}
268286

287+
[UnityEngine.Scripting.Preserve]
269288
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
270289
{
271290
string filePath = GetCacheFileLoadPath(bundle);
@@ -275,6 +294,7 @@ public virtual byte[] ReadBundleFileData(PackageBundle bundle)
275294
return Array.Empty<byte>();
276295
}
277296

297+
[UnityEngine.Scripting.Preserve]
278298
public virtual string ReadBundleFileText(PackageBundle bundle)
279299
{
280300
string filePath = GetCacheFileLoadPath(bundle);
@@ -286,11 +306,13 @@ public virtual string ReadBundleFileText(PackageBundle bundle)
286306

287307
#region 内部方法
288308

309+
[UnityEngine.Scripting.Preserve]
289310
public WXFileSystemManager GetFileSystemMgr()
290311
{
291312
return _fileSystemMgr;
292313
}
293314

315+
[UnityEngine.Scripting.Preserve]
294316
public bool CheckCacheFileExist(string filePath)
295317
{
296318
string result = WX.GetCachePath(filePath);
@@ -300,6 +322,7 @@ public bool CheckCacheFileExist(string filePath)
300322
return true;
301323
}
302324

325+
[UnityEngine.Scripting.Preserve]
303326
public string GetCacheFileLoadPath(PackageBundle bundle)
304327
{
305328
if (_cacheFilePathMapping.TryGetValue(bundle.BundleGUID, out string filePath) == false)

0 commit comments

Comments
 (0)