123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, resources, Sprite, SpriteFrame, Texture2D } from 'cc';
- export class tools {
- 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){
- // resources.load("prefab/toast",Prefab,(err, prefab)=>{
- // let node = instantiate(prefab);
- // node.name = "toast"
- // node.parent = main.g_canvas.node;
- // node.getComponent(toast).show(text)
- // })
- }
- public static loadUrl(url:string,spr:Sprite){
- if(url.length<=0){
- return null;
- }
- assetManager.loadRemote<ImageAsset>(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<ImageAsset>(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})
- }
- });
- }
- }
|