MainScene.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { _decorator, AssetManager, assetManager, Component, find, instantiate, Label, Node, Prefab, sys, screen, view, ResolutionPolicy } 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. if(!sys.isMobile){
  12. view.setResolutionPolicy(ResolutionPolicy.SHOW_ALL);
  13. }
  14. UtilsPanel.getAllNeedCom(this, find("Canvas"), true);
  15. nav_info.init();
  16. nav_info.scene = this;
  17. Config.init();
  18. this.loadPrefab();
  19. }
  20. private loadPrefab(){
  21. assetManager.loadBundle(nav_info.bundle, (err:any, bundle:AssetManager.Bundle)=>{
  22. if(err)return;
  23. bundle.load("prefab/" + nav_info.pre, Prefab, (err:any, pre:Prefab)=>{
  24. let new_node = instantiate(pre);
  25. new_node.setParent(find("Canvas"));
  26. this.node_tip.setSiblingIndex(-1);
  27. })
  28. })
  29. }
  30. public showTip(str:string){
  31. this.unschedule(this.hideTip);
  32. this.node_tip.active = true;
  33. this.lb_tip.string = str;
  34. this.scheduleOnce(this.hideTip, 2)
  35. }
  36. private hideTip(){
  37. this.node_tip.active = false;
  38. }
  39. }