引擎的RES 源码中的getResByUrl 是这样写的,
export function getResByUrl(url: string, compFunc: Function, thisObject: any, type: string = ""): void {
instance.getResByUrl(url, compFunc, thisObject, type);
}
但是在该类中Instance 一开始没有初始化,源码是这样的。
/**
* Resource单例
*/
var instance: Resource;
但是如果一开始调用了RES.loadConfig 后面就可以用getResByUrl .因为源码是这样写的:
/**
* 加载配置文件并解析。
* @see #setMaxRetryTimes
* @version Egret 2.4
* @platform Web,Native
* @language zh_CN
*/
export function loadConfig(url: string, resourceRoot: string) {
if (resourceRoot.indexOf('://') >= 0) {
const temp = resourceRoot.split('://');
resourceRoot = temp[0] + '://' + path.normalize(temp[1] + '/');
}
else {
resourceRoot = path.normalize(resourceRoot + "/");
url = url.replace(resourceRoot, '');
}
setConfigURL(url, resourceRoot);
if (!instance) instance = new Resource();
return instance.loadConfig();
}。
这个官方应该修复一下。我等了好几个版本到现在还没修复。老版的RES instance 默认就初始化了。
|