/* * @Author: WoNiu * @Date: 2024-03-21 13:29:53 * @LastEditTime: 2024-03-29 14:21:02 * @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"; const { ccclass, property } = _decorator; /** * @description: 游戏根节点的单例 用于直接提供子节点 */ export class GameRootSingleton { private static readonly _instance: GameRootSingleton = new GameRootSingleton(); private constructor() {} public static getInstance(): GameRootSingleton { return GameRootSingleton._instance; } boardRootNode: Node; UIRootNode: Node; DialogRootNode: Node; boardRoot: BoardRoot; UIRoot: UIRoot; DialogRoot: DialogRoot; /** 玩家角色控制脚本 */ gameRoleController: GameRoleController; } @ccclass("GameRootController") /** * @description: 游戏根节点脚本 */ export class GameRootController extends Component { @property(Node) boardRootNode: Node; @property(Node) UIRootNode: Node; @property(Node) DialogRootNode: Node; start() { /// 给三个图层添加 root 根脚本 const game = GameRootSingleton.getInstance(); game.boardRootNode = this.boardRootNode; game.UIRootNode = this.UIRootNode; game.DialogRootNode = this.DialogRootNode; /// 给三个图层添加 root 根脚本 game.boardRoot = this.boardRootNode.getComponent(BoardRoot); game.UIRoot = this.UIRootNode.getComponent(UIRoot); game.DialogRoot = this.DialogRootNode.getComponent(DialogRoot); /// 在 UI 节点 添加玩家角色控制脚本 this.UIRootNode.addComponent(GameRoleController); // 添加游戏 匹配过程控制 脚本 game.gameRoleController = this.addComponent(GameRoleController); } update(deltaTime: number) {} }