SceneSetup.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { _decorator, Component, Node, director, find, resources, Prefab } from 'cc';
  2. import { GameManager } from './GameManager';
  3. import { PhysicsManager } from './PhysicsManager';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('SceneSetup')
  6. export class SceneSetup extends Component {
  7. start() {
  8. // 添加物理管理器
  9. if (!this.node.getComponent(PhysicsManager)) {
  10. this.node.addComponent(PhysicsManager);
  11. }
  12. // 添加游戏管理器
  13. if (!this.node.getComponent(GameManager)) {
  14. const gameManager = this.node.addComponent(GameManager);
  15. // 查找并设置必要的引用
  16. // 加载Ball预制体
  17. resources.load('assets/Prefabs/Ball', Prefab, (err, prefab) => {
  18. if (err) {
  19. console.error('加载Ball预制体失败:', err);
  20. } else {
  21. gameManager.ballPrefab = prefab;
  22. }
  23. });
  24. const blockSelectionUI = find('Canvas/GameLevelUI/BlockSelectionUI');
  25. if (blockSelectionUI) {
  26. gameManager.blockSelectionUI = blockSelectionUI;
  27. }
  28. const gameArea = find('Canvas/GameLevelUI/GameArea');
  29. if (gameArea) {
  30. gameManager.gameArea = gameArea;
  31. }
  32. }
  33. }
  34. }