| 123456789101112131415161718192021222324252627282930313233343536373839 |
- import { _decorator, Component, Node, director, find, resources, Prefab } from 'cc';
- import { GameManager } from './GameManager';
- import { PhysicsManager } from './PhysicsManager';
- const { ccclass, property } = _decorator;
- @ccclass('SceneSetup')
- export class SceneSetup extends Component {
- start() {
- // 添加物理管理器
- if (!this.node.getComponent(PhysicsManager)) {
- this.node.addComponent(PhysicsManager);
- }
- // 添加游戏管理器
- if (!this.node.getComponent(GameManager)) {
- const gameManager = this.node.addComponent(GameManager);
-
- // 查找并设置必要的引用
- // 加载Ball预制体
- resources.load('assets/Prefabs/Ball', Prefab, (err, prefab) => {
- if (err) {
- console.error('加载Ball预制体失败:', err);
- } else {
- gameManager.ballPrefab = prefab;
- }
- });
-
- const blockSelectionUI = find('Canvas/GameLevelUI/BlockSelectionUI');
- if (blockSelectionUI) {
- gameManager.blockSelectionUI = blockSelectionUI;
- }
-
- const gameArea = find('Canvas/GameLevelUI/GameArea');
- if (gameArea) {
- gameManager.gameArea = gameArea;
- }
- }
- }
- }
|