UIManager.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { _decorator,instantiate,Prefab ,Node,find} from 'cc';
  2. import { GameMng } from '../GameMng';
  3. import { user_info_view } from '../Main/user_info_view';
  4. import { userData } from '../UserData/userData';
  5. import { ResMng } from './ResMng';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('UIManager')
  8. export class UIManager {
  9. private static _instance: UIManager | null = null;
  10. private static topLayerList:Node[] = [];
  11. private constructor() {
  12. }
  13. public static get Instance() {
  14. if (UIManager._instance === null)
  15. UIManager._instance = new UIManager();
  16. return UIManager._instance;
  17. }
  18. public static AddPrefab(_prefab:Prefab,parent: any = null): Node {
  19. let prefab = instantiate(_prefab);
  20. if (parent == null) {
  21. parent = UIManager.Instance.TopLayer;
  22. if(_prefab.name==="UILoading"||_prefab.name==="waitView"||_prefab.name==="Dialog"){
  23. this.pushLayer(prefab)
  24. console.log("_prefab name ",_prefab.name)
  25. }
  26. }
  27. parent.addChild(prefab);
  28. return prefab;
  29. }
  30. public static addUserInfoViewPrefab(user_data:userData): Node {
  31. let prefab = instantiate(GameMng.Instance.uiuserinfo);
  32. let parent:Node = UIManager.Instance.TopLayer;
  33. parent.addChild(prefab);
  34. prefab.getComponent(user_info_view).show(user_data)
  35. return prefab;
  36. }
  37. private topLayer: any = null;
  38. public get TopLayer() {
  39. this.topLayer = find("Canvas");
  40. return this.topLayer;
  41. }
  42. public static removeLoadingLayer() {
  43. console.log("removeLoadingLayer")
  44. for (let index = 0; index < this.topLayerList.length; index++) {
  45. const element = this.topLayerList[index];
  46. if(element){
  47. console.log("element.name",element.name)
  48. if(element.name == "UILoading"){
  49. element.destroy()
  50. this.topLayerList[index] = null;
  51. }
  52. }
  53. }
  54. }
  55. public static removeWaitViewLayer() {
  56. for (let index = 0; index < this.topLayerList.length; index++) {
  57. const element = this.topLayerList[index];
  58. if(element){
  59. console.log("element.name",element.name)
  60. if(element.name==="waitView"){
  61. element.destroy()
  62. this.topLayerList[index] = null;
  63. }
  64. }
  65. }
  66. }
  67. public static removeDialogViewLayer() {
  68. for (let index = 0; index < this.topLayerList.length; index++) {
  69. const element = this.topLayerList[index];
  70. if(element){
  71. console.log("element.name",element.name)
  72. if(element.name==="Dialog"){
  73. element.destroy()
  74. this.topLayerList[index] = null;
  75. }
  76. }
  77. }
  78. }
  79. public static pushLayer(layer:Node){
  80. for (let index = 0; index < this.topLayerList.length; index++) {
  81. if(this.topLayerList[index]==null){
  82. this.topLayerList[index] = layer;
  83. return;
  84. }
  85. }
  86. return this.topLayerList.push(layer)
  87. }
  88. }