type 字段需要传字符串,不是类。Laya.TextResource 是一个类构造器,传进去后 Loader.typeMap 里找不到对应条目,直接返回 null 了。
.json 文件本身已经注册了默认的加载器,不需要指定 type。直接这样就行:
let resArr = [
"resources/config/tb_hero.json",
"resources/config/tb_unit.json"
];
Laya.loader.load(resArr).then(() => {
resArr.forEach((url) => {
console.log(Laya.loader.getRes(url));
});
});
如果你确实想显式指定类型,用 Laya.Loader.JSON 或 Laya.Loader.TEXT(这些是字符串常量),不要用 Laya.TextResource(这是类):
{ url: "resources/config/tb_hero.json", type: Laya.Loader.JSON }
同理 getRes 的第二个参数也是字符串,不传的话默认取主资源,对你这个场景直接 Laya.loader.getRes(url) 就够了。
以上由 AI 自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。