puerts
puerts copied to clipboard
[Unity] 安卓真机TS调用c#报错 TypeError: task.GetAwaiter(...).OnCompleted is not a function
error log | 日志或报错信息

context | 编译/运行环境
Unity 2019.4.21f1c1 (64-bit) 谷歌 pixel3 安卓10 操作系统
how to reproduce | 复现步骤
- 在ts里去调用 c# 异步方法 2. 3.
more | 其他
public static async Task LoadFairyGUIPackage(string address, string packageName)
{
var pkgAsset = await Addressables.LoadAssetAsync<TextAsset>(address).Task;
UIPackage.AddPackage(
pkgAsset.bytes,
packageName,
async (string name, string extension, Type type, PackageItem ite) =>
{
Log.Debug(LogGroups.Engine, $"{name}, {extension}, {type.ToString()}, {ite.ToString()}");
if (type == typeof(Texture))
{
Texture t = await Addressables.LoadAssetAsync<Texture>(name + extension).Task;
ite.owner.SetItemAsset(ite, t, DestroyMethod.Custom);
}
});
Addressables.Release(pkgAsset);
}
调用的Promise
function taskToPromise(task) {
return new Promise((resolve, reject) => {
task.GetAwaiter().OnCompleted(() => {
let t = task;
task = undefined;
if (t.IsFaulted) {
if (t.Exception) {
if (t.Exception.InnerException) {
reject(t.Exception.InnerException.Message);
} else {
reject(t.Exception.Message);
}
} else {
reject("unknow exception!");
}
} else {
resolve(t.Result);
}
});
});
}
有试过生成System.Runtime.CompilerServices.TaskAwaiter或者尝试其他防裁剪的手段吗
生成过也没有用 还是报错
#793 同样的问题
@daodaozhangnianxi 为什么把这个关掉了?