import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, resources, Sprite, SpriteFrame, Texture2D } from 'cc'; import { main } from './main'; import { toast } from './toast'; import { gameManager } from './run/gameManager'; import { config } from './config'; export class tools { public static platform = config.Platform.BROWSER //平台类型 public static show_dialog(title="是否确定?",sure_callback,cancel_callback=null){ // resources.load("prefab/dialog_view",Prefab,(err, prefab)=>{ // let node = instantiate(prefab); // node.parent = main.g_canvas.node; // node.getComponent(dialog_view).show(title,sure_callback,cancel_callback) // }) } public static showToast(text:string, isShow:boolean=false){ if(isShow==false) { return } resources.load("prefab/run/toast",Prefab,(err, prefab)=>{ let node = instantiate(prefab); // node.parent = main.g_canvas.node; node.parent = gameManager.Singleton.getTopFloorLayer() node.getComponent(toast).show(text) }) } public static loadUrl(url:string,spr:Sprite){ if(url.length<=0){ return null; } assetManager.loadRemote(url, (err, imageAsset2)=>{ if (!err && imageAsset2) { const texture = new Texture2D(); texture.image = imageAsset2; let spFrame2 = new SpriteFrame(); spFrame2.texture = texture; spr.spriteFrame = spFrame2; } }); } public static getLocalTime(n){ return new Date(parseInt(n)).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " "); } public static loadSceneImg(url:string,call){ if(url.length<=0){ return null; } assetManager.loadRemote(url, (err, imageAsset2)=>{ if (!err && imageAsset2) { const texture = new Texture2D(); texture.image = imageAsset2; let spFrame2 = new SpriteFrame(); spFrame2.texture = texture; spFrame2.addRef() call({"url":url,"sf":spFrame2}) } }); } public static loadSceneMp3(url:string,call){ if(url.length<=0){ return null; } assetManager.loadRemote(url, (err: any, clip: any)=> { clip.addRef() if (!err && clip) { call({"url":url,"clip":clip}) } }); } // 去除左边和右边空格 public static trimLeftAndRightblank(str: string):string { const reg = /^\s+|\s+$/g; return str.replace(reg, '') } }