DaFuWeng/assets/Script/GameRootController.ts

73 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-03-25 19:50:16 +08:00
/*
* @Author: WoNiu
* @Date: 2024-03-21 13:29:53
* @LastEditTime: 2024-03-29 14:21:02
2024-03-25 19:50:16 +08:00
* @LastEditors: WoNiu
* @Description:
*/
import { _decorator, Component, Node } from "cc";
import { BoardRoot } from "./BoardRoot";
import { UIRoot } from "./UIRoot/UIRoot";
import { GameRoleController } from "./UIRoot/GameRoleController";
import { DialogRoot } from "./DialogRoot/DialogRoot";
2024-03-22 21:19:27 +08:00
const { ccclass, property } = _decorator;
2024-03-25 19:50:16 +08:00
/**
* @description:
*/
2024-03-22 21:19:27 +08:00
export class GameRootSingleton {
private static readonly _instance: GameRootSingleton =
new GameRootSingleton();
2024-03-22 21:19:27 +08:00
private constructor() {}
2024-03-22 21:19:27 +08:00
public static getInstance(): GameRootSingleton {
return GameRootSingleton._instance;
}
2024-03-22 21:19:27 +08:00
boardRootNode: Node;
UIRootNode: Node;
DialogRootNode: Node;
2024-03-22 21:19:27 +08:00
boardRoot: BoardRoot;
UIRoot: UIRoot;
DialogRoot: DialogRoot;
2024-03-22 21:19:27 +08:00
/** 玩家角色控制脚本 */
gameRoleController: GameRoleController;
2024-03-22 21:19:27 +08:00
}
2024-03-22 21:19:27 +08:00
@ccclass("GameRootController")
2024-03-25 19:50:16 +08:00
/**
* @description:
*/
2024-03-22 21:19:27 +08:00
export class GameRootController extends Component {
@property(Node) boardRootNode: Node;
@property(Node) UIRootNode: Node;
@property(Node) DialogRootNode: Node;
2024-03-22 21:19:27 +08:00
start() {
/// 给三个图层添加 root 根脚本
const game = GameRootSingleton.getInstance();
game.boardRootNode = this.boardRootNode;
game.UIRootNode = this.UIRootNode;
game.DialogRootNode = this.DialogRootNode;
2024-03-22 21:19:27 +08:00
/// 给三个图层添加 root 根脚本
game.boardRoot = this.boardRootNode.getComponent(BoardRoot);
game.UIRoot = this.UIRootNode.getComponent(UIRoot);
game.DialogRoot = this.DialogRootNode.getComponent(DialogRoot);
2024-03-22 21:19:27 +08:00
/// 在 UI 节点 添加玩家角色控制脚本
this.UIRootNode.addComponent(GameRoleController);
2024-03-22 21:19:27 +08:00
// 添加游戏 匹配过程控制 脚本
game.gameRoleController = this.addComponent(GameRoleController);
2024-03-22 21:19:27 +08:00
}
2024-03-22 21:19:27 +08:00
update(deltaTime: number) {}
2024-03-22 21:19:27 +08:00
}