uiManager.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { Node, Prefab, instantiate, resources } from "cc";
  2. export class uiManager {
  3. private static instance:uiManager =null;
  4. public static Instance(){
  5. if(this.instance==null){
  6. this.instance = new uiManager
  7. }
  8. return this.instance
  9. }
  10. private ui_parent:Node = null
  11. private loading_view:Node = null
  12. private send_msg_view:Node = null
  13. public init(ui_node:Node,loading_node:Node,send_msg_loading:Node){
  14. this.ui_parent = ui_node
  15. this.send_msg_view = send_msg_loading
  16. this.loading_view = loading_node
  17. }
  18. public showUi(ui_path:string,parent:Node =null,cb=null){
  19. if(this.ui_parent==null){
  20. return console.error("ui_parent not init..")
  21. }
  22. resources.load(ui_path,Prefab,(err,fb:Prefab)=>{
  23. if(!err){
  24. let node = instantiate(fb)
  25. if(parent!=null){
  26. node.parent = parent
  27. }else{
  28. node.parent = this.ui_parent
  29. }
  30. if(cb!=null){
  31. cb(node)
  32. }
  33. }else{
  34. console.error("showUi error:",err)
  35. }
  36. })
  37. }
  38. public showLoading(){
  39. if(this.loading_view!=null){
  40. }else{
  41. console.error("loading view not init..")
  42. }
  43. }
  44. public hideLoading(){
  45. if(this.loading_view!=null){
  46. }else{
  47. console.error("loading view not init..")
  48. }
  49. }
  50. public showSendMsgWait(){
  51. if(this.send_msg_view!=null){
  52. this.send_msg_view.active = true
  53. }else{
  54. console.error("send_msg_view view not init..")
  55. }
  56. }
  57. public hideSendMsgWait(){
  58. if(this.send_msg_view!=null){
  59. this.send_msg_view.active = false
  60. }else{
  61. console.error("send_msg_view view not init..")
  62. }
  63. }
  64. public onButtonListen(btn:Node,call_back){
  65. btn.on(Node.EventType.TOUCH_END,()=>{
  66. call_back()
  67. })
  68. }
  69. }