FGUIInitiator.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { EventDispatcher } from "../events/EventDispatcher";
  2. import { GUIManager } from "../gui/GUIManager";
  3. import IInitiator from "./IInitiator";
  4. import InitiatorEvent from "./InitiatorEvent";
  5. /**
  6. * UI 初始化
  7. */
  8. export default class FGUIInitiator extends EventDispatcher implements IInitiator{
  9. private __commonUIAB:string;
  10. private __commonUI:string;
  11. constructor(commonUIAB:string,commonUI:string){
  12. super();
  13. this.__commonUI=commonUI;
  14. this.__commonUIAB=commonUIAB;
  15. }
  16. Start(): void {
  17. this.CheckCommonUI();
  18. }
  19. private CheckCommonUI():void{
  20. let bundle:cc.AssetManager.Bundle=cc.assetManager.getBundle(this.__commonUIAB);
  21. if(bundle==null){
  22. cc.assetManager.loadBundle(this.__commonUIAB,this.OnCommonUIABLoadComplete.bind(this))
  23. }else{
  24. this.LoadCommonUI(bundle);
  25. }
  26. }
  27. private OnCommonUIABLoadComplete(err:Error,bundle:cc.AssetManager.Bundle):void{
  28. if(err){
  29. throw new Error("公共UI资源包加载出错:"+this.__commonUIAB);
  30. }
  31. this.LoadCommonUI(bundle);
  32. }
  33. private LoadCommonUI(bundle:cc.AssetManager.Bundle):void{
  34. fgui.UIPackage.loadPackage(bundle,this.__commonUI,(err:Error,bundle)=>{
  35. if(err){
  36. throw new Error("AssetBundle中不存在:"+this.__commonUI);
  37. }
  38. this.DispatchEvent(InitiatorEvent.EVENT_COMPLETE);
  39. })
  40. }
  41. Destroy(): void {
  42. }
  43. GetName(): string {
  44. return "FGUIInitiator";
  45. }
  46. }