MainScene.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, AssetManager, assetManager, Component, find, instantiate, Label, Node, Prefab, sys, screen } from 'cc';
  2. import { Config, nav_info } from './NavInfo';
  3. import { UtilsPanel } from './UtilsPanel';
  4. const { ccclass } = _decorator;
  5. @ccclass('MainScene')
  6. export class MainScene extends Component {
  7. private node_tip: Node = null;
  8. private lb_tip: Label = null;
  9. protected onLoad(): void {
  10. // if (sys.isBrowser || sys.isMobile) screen.requestFullScreen()
  11. UtilsPanel.getAllNeedCom(this, find("Canvas"), true);
  12. nav_info.init();
  13. nav_info.scene = this;
  14. Config.init();
  15. this.loadPrefab();
  16. }
  17. private loadPrefab(){
  18. assetManager.loadBundle(nav_info.bundle, (err:any, bundle:AssetManager.Bundle)=>{
  19. if(err)return;
  20. bundle.load("prefab/" + nav_info.pre, Prefab, (err:any, pre:Prefab)=>{
  21. let new_node = instantiate(pre);
  22. new_node.setParent(find("Canvas"));
  23. this.node_tip.setSiblingIndex(-1);
  24. })
  25. })
  26. }
  27. public showTip(str:string){
  28. this.unschedule(this.hideTip);
  29. this.node_tip.active = true;
  30. this.lb_tip.string = str;
  31. this.scheduleOnce(this.hideTip, 2)
  32. }
  33. private hideTip(){
  34. this.node_tip.active = false;
  35. }
  36. }