LayerManager.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. export default class LayerManager
  2. {
  3. /**
  4. * 添加内容到层
  5. * @param layerIndex
  6. * @param node
  7. */
  8. AddToLayer(layerIndex:number,node:fgui.GComponent):void{
  9. let layer:fgui.GComponent=this.GetLayer(layerIndex);
  10. if(layer==null){
  11. throw new Error("找不到:"+layerIndex+"层!");
  12. }
  13. layer.addChild(node);
  14. }
  15. /**
  16. * 从层上删除内容
  17. * @param layerIndex
  18. * @param node
  19. */
  20. RemoveFormeLayer(layerIndex:number,node:fgui.GComponent):void{
  21. let layer:fgui.GComponent=this.GetLayer(layerIndex);
  22. if(layer==null){
  23. throw new Error("找不到:"+layerIndex+"层!");
  24. }
  25. layer.removeChild(node);
  26. }
  27. /**
  28. * 通过层索引获取层
  29. * @param layerIndex
  30. */
  31. GetLayer(layerIndex:number):fgui.GComponent{
  32. let layer:fgui.GComponent=fgui.GRoot.inst.getChildAt(layerIndex).asCom;
  33. if(layer==null){
  34. throw new Error("找不到:"+layerIndex+"层!");
  35. }
  36. return layer;
  37. }
  38. /**
  39. * 单例
  40. */
  41. private static instance:LayerManager;
  42. public static get single():LayerManager{
  43. if(this.instance==null){
  44. this.instance=new LayerManager();
  45. }
  46. return this.instance;
  47. }
  48. }