tools.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { _decorator, assetManager, Component, ImageAsset, instantiate, Node, Prefab, resources, Sprite, SpriteFrame, Texture2D } from 'cc';
  2. export class tools {
  3. public static show_dialog(title="是否确定?",sure_callback,cancel_callback=null){
  4. // resources.load("prefab/dialog_view",Prefab,(err, prefab)=>{
  5. // let node = instantiate(prefab);
  6. // node.parent = main.g_canvas.node;
  7. // node.getComponent(dialog_view).show(title,sure_callback,cancel_callback)
  8. // })
  9. }
  10. public static showToast(text:string){
  11. // resources.load("prefab/toast",Prefab,(err, prefab)=>{
  12. // let node = instantiate(prefab);
  13. // node.name = "toast"
  14. // node.parent = main.g_canvas.node;
  15. // node.getComponent(toast).show(text)
  16. // })
  17. }
  18. public static loadUrl(url:string,spr:Sprite){
  19. if(url.length<=0){
  20. return null;
  21. }
  22. assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
  23. if (!err && imageAsset2) {
  24. const texture = new Texture2D();
  25. texture.image = imageAsset2;
  26. let spFrame2 = new SpriteFrame();
  27. spFrame2.texture = texture;
  28. spr.spriteFrame = spFrame2;
  29. }
  30. });
  31. }
  32. public static getLocalTime(n){
  33. return new Date(parseInt(n)).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
  34. }
  35. public static loadSceneImg(url:string,call){
  36. if(url.length<=0){
  37. return null;
  38. }
  39. assetManager.loadRemote<ImageAsset>(url, (err, imageAsset2)=>{
  40. if (!err && imageAsset2) {
  41. const texture = new Texture2D();
  42. texture.image = imageAsset2;
  43. let spFrame2 = new SpriteFrame();
  44. spFrame2.texture = texture;
  45. spFrame2.addRef()
  46. call({"url":url,"sf":spFrame2})
  47. }
  48. });
  49. }
  50. public static loadSceneMp3(url:string,call){
  51. if(url.length<=0){
  52. return null;
  53. }
  54. assetManager.loadRemote(url, (err: any, clip: any)=> {
  55. clip.addRef()
  56. if (!err && clip) {
  57. call({"url":url,"clip":clip})
  58. }
  59. });
  60. }
  61. }