[LayaAirIDE 2.0]Spine动画资源加载时不能同时使用"版本管理"和"URL.basePath"

当同时启用了版本控制和设置了URL.basePath之后,在加载Spine文件时会出现以下互斥现象:
1. 版本管理启用之后Spine动画文件变成了sp-hashStr.sk和sp-hashStr2.png,并在version.json中记录了映射关系为{sp.sk:sp-hashStr.sk, sp.png:sp-hashStr2.png}。将它们上传至远程路径假设为https://www.xx.com/
2. 设置URL.basePath="https://www.xx.com/"
3. 进入游戏后加载sp.sk, 此时会从version.json中找到sp.sk对应的真实文件名为sp-hashStr.sk,加上URL.basePath后得到最终路径为https://www.xx.com/sp-hashStr.sk
4. 加载成功后解析sk文件,得到该sk文件需要加载一个配套图片路径为https://www.xx.com/sp.png
5. 把路径“https://www.xx.com/sp.png”去version.json中寻找映射关系,发现找不到映射关系,故直接去该路径加载,加载失败,没有该文件
issue.jpg

 
此问题的根源在于sk文件解析完毕后企图加载配套png时给到LoaderManager的png图片路径为已加上URL.basePath的路径(在此例中为https://www.xx.com/sp.png),而在version.json中记录的真实文件名映射关系中,key值为不带有URL.basePath的路径(在此例中为sp.png),导致无法获得png文件的带有hash值得真实文件名。
 
我的解决方式是修改laya.ani.js文件,在其根源处就进行路径纠正。在laya.ani.js(IDE 2.0.0版本)的4827行左右的Templet类的onComplete及parseData方法中设置this._path的位置处对_path进行路径过滤,去掉它内部包含URL.basePath的部分
__proto.onComplete=function(content){
if (this._isDestroyed){
this.destroy();
return;
};
var tSkBuffer=Loader.getRes(this._skBufferUrl);
if (!tSkBuffer){
this.event(/*laya.events.Event.ERROR*/"error","load failed:"+this._skBufferUrl);
return;
}
//MODIFIED:使用formatPath进行路径过滤
this._path=this.formatPath(this._skBufferUrl.slice(0,this._skBufferUrl.lastIndexOf("/"))+"/");
this.parseData(null,tSkBuffer);
}

__proto.parseData=function(texture,skeletonData,playbackRate){
(playbackRate===void 0)&& (playbackRate=30);
if(!this._path&&this.url){
//MODIFIED:使用formatPath进行路径过滤
this._path=this.formatPath(this.url.slice(0,this.url.lastIndexOf("/"))+"/");
}
this._mainTexture=texture;
if (this._mainTexture){
if (Render.isWebGL && texture.bitmap){
texture.bitmap.enableMerageInAtlas=false;
}
}
this._rate=playbackRate;
this.parse(skeletonData);
}

//MODIFIED:增加Path过滤,保证在启用版本管理时能够拿到真实的文件名
__proto.formatPath=function(path){
if(path.indexOf(Laya.URL.basePath) == 0)return path.substr(Laya.URL.basePath.length);
return path;
}
当然,这个方法只不过解决的是燃眉之急罢了,后续希望官方人员引起重视并尽快修正此问题
已邀请:

Aar0n

赞同来自:

嗯,感谢反馈并指出原因。

Aar0n

赞同来自:

2.0.2 版本应该是改过了,建议升级引擎试试,如果有问题继续反馈

要回复问题请先

商务合作
商务合作