加载远程资源
This commit is contained in:
@@ -329,17 +329,16 @@ export default class ResManager {
|
||||
// })
|
||||
// }
|
||||
|
||||
//region 加载远程图片
|
||||
/**
|
||||
* 获取远程图片资源并设置
|
||||
* @param spt 要设置的节点
|
||||
* @param url url地址
|
||||
* @param suffix 图片后缀名
|
||||
* @param cb 回调函数
|
||||
*/
|
||||
changeRemoteSpriteFrame(spt: Sprite, url: string, suffix: string = 'png', cb: Function = null) {
|
||||
/** 加载远程图片 */
|
||||
changeRemoteSpriteFrame(spt: Sprite, url: string, cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
assetManager.loadRemote<ImageAsset>(url, {ext: '.'+suffix}, (err, res: ImageAsset) => {
|
||||
// 临时加了一个字段,用来保存当前加载的资源路径
|
||||
let spttemp:any = spt;
|
||||
// 在异步回调时判断这个组件是不是还在加载同一个 url,避免多次调用时产生覆盖冲突
|
||||
spttemp.frameUrl = url;
|
||||
// 加载
|
||||
assetManager.loadRemote<ImageAsset>(url, (err, res: ImageAsset) => {
|
||||
console.log("加载远程图片: ", url);
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
@@ -347,18 +346,42 @@ export default class ResManager {
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (spttemp.frameUrl != url) {
|
||||
return;
|
||||
}
|
||||
const spriteFrame = new SpriteFrame();
|
||||
const texture = new Texture2D();
|
||||
texture.image = res;
|
||||
spriteFrame.texture = texture;
|
||||
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** 加载远程视频 */
|
||||
loadRemoteVideo(spt: VideoPlayer, url: string, cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
// 临时加了一个字段,用来保存当前加载的资源路径
|
||||
let spttemp:any = spt;
|
||||
// 在异步回调时判断这个组件是不是还在加载同一个 url,避免多次调用时产生覆盖冲突
|
||||
spttemp.frameUrl = url;
|
||||
// 加载
|
||||
assetManager.loadRemote<VideoClip>(url, (err, res: VideoClip) => {
|
||||
console.log("加载远程视频: ", url);
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
if (spttemp.frameUrl != url) {
|
||||
return;
|
||||
}
|
||||
spt.clip = res;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** 加载resources里的PB path:不带后缀*/
|
||||
|
||||
@@ -16,6 +16,8 @@ import Utils from "db://assets/Scripts/Main/Common/Utils";
|
||||
import { ViewManager } from "db://assets/Scripts/Main/Manager/ViewManager";
|
||||
import { GButton } from "db://assets/Scripts/Main/Common/GButton";
|
||||
import { SceneBgVideoLayer } from "../../../Sub/UI/SceneBgVideoLayer";
|
||||
import { DataManager, DataId } from "../../data/DataManager";
|
||||
import { EnvData } from "../../data/EnvData";
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
interface ShowPanelData {
|
||||
@@ -67,8 +69,14 @@ export class ShowPanel extends li_BaseView {
|
||||
}
|
||||
|
||||
show(path: string) {
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
if (this.isImg) {
|
||||
ResManager.I.changeBundleSpriteFrame(this.image, path, "Girls", () => {
|
||||
// ResManager.I.changeBundleSpriteFrame(this.image, path, "Girls", () => {
|
||||
// Utils.adjustBgPixelRatio(this.image.node, 3);
|
||||
// });
|
||||
// 加载远程资源
|
||||
let newPath = envData.cdn + "/" + "Girls/" + path + ".png";
|
||||
ResManager.I.changeRemoteSpriteFrame(this.image, newPath, () => {
|
||||
Utils.adjustBgPixelRatio(this.image.node, 3);
|
||||
});
|
||||
} else {
|
||||
@@ -77,11 +85,11 @@ export class ShowPanel extends li_BaseView {
|
||||
const targetSize = this.videoArea
|
||||
? new Size(this.videoArea.width, this.videoArea.height)
|
||||
: new Size(600, 800);
|
||||
|
||||
ResManager.I.changeBundleVideo(
|
||||
// 加载远程资源
|
||||
let newPath = envData.cdn + "/" + "Girls/" + path + ".mp4";
|
||||
ResManager.I.loadRemoteVideo(
|
||||
this.videoPlayer,
|
||||
path,
|
||||
"Girls",
|
||||
newPath,
|
||||
(res: VideoClip) => {
|
||||
// 设置视频大小和位置
|
||||
const uiTransform = this.videoPlayer.node.getComponent(UITransform);
|
||||
|
||||
@@ -17,6 +17,7 @@ import { GirlDetailPanel } from "../ui/panels/GirlDetailPanel";
|
||||
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
||||
import { DataManager, DataId } from "../data/DataManager";
|
||||
import { GirlData } from "../data/GirlData";
|
||||
import { EnvData } from "../data/EnvData";
|
||||
import { TipsPanel } from "../ui/panels/TipsPanel";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
@@ -204,7 +205,16 @@ export class DetailImageItem extends Component {
|
||||
imgPath = this.url + "_thumbnail_blur";
|
||||
}
|
||||
|
||||
ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => {
|
||||
// ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => {
|
||||
// this.question.active = false;
|
||||
// this.scaleToFillItem();
|
||||
// this.loading.active = false;
|
||||
// });
|
||||
|
||||
// 加载远程资源
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
let newPath = envData.cdn + "/" + "Girls/" + imgPath + ".jpg";
|
||||
ResManager.I.changeRemoteSpriteFrame(this.img, newPath, () => {
|
||||
this.question.active = false;
|
||||
this.scaleToFillItem();
|
||||
this.loading.active = false;
|
||||
@@ -216,7 +226,15 @@ export class DetailImageItem extends Component {
|
||||
this.priceFrame.active = false;
|
||||
this.isVisible = true;
|
||||
const imgPath = this.url + "_thumbnail";
|
||||
ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => {
|
||||
// ResManager.I.changeBundleSpriteFrame(this.img, imgPath, "Girls", () => {
|
||||
// this.question.active = false; // 图片加载成功后隐藏问号
|
||||
// this.scaleToFillItem();
|
||||
// });
|
||||
|
||||
// 加载远程资源
|
||||
const envData = DataManager.I.getDataById<EnvData>(DataId.Env);
|
||||
let newPath = envData.cdn + "/" + "Girls/" + imgPath + ".jpg";
|
||||
ResManager.I.changeRemoteSpriteFrame(this.img, newPath, () => {
|
||||
this.question.active = false; // 图片加载成功后隐藏问号
|
||||
this.scaleToFillItem();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user